ai-chatbot/lib/canvas/remote-zip-contract.ts

36 lines
1.2 KiB
TypeScript

import { z } from "zod";
export const zipWorkerJob = z.object({
attempt: z.number().int().nonnegative(),
folderName: z.string().min(1).max(100).refine(value => !value.includes("/") && !value.includes(String.fromCharCode(92)) && !/^\.+$/.test(value)),
expiresAt: z.number().int().positive(),
appOrigin: z.string().url(),
files: z.array(z.object({
name: z.string().max(200).optional(),
sources: z.array(z.string().url()).max(8),
})).min(1).max(200),
storage: z.object({
bucket: z.string().regex(/^[a-z0-9][a-z0-9-]{0,62}$/),
token: z.string().min(1).max(4096),
publicUrl: z.string().url(),
}),
});
export const zipWorkerSnapshot = z.object({
status: z.enum(["pending", "running", "completed", "failed"]),
stage: z.string().max(300),
error: z.string().max(500).optional(),
processedCount: z.number().int().nonnegative(),
successCount: z.number().int().nonnegative(),
failedCount: z.number().int().nonnegative(),
compressPercent: z.number().min(0).max(100),
bytes: z.number().int().positive().optional(),
});
export type ZipWorkerJob = z.infer<typeof zipWorkerJob>;
export type ZipWorkerSnapshot = z.infer<typeof zipWorkerSnapshot>;
export function zipStorageKey(id: string) {
return `canvas-downloads/${id}.zip`;
}