feat(medias): support upload of multiple items (#4169)

This commit is contained in:
Meier Lukas
2025-10-02 19:54:40 +02:00
committed by GitHub
parent f82f343631
commit dcb845b609
6 changed files with 94 additions and 66 deletions

View File

@@ -1,3 +1,4 @@
import z from "zod";
import { zfd } from "zod-form-data";
import { createCustomErrorParams } from "./form/i18n";
@@ -5,30 +6,34 @@ import { createCustomErrorParams } from "./form/i18n";
export const supportedMediaUploadFormats = ["image/png", "image/jpeg", "image/webp", "image/gif", "image/svg+xml"];
export const mediaUploadSchema = zfd.formData({
file: zfd.file().check((context) => {
if (!supportedMediaUploadFormats.includes(context.value.type)) {
context.issues.push({
code: "custom",
params: createCustomErrorParams({
key: "invalidFileType",
params: { expected: `one of ${supportedMediaUploadFormats.join(", ")}` },
}),
input: context.value.type,
});
return;
}
files: zfd.repeatable(
z.array(
zfd.file().check((context) => {
if (!supportedMediaUploadFormats.includes(context.value.type)) {
context.issues.push({
code: "custom",
params: createCustomErrorParams({
key: "invalidFileType",
params: { expected: `one of ${supportedMediaUploadFormats.join(", ")}` },
}),
input: context.value.type,
});
return;
}
if (context.value.size > 1024 * 1024 * 32) {
// Don't forget to update the limit in nginx.conf (client_max_body_size)
context.issues.push({
code: "custom",
params: createCustomErrorParams({
key: "fileTooLarge",
params: { maxSize: "32 MB" },
}),
input: context.value.size,
});
return;
}
}),
if (context.value.size > 1024 * 1024 * 32) {
// Don't forget to update the limit in nginx.conf (client_max_body_size)
context.issues.push({
code: "custom",
params: createCustomErrorParams({
key: "fileTooLarge",
params: { maxSize: "32 MB" },
}),
input: context.value.size,
});
return;
}
}),
),
),
});