Local file storage (#5763)
Co-authored-by: Tom Moor <tom.moor@gmail.com>
This commit is contained in:
33
plugins/storage/server/api/schema.ts
Normal file
33
plugins/storage/server/api/schema.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import formidable from "formidable";
|
||||
import isEmpty from "lodash/isEmpty";
|
||||
import { z } from "zod";
|
||||
import { ValidateKey } from "@server/validation";
|
||||
|
||||
export const FilesCreateSchema = z.object({
|
||||
body: z.object({
|
||||
key: z
|
||||
.string()
|
||||
.refine(ValidateKey.isValid, { message: ValidateKey.message })
|
||||
.transform(ValidateKey.sanitize),
|
||||
}),
|
||||
file: z.custom<formidable.File>(),
|
||||
});
|
||||
|
||||
export type FilesCreateReq = z.infer<typeof FilesCreateSchema>;
|
||||
|
||||
export const FilesGetSchema = z.object({
|
||||
query: z
|
||||
.object({
|
||||
key: z
|
||||
.string()
|
||||
.refine(ValidateKey.isValid, { message: ValidateKey.message })
|
||||
.optional()
|
||||
.transform((val) => (val ? ValidateKey.sanitize(val) : undefined)),
|
||||
sig: z.string().optional(),
|
||||
})
|
||||
.refine((obj) => !(isEmpty(obj.key) && isEmpty(obj.sig)), {
|
||||
message: "One of key or sig is required",
|
||||
}),
|
||||
});
|
||||
|
||||
export type FilesGetReq = z.infer<typeof FilesGetSchema>;
|
||||
Reference in New Issue
Block a user