feat: add media management (#1337)

* feat: add media management

* feat: add missing page search item

* fix: medias should be hidden for anonymous users

* chore: rename show-all to include-from-all-users

* fix: inconsistent table column for creator-id of media

* fix: schema check not working because of custom type for blob in mysql

* chore: temporarily remove migrations

* chore: readd removed migrations
This commit is contained in:
Meier Lukas
2024-10-26 22:45:32 +02:00
committed by GitHub
parent f8c21f6000
commit db198c6dab
22 changed files with 3762 additions and 5 deletions

View File

@@ -5,6 +5,7 @@ import { groupSchemas } from "./group";
import { iconsSchemas } from "./icons";
import { integrationSchemas } from "./integration";
import { locationSchemas } from "./location";
import { mediaSchemas } from "./media";
import { searchEngineSchemas } from "./search-engine";
import { userSchemas } from "./user";
import { widgetSchemas } from "./widgets";
@@ -19,6 +20,7 @@ export const validation = {
location: locationSchemas,
icons: iconsSchemas,
searchEngine: searchEngineSchemas,
media: mediaSchemas,
common: commonSchemas,
};
@@ -32,3 +34,4 @@ export {
type BoardItemIntegration,
} from "./shared";
export { passwordRequirements } from "./user";
export { supportedMediaUploadFormats } from "./media";

View File

@@ -0,0 +1,44 @@
import type { z } from "zod";
import { zfd } from "zod-form-data";
import { createCustomErrorParams } from "./form/i18n";
export const supportedMediaUploadFormats = ["image/png", "image/jpeg", "image/webp", "image/gif", "image/svg+xml"];
export const uploadMediaSchema = zfd.formData({
file: zfd.file().superRefine((value: File | null, context: z.RefinementCtx) => {
if (!value) {
return context.addIssue({
code: "invalid_type",
expected: "object",
received: "null",
});
}
if (!supportedMediaUploadFormats.includes(value.type)) {
return context.addIssue({
code: "custom",
params: createCustomErrorParams({
key: "invalidFileType",
params: { expected: `one of ${supportedMediaUploadFormats.join(", ")}` },
}),
});
}
if (value.size > 1024 * 1024 * 32) {
return context.addIssue({
code: "custom",
params: createCustomErrorParams({
key: "fileTooLarge",
params: { maxSize: "32 MB" },
}),
});
}
return null;
}),
});
export const mediaSchemas = {
uploadMedia: uploadMediaSchema,
};