Something went wrong. Try again.
Schedule posts and reposts to Bluesky (and other PDSes) with Cloudflare workers. skyscheduler.work
scheduling social-media cloudflare bsky service cloudflare-workers bsky-tool bluesky
Something went wrong. Try again.
1.6 kB · 42 lines
TypeScript
at main
123456789101112131415161718192021222324252627282930313233343536373839404142import * as z from "zod/v4";import { BSKY_GIF_MIME_TYPES, BSKY_IMG_MIME_TYPES, BSKY_VIDEO_MIME_TYPES, BSKY_VIDEO_SIZE_LIMIT, BSKY_VIDEO_SIZE_LIMIT_IN_MB, CF_IMAGES_FILE_SIZE_LIMIT, CF_IMAGES_FILE_SIZE_LIMIT_IN_MB, GIF_UPLOAD_ALLOWED, R2_FILE_SIZE_LIMIT, R2_FILE_SIZE_LIMIT_IN_MB} from "../limits";
export const FileUploadSchema = z.object({ file: z.file({error: "uploaded data is not a file"}) .min(1, "invalid file size") .max(R2_FILE_SIZE_LIMIT, `max file size is ${R2_FILE_SIZE_LIMIT_IN_MB}MB`) .mime([...BSKY_IMG_MIME_TYPES, ...BSKY_VIDEO_MIME_TYPES, ... GIF_UPLOAD_ALLOWED ? BSKY_GIF_MIME_TYPES : []], "file type not allowed") .superRefine((file, ctx) => { const fileType: string = file.type.toLowerCase(); // Check image file restrictions if (BSKY_IMG_MIME_TYPES.includes(fileType)) { if (file.size > CF_IMAGES_FILE_SIZE_LIMIT) { ctx.addIssue({ code: "custom", message: `max image upload size is ${CF_IMAGES_FILE_SIZE_LIMIT_IN_MB}MB`, path: ["file"] }); } } // video file restrictions (also gifs if they are enabled) else if (BSKY_VIDEO_MIME_TYPES.includes(fileType) || (GIF_UPLOAD_ALLOWED && BSKY_GIF_MIME_TYPES.includes(fileType))) { if (file.size > BSKY_VIDEO_SIZE_LIMIT) { ctx.addIssue({ code: "custom", message: `max video size is ${BSKY_VIDEO_SIZE_LIMIT_IN_MB}MB`, path: ["file"] }); } } }).nonoptional("missing file data")});