mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-07 15:09:02 +00:00
fix(workorders): cap completion documents at 50 MB
This commit is contained in:
parent
ca2b3b5134
commit
93f68f84e4
5 changed files with 35 additions and 7 deletions
|
|
@ -11,6 +11,7 @@ import {
|
||||||
formatMediaSizeLimit,
|
formatMediaSizeLimit,
|
||||||
isWorkOrderDocumentsReadOnly,
|
isWorkOrderDocumentsReadOnly,
|
||||||
isWorkOrderFileTooLarge,
|
isWorkOrderFileTooLarge,
|
||||||
|
MAX_WORK_ORDER_COMPLETION_DOC_BYTES,
|
||||||
} from "@/domain/work-orders/utils/work-order-media-limits";
|
} from "@/domain/work-orders/utils/work-order-media-limits";
|
||||||
import { useCompDocDialog } from "@/app/(protected)/workorders/_hooks/use-comp-doc-dialog";
|
import { useCompDocDialog } from "@/app/(protected)/workorders/_hooks/use-comp-doc-dialog";
|
||||||
import { CompDocDialogFooter } from "./comp-doc-dialog-footer";
|
import { CompDocDialogFooter } from "./comp-doc-dialog-footer";
|
||||||
|
|
@ -35,8 +36,8 @@ type UseCompDocPdfUploadArgs = {
|
||||||
};
|
};
|
||||||
|
|
||||||
function rejectCompDocPdf(file: File, rowVersion: string): string | null {
|
function rejectCompDocPdf(file: File, rowVersion: string): string | null {
|
||||||
if (isWorkOrderFileTooLarge(file)) {
|
if (isWorkOrderFileTooLarge(file, MAX_WORK_ORDER_COMPLETION_DOC_BYTES)) {
|
||||||
return `File exceeds the ${formatMediaSizeLimit()} limit.`;
|
return `File exceeds the ${formatMediaSizeLimit(MAX_WORK_ORDER_COMPLETION_DOC_BYTES)} limit.`;
|
||||||
}
|
}
|
||||||
if (file.type !== "application/pdf" && !file.name.toLowerCase().endsWith(".pdf")) {
|
if (file.type !== "application/pdf" && !file.name.toLowerCase().endsWith(".pdf")) {
|
||||||
return "Please upload a PDF file.";
|
return "Please upload a PDF file.";
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ import { fmtDocNow } from "@/domain/work-orders/utils/completion-doc-state";
|
||||||
import {
|
import {
|
||||||
formatMediaSizeLimit,
|
formatMediaSizeLimit,
|
||||||
isWorkOrderFileTooLarge,
|
isWorkOrderFileTooLarge,
|
||||||
|
MAX_WORK_ORDER_COMPLETION_DOC_BYTES,
|
||||||
} from "@/domain/work-orders/utils/work-order-media-limits";
|
} from "@/domain/work-orders/utils/work-order-media-limits";
|
||||||
|
|
||||||
type UseCompDocPdfActionsArgs = {
|
type UseCompDocPdfActionsArgs = {
|
||||||
|
|
@ -55,8 +56,10 @@ export function useCompDocPdfActions({
|
||||||
function handleUploadPdf(files: FileList | null) {
|
function handleUploadPdf(files: FileList | null) {
|
||||||
const file = files?.[0];
|
const file = files?.[0];
|
||||||
if (!file) return;
|
if (!file) return;
|
||||||
if (isWorkOrderFileTooLarge(file)) {
|
if (isWorkOrderFileTooLarge(file, MAX_WORK_ORDER_COMPLETION_DOC_BYTES)) {
|
||||||
toast.error(`File exceeds the ${formatMediaSizeLimit()} limit.`);
|
toast.error(
|
||||||
|
`File exceeds the ${formatMediaSizeLimit(MAX_WORK_ORDER_COMPLETION_DOC_BYTES)} limit.`,
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (file.type !== "application/pdf" && !file.name.toLowerCase().endsWith(".pdf")) {
|
if (file.type !== "application/pdf" && !file.name.toLowerCase().endsWith(".pdf")) {
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ import { hasCompletionMediaGallery } from "@/domain/work-orders/utils/partition-
|
||||||
import {
|
import {
|
||||||
formatMediaSizeLimit,
|
formatMediaSizeLimit,
|
||||||
isWorkOrderFileTooLarge,
|
isWorkOrderFileTooLarge,
|
||||||
|
MAX_WORK_ORDER_COMPLETION_DOC_BYTES,
|
||||||
} from "@/domain/work-orders/utils/work-order-media-limits";
|
} from "@/domain/work-orders/utils/work-order-media-limits";
|
||||||
import { SlideOverCompletionActions } from "./slide-over-completion-actions";
|
import { SlideOverCompletionActions } from "./slide-over-completion-actions";
|
||||||
import { SlideOverCompletionMedia } from "./slide-over-completion-media";
|
import { SlideOverCompletionMedia } from "./slide-over-completion-media";
|
||||||
|
|
@ -71,8 +72,10 @@ export function SlideOverCompletionTab({
|
||||||
const handlePdfSelected = (files: FileList | null) => {
|
const handlePdfSelected = (files: FileList | null) => {
|
||||||
const file = files?.[0];
|
const file = files?.[0];
|
||||||
if (!file || !onUploadCompletionPdf) return;
|
if (!file || !onUploadCompletionPdf) return;
|
||||||
if (isWorkOrderFileTooLarge(file)) {
|
if (isWorkOrderFileTooLarge(file, MAX_WORK_ORDER_COMPLETION_DOC_BYTES)) {
|
||||||
toast.error(`File exceeds the ${formatMediaSizeLimit()} limit.`);
|
toast.error(
|
||||||
|
`File exceeds the ${formatMediaSizeLimit(MAX_WORK_ORDER_COMPLETION_DOC_BYTES)} limit.`,
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (file.type !== "application/pdf" && !file.name.toLowerCase().endsWith(".pdf")) {
|
if (file.type !== "application/pdf" && !file.name.toLowerCase().endsWith(".pdf")) {
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,11 @@
|
||||||
import { isWorkOrderCompletionSurfaceReadOnly } from "@/domain/work-orders/utils/work-order-lock";
|
import { isWorkOrderCompletionSurfaceReadOnly } from "@/domain/work-orders/utils/work-order-lock";
|
||||||
|
|
||||||
/** Backend RequestSizeLimit for media and completion-doc uploads. */
|
/** Backend RequestSizeLimit for media uploads and Extra Docs. */
|
||||||
export const MAX_WORK_ORDER_MEDIA_BYTES = 200_000_000;
|
export const MAX_WORK_ORDER_MEDIA_BYTES = 200_000_000;
|
||||||
|
|
||||||
|
/** Backend RequestSizeLimit for completion-document uploads. */
|
||||||
|
export const MAX_WORK_ORDER_COMPLETION_DOC_BYTES = 50_000_000;
|
||||||
|
|
||||||
const MEDIA_MIME_TYPES = new Set([
|
const MEDIA_MIME_TYPES = new Set([
|
||||||
"image/jpeg",
|
"image/jpeg",
|
||||||
"image/jpg",
|
"image/jpg",
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import {
|
||||||
isWorkOrderExtraDocTypeAllowed,
|
isWorkOrderExtraDocTypeAllowed,
|
||||||
isWorkOrderFileTooLarge,
|
isWorkOrderFileTooLarge,
|
||||||
isWorkOrderMediaTypeAllowed,
|
isWorkOrderMediaTypeAllowed,
|
||||||
|
MAX_WORK_ORDER_COMPLETION_DOC_BYTES,
|
||||||
MAX_WORK_ORDER_MEDIA_BYTES,
|
MAX_WORK_ORDER_MEDIA_BYTES,
|
||||||
workOrderExtraDocsAcceptAttribute,
|
workOrderExtraDocsAcceptAttribute,
|
||||||
workOrderMediaAcceptAttribute,
|
workOrderMediaAcceptAttribute,
|
||||||
|
|
@ -32,6 +33,23 @@ describe("work-order-media-limits", () => {
|
||||||
expect(isWorkOrderFileTooLarge({ size: 10 } as File)).toBe(false);
|
expect(isWorkOrderFileTooLarge({ size: 10 } as File)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("caps completion-document uploads at 50_000_000 bytes and formats the completion copy", () => {
|
||||||
|
expect(MAX_WORK_ORDER_COMPLETION_DOC_BYTES).toBe(50_000_000);
|
||||||
|
expect(formatMediaSizeLimit(MAX_WORK_ORDER_COMPLETION_DOC_BYTES)).toBe("50 MB");
|
||||||
|
expect(
|
||||||
|
isWorkOrderFileTooLarge(
|
||||||
|
{ size: MAX_WORK_ORDER_COMPLETION_DOC_BYTES } as File,
|
||||||
|
MAX_WORK_ORDER_COMPLETION_DOC_BYTES,
|
||||||
|
),
|
||||||
|
).toBe(false);
|
||||||
|
expect(
|
||||||
|
isWorkOrderFileTooLarge(
|
||||||
|
{ size: MAX_WORK_ORDER_COMPLETION_DOC_BYTES + 1 } as File,
|
||||||
|
MAX_WORK_ORDER_COMPLETION_DOC_BYTES,
|
||||||
|
),
|
||||||
|
).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
it("allows only JPG PNG MP4 MOV by MIME or extension", () => {
|
it("allows only JPG PNG MP4 MOV by MIME or extension", () => {
|
||||||
expect(isWorkOrderMediaTypeAllowed({ name: "a.jpg", type: "image/jpeg" } as File)).toBe(true);
|
expect(isWorkOrderMediaTypeAllowed({ name: "a.jpg", type: "image/jpeg" } as File)).toBe(true);
|
||||||
expect(isWorkOrderMediaTypeAllowed({ name: "a.jpg", type: "image/jpg" } as File)).toBe(true);
|
expect(isWorkOrderMediaTypeAllowed({ name: "a.jpg", type: "image/jpg" } as File)).toBe(true);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue