mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-01 19:03:12 +00:00
31 lines
835 B
TypeScript
31 lines
835 B
TypeScript
import type {
|
|
FileCategory,
|
|
MediaCategory,
|
|
MediaFile,
|
|
} from "@/domain/work-orders/types/work-order-media";
|
|
|
|
let mediaIdCounter = 0;
|
|
|
|
export function classifyUpload(f: File): {
|
|
fileType: FileCategory;
|
|
category: MediaCategory;
|
|
} {
|
|
const t = f.type;
|
|
if (t.startsWith("image/")) return { fileType: "image", category: "Photo" };
|
|
if (t.startsWith("video/")) return { fileType: "video", category: "Video" };
|
|
if (t === "application/pdf" || /\.pdf$/i.test(f.name)) {
|
|
return { fileType: "pdf", category: "Report" };
|
|
}
|
|
return { fileType: "other", category: "Other" };
|
|
}
|
|
|
|
export function makeMediaFile(f: File): MediaFile {
|
|
const { fileType, category } = classifyUpload(f);
|
|
return {
|
|
id: `m-${Date.now()}-${mediaIdCounter++}`,
|
|
name: f.name,
|
|
fileType,
|
|
url: URL.createObjectURL(f),
|
|
category,
|
|
};
|
|
}
|