1
8
9import { z } from "zod";
10
11import { LIMITS } from "../constants.js";
12
13export const createUploadSchema = z
14 .object({
15 name: z
16 .string()
17 .min(1)
18 .max(255)
19 .refine((n) => !n.includes("..") && !n.includes("/") && !n.includes("\\"), {
20 message: "name must be a plain file name (no paths)",
21 }),
22 mimeType: z
23 .string()
24 .min(3)
25 .max(127)
26 .regex(/^[a-z0-9.+-]+\/[a-z0-9.+-]+$/i, "invalid mime type"),
27 size: z
28 .number()
29 .int()
30 .min(0)
31 .max(LIMITS.MAX_FILE_SIZE, `File exceeds the ${LIMITS.MAX_FILE_SIZE / 1024 / 1024} MB limit`),
32
33 blockId: z.string().min(1).optional(),
34
35 pageId: z.string().min(1).optional(),
36
37 })
38 .strict();
39export type CreateUpload = z.infer<typeof createUploadSchema>;
40
41export const completeUploadSchema = z
42 .object({
43 fileId: z.string().min(1),
44 })
45 .strict();
46export type CompleteUpload = z.infer<typeof completeUploadSchema>;
47