keep trying

Signed-off-by: Kenneth Obsequio <k80308392@gmail.com>
This commit is contained in:
2026-07-12 14:49:23 +08:00
parent 69ca47e00a
commit e9b99f8243
12 changed files with 576 additions and 16 deletions
+54
View File
@@ -0,0 +1,54 @@
// utils/assetUpload.util.js
//
// Client-side gate for the Add Asset multi-file drop zone. Mirrors what the
// backend actually knows how to classify (resolveFileType() in
// assets.controller.js: image/video/audio by MIME prefix, everything else
// under application/* or text/* becomes "document") but rejects generic
// binaries up front instead of letting them 500 on the server.
const ALLOWED_DOCUMENT_MIME_TYPES = new Set([
"application/pdf",
"application/msword",
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"application/vnd.ms-excel",
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"application/vnd.ms-powerpoint",
"application/vnd.openxmlformats-officedocument.presentationml.presentation",
"application/zip",
"application/x-zip-compressed",
"application/json",
"application/rtf",
"text/plain",
"text/csv",
"text/markdown",
]);
const ALLOWED_DOCUMENT_EXTENSIONS = new Set([
"pdf", "doc", "docx", "xls", "xlsx", "ppt", "pptx",
"zip", "json", "rtf", "txt", "csv", "md",
]);
export function fileExtension(filename = "") {
const dot = filename.lastIndexOf(".");
return dot > 0 ? filename.slice(dot + 1).toLowerCase() : "";
}
// { ok: true } or { ok: false, reason }
export function validateAssetFile(file) {
const mime = file.type || "";
if (mime.startsWith("image/") || mime.startsWith("video/") || mime.startsWith("audio/")) {
return { ok: true };
}
const ext = fileExtension(file.name);
if (ALLOWED_DOCUMENT_MIME_TYPES.has(mime) || ALLOWED_DOCUMENT_EXTENSIONS.has(ext)) {
return { ok: true };
}
const label = ext ? `.${ext}` : (mime || "unknown");
return {
ok: false,
reason: `Unsupported file type "${label}". Allowed formats: images, video, audio, documents.`,
};
}