setting, session and profile fix
This commit is contained in:
parent
068142ed61
commit
a434af224c
34 changed files with 497 additions and 119 deletions
43
frontend/src/utils/fileMeta.js
Normal file
43
frontend/src/utils/fileMeta.js
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
const TYPE_LABELS = {
|
||||
"application/pdf": "PDF",
|
||||
"application/msword": "Word",
|
||||
"application/vnd.openxmlformats-officedocument.wordprocessingml.document": "Word",
|
||||
"application/vnd.ms-excel": "Excel",
|
||||
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": "Excel",
|
||||
"application/vnd.ms-powerpoint": "PowerPoint",
|
||||
"application/vnd.openxmlformats-officedocument.presentationml.presentation": "PowerPoint",
|
||||
"application/zip": "ZIP",
|
||||
"application/json": "JSON",
|
||||
"text/plain": "Text",
|
||||
"text/csv": "CSV",
|
||||
"image/jpeg": "JPEG",
|
||||
"image/jpg": "JPEG",
|
||||
"image/png": "PNG",
|
||||
"image/gif": "GIF",
|
||||
"image/webp": "WebP",
|
||||
"image/svg+xml": "SVG",
|
||||
};
|
||||
|
||||
export function formatFileSize(bytes) {
|
||||
const size = Number(bytes);
|
||||
if (!Number.isFinite(size) || size <= 0) return "";
|
||||
if (size < 1024) return `${size} B`;
|
||||
if (size < 1024 * 1024) return `${Math.round(size / 1024)} KB`;
|
||||
if (size < 1024 * 1024 * 1024) return `${(size / (1024 * 1024)).toFixed(1)} MB`;
|
||||
return `${(size / (1024 * 1024 * 1024)).toFixed(1)} GB`;
|
||||
}
|
||||
|
||||
export function fileTypeLabel(type, filename = "") {
|
||||
const mime = String(type || "").toLowerCase();
|
||||
if (TYPE_LABELS[mime]) return TYPE_LABELS[mime];
|
||||
if (mime.startsWith("image/")) return mime.slice(6).toUpperCase();
|
||||
if (mime.startsWith("video/")) return "Video";
|
||||
if (mime.startsWith("audio/")) return "Audio";
|
||||
const ext = String(filename).split(".").pop();
|
||||
if (ext && ext !== filename && ext.length <= 5) return ext.toUpperCase();
|
||||
return "File";
|
||||
}
|
||||
|
||||
export function fileMetaLine(type, size, filename = "") {
|
||||
return [fileTypeLabel(type, filename), formatFileSize(size)].filter(Boolean).join(" · ");
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue