Add image upload and edit functions
This commit is contained in:
9
src/schemas/artworks/albumSchema.ts
Normal file
9
src/schemas/artworks/albumSchema.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import { z } from "zod/v4"
|
||||
|
||||
export const albumSchema = z.object({
|
||||
name: z.string().min(3, "Name is required. Min 3 characters."),
|
||||
slug: z.string().min(3, "Slug is required. Min 3 characters.").regex(/^[a-z]+$/, "Only lowercase letters are allowed (no numbers, spaces, or uppercase)"),
|
||||
description: z.string().optional(),
|
||||
})
|
||||
|
||||
export type albumSchema = z.infer<typeof albumSchema>
|
||||
9
src/schemas/artworks/categorySchema.ts
Normal file
9
src/schemas/artworks/categorySchema.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import { z } from "zod/v4"
|
||||
|
||||
export const categorySchema = z.object({
|
||||
name: z.string().min(3, "Name is required. Min 3 characters."),
|
||||
slug: z.string().min(3, "Slug is required. Min 3 characters.").regex(/^[a-z]+$/, "Only lowercase letters are allowed (no numbers, spaces, or uppercase)"),
|
||||
description: z.string().optional(),
|
||||
})
|
||||
|
||||
export type categorySchema = z.infer<typeof categorySchema>
|
||||
47
src/schemas/artworks/imageSchema.ts
Normal file
47
src/schemas/artworks/imageSchema.ts
Normal file
@ -0,0 +1,47 @@
|
||||
import { z } from "zod/v4";
|
||||
|
||||
export const fileUploadSchema = z.object({
|
||||
file: z
|
||||
.custom<FileList>()
|
||||
.refine((files) => files instanceof FileList && files.length > 0, {
|
||||
message: "Image file is required",
|
||||
}),
|
||||
})
|
||||
|
||||
const isFileList = (v: unknown): v is FileList =>
|
||||
typeof FileList !== "undefined" && v instanceof FileList;
|
||||
|
||||
export const fileBulkUploadSchema = z.object({
|
||||
file: z
|
||||
.custom<FileList>((v) => isFileList(v), "Please choose one or more files")
|
||||
.refine((files) => files.length > 0, {
|
||||
message: "At least one image file is required",
|
||||
}),
|
||||
})
|
||||
|
||||
export const artworkSchema = z.object({
|
||||
name: z.string().min(1, "Name is required"),
|
||||
needsWork: z.boolean(),
|
||||
nsfw: z.boolean(),
|
||||
published: z.boolean(),
|
||||
setAsHeader: z.boolean(),
|
||||
|
||||
altText: z.string().optional(),
|
||||
description: z.string().optional(),
|
||||
notes: z.string().optional(),
|
||||
month: z.number().optional(),
|
||||
year: z.number().optional(),
|
||||
creationDate: z.date().optional(),
|
||||
|
||||
// fileId: z.string(),
|
||||
// albumId: z.string().optional(),
|
||||
// typeId: z.string().optional(),
|
||||
|
||||
metadataId: z.string().optional(),
|
||||
|
||||
categoryIds: z.array(z.string()).optional(),
|
||||
colorIds: z.array(z.string()).optional(),
|
||||
// sortContextIds: z.array(z.string()).optional(),
|
||||
tagIds: z.array(z.string()).optional(),
|
||||
variantIds: z.array(z.string()).optional(),
|
||||
})
|
||||
10
src/schemas/artworks/tagSchema.ts
Normal file
10
src/schemas/artworks/tagSchema.ts
Normal file
@ -0,0 +1,10 @@
|
||||
import { z } from "zod/v4"
|
||||
|
||||
export const tagSchema = z.object({
|
||||
name: z.string().min(3, "Name is required. Min 3 characters."),
|
||||
slug: z.string().min(3, "Slug is required. Min 3 characters.").regex(/^[a-z]+$/, "Only lowercase letters are allowed (no numbers, spaces, or uppercase)"),
|
||||
description: z.string().optional(),
|
||||
})
|
||||
|
||||
export type tagSchema = z.infer<typeof tagSchema>
|
||||
|
||||
9
src/schemas/artworks/typeSchema.ts
Normal file
9
src/schemas/artworks/typeSchema.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import { z } from "zod/v4"
|
||||
|
||||
export const typeSchema = z.object({
|
||||
name: z.string().min(3, "Name is required. Min 3 characters."),
|
||||
slug: z.string().min(3, "Slug is required. Min 3 characters.").regex(/^[a-z]+$/, "Only lowercase letters are allowed (no numbers, spaces, or uppercase)"),
|
||||
description: z.string().optional(),
|
||||
})
|
||||
|
||||
export type typeSchema = z.infer<typeof typeSchema>
|
||||
Reference in New Issue
Block a user