Add production-ready media library
CI / quality (push) Waiting to run

This commit is contained in:
MOH
2026-03-07 16:20:11 +01:00
parent ea64373853
commit 0f9f9e5f79
13 changed files with 1084 additions and 11 deletions
+42
View File
@@ -0,0 +1,42 @@
import { MediaKind } from "@prisma/client";
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>;