Skip to content

Commit 5e2741f

Browse files
committed
fix: enhance file type validation in AtlasProvider to support wildcard MIME types
1 parent e16934e commit 5e2741f

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

kleros-app/src/lib/atlas/providers/AtlasProvider.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,16 @@ export const AtlasProvider: React.FC<{ config: AtlasConfig; children?: React.Rea
281281
const restrictions = roleRestrictions.find((supportedRoles) => Roles[supportedRoles.name] === role);
282282

283283
if (!restrictions) throw new Error("Unsupported role.");
284-
if (!restrictions.restriction.allowedMimeTypes.includes(file.type)) throw new Error("Unsupported file type.");
284+
285+
const isValidMimeType = restrictions.restriction.allowedMimeTypes.some((allowedType) => {
286+
if (allowedType.endsWith("/*")) {
287+
const prefix = allowedType.replace("/*", "/");
288+
return file.type.startsWith(prefix);
289+
}
290+
return allowedType === file.type;
291+
});
292+
293+
if (!isValidMimeType) throw new Error("Unsupported file type.");
285294
if (file.size > restrictions.restriction.maxSize)
286295
throw new Error(
287296
`File too big. Max allowed size : ${(restrictions.restriction.maxSize / (1024 * 1024)).toFixed(2)} mb.`

0 commit comments

Comments
 (0)