CI / quality (push) Waiting to run
- Add lib/db (schema, postgres.js client, enums, seed, migrations) on Drizzle - Rewrite all lib and admin action queries from Prisma to Drizzle - Keep existing table/column names so no data migration is needed - Preserve signed-cookie admin auth unchanged - Map unique-violation handling from Prisma P2002 to SQLSTATE 23505 - Swap deps, scripts, Makefile, and Dockerfile from Prisma to Drizzle
43 lines
1.2 KiB
TypeScript
43 lines
1.2 KiB
TypeScript
import { MediaKind } from "@/lib/db/enums";
|
|
import { z } from "zod";
|
|
|
|
const mediaModeSchema = z.enum(["library", "external", "upload"]);
|
|
|
|
const optionalTrimmedText = z.string().trim().optional().transform((value) => value ?? "");
|
|
|
|
export const mediaFieldInputSchema = z
|
|
.object({
|
|
mode: mediaModeSchema,
|
|
assetId: optionalTrimmedText,
|
|
url: optionalTrimmedText,
|
|
label: optionalTrimmedText,
|
|
kind: z.nativeEnum(MediaKind),
|
|
})
|
|
.superRefine((value, context) => {
|
|
if (value.mode === "library" && !value.assetId) {
|
|
context.addIssue({
|
|
code: z.ZodIssueCode.custom,
|
|
path: ["assetId"],
|
|
message: "Library selection requires a media asset.",
|
|
});
|
|
}
|
|
|
|
if (value.mode === "external" && !value.url) {
|
|
context.addIssue({
|
|
code: z.ZodIssueCode.custom,
|
|
path: ["url"],
|
|
message: "External media requires a URL.",
|
|
});
|
|
}
|
|
|
|
if (value.url && !/^https?:\/\//.test(value.url) && !value.url.startsWith("/")) {
|
|
context.addIssue({
|
|
code: z.ZodIssueCode.custom,
|
|
path: ["url"],
|
|
message: "Media URL must be an absolute URL or start with /.",
|
|
});
|
|
}
|
|
});
|
|
|
|
export type MediaFieldInput = z.infer<typeof mediaFieldInputSchema>;
|