mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-02 03:53:13 +00:00
46 lines
1.7 KiB
TypeScript
46 lines
1.7 KiB
TypeScript
/** Backend RequestSizeLimit for media and completion-doc uploads. */
|
|
export const MAX_WORK_ORDER_MEDIA_BYTES = 30 * 1024 * 1024;
|
|
|
|
const ALLOWED_MIME_TYPES = new Set(["image/jpeg", "image/png", "video/mp4", "video/quicktime"]);
|
|
|
|
const ALLOWED_EXTENSIONS = new Set([".jpg", ".jpeg", ".png", ".mp4", ".mov"]);
|
|
|
|
export function isWorkOrderFileTooLarge(
|
|
file: File,
|
|
maxBytes = MAX_WORK_ORDER_MEDIA_BYTES,
|
|
): boolean {
|
|
return file.size > maxBytes;
|
|
}
|
|
|
|
export function isWorkOrderMediaTypeAllowed(file: File): boolean {
|
|
const mimeOk = Boolean(file.type) && ALLOWED_MIME_TYPES.has(file.type.toLowerCase());
|
|
const name = file.name.toLowerCase();
|
|
const dot = name.lastIndexOf(".");
|
|
const ext = dot >= 0 ? name.slice(dot) : "";
|
|
const extOk = ALLOWED_EXTENSIONS.has(ext);
|
|
return mimeOk || extOk;
|
|
}
|
|
|
|
export function workOrderMediaAcceptAttribute(): string {
|
|
return "image/jpeg,image/png,video/mp4,video/quicktime,.jpg,.jpeg,.png,.mp4,.mov";
|
|
}
|
|
|
|
export function formatMediaSizeLimit(maxBytes = MAX_WORK_ORDER_MEDIA_BYTES): string {
|
|
return `${Math.round(maxBytes / (1024 * 1024))} MB`;
|
|
}
|
|
|
|
import { isWorkOrderCompletionSurfaceReadOnly } from "@/domain/work-orders/utils/work-order-lock";
|
|
|
|
/** Completion-doc / completion-media lock: Canceled or Completed. Extra Docs use canMutateWorkOrderExtraDocs. */
|
|
export function isWorkOrderDocumentsReadOnly(status: string | null | undefined): boolean {
|
|
return isWorkOrderCompletionSurfaceReadOnly(status);
|
|
}
|
|
|
|
export function canDeleteWorkOrderMedia(media: {
|
|
id: string | number;
|
|
isLegacy?: boolean;
|
|
}): boolean {
|
|
if (media.isLegacy) return false;
|
|
const numericId = typeof media.id === "number" ? media.id : Number(media.id);
|
|
return Number.isFinite(numericId) && numericId > 0;
|
|
}
|