37 lines
1.3 KiB
TypeScript
37 lines
1.3 KiB
TypeScript
|
|
import { z } from 'zod';
|
||
|
|
|
||
|
|
export const createBrochureSchema = z.object({
|
||
|
|
label: z.string().trim().min(1).max(120),
|
||
|
|
description: z.string().max(500).optional().nullable(),
|
||
|
|
isDefault: z.boolean().optional(),
|
||
|
|
});
|
||
|
|
|
||
|
|
export const updateBrochureSchema = z.object({
|
||
|
|
label: z.string().trim().min(1).max(120).optional(),
|
||
|
|
description: z.string().max(500).optional().nullable(),
|
||
|
|
isDefault: z.boolean().optional(),
|
||
|
|
});
|
||
|
|
|
||
|
|
export const registerBrochureVersionSchema = z.object({
|
||
|
|
storageKey: z
|
||
|
|
.string()
|
||
|
|
.min(1)
|
||
|
|
.max(500)
|
||
|
|
// Mirrors the `validateStorageKey` regex in `src/lib/storage/filesystem.ts`
|
||
|
|
// — defense-in-depth against path-traversal payloads from the client.
|
||
|
|
.regex(/^[a-zA-Z0-9/_.-]+$/, 'Invalid storage key format')
|
||
|
|
.refine((s) => !s.includes('..'), 'Storage key may not contain ".."')
|
||
|
|
.refine((s) => !s.startsWith('/'), 'Storage key may not be absolute'),
|
||
|
|
fileName: z.string().min(1).max(255),
|
||
|
|
fileSizeBytes: z
|
||
|
|
.number()
|
||
|
|
.int()
|
||
|
|
.positive()
|
||
|
|
.max(100 * 1024 * 1024), // 100MB hard ceiling
|
||
|
|
contentSha256: z.string().regex(/^[0-9a-f]{64}$/, 'sha256 must be 64-char hex'),
|
||
|
|
});
|
||
|
|
|
||
|
|
export type CreateBrochureInput = z.infer<typeof createBrochureSchema>;
|
||
|
|
export type UpdateBrochureInput = z.infer<typeof updateBrochureSchema>;
|
||
|
|
export type RegisterBrochureVersionInput = z.infer<typeof registerBrochureVersionSchema>;
|