deerflow2/frontend/src/core/uploads/file-validation.ts
luobo 144c9b2464
fix(frontend): block unsupported .app uploads (#1834)
Co-authored-by: Willem Jiang <willem.jiang@gmail.com>
2026-04-04 14:42:26 +08:00

35 lines
912 B
TypeScript

const MACOS_APP_BUNDLE_CONTENT_TYPES = new Set([
"",
"application/octet-stream",
]);
export const MACOS_APP_BUNDLE_UPLOAD_MESSAGE =
"macOS .app bundles can't be uploaded directly from the browser. Compress the app as a .zip or upload the .dmg instead.";
export function isLikelyMacOSAppBundle(file: Pick<File, "name" | "type">) {
return (
file.name.toLowerCase().endsWith(".app") &&
MACOS_APP_BUNDLE_CONTENT_TYPES.has(file.type)
);
}
export function splitUnsupportedUploadFiles(fileList: File[] | FileList) {
const incoming = Array.from(fileList);
const accepted: File[] = [];
const rejected: File[] = [];
for (const file of incoming) {
if (isLikelyMacOSAppBundle(file)) {
rejected.push(file);
continue;
}
accepted.push(file);
}
return {
accepted,
rejected,
message: rejected.length > 0 ? MACOS_APP_BUNDLE_UPLOAD_MESSAGE : undefined,
};
}