Add image upload and edit functions

This commit is contained in:
2025-12-20 16:34:50 +01:00
parent 96fa12993b
commit dfb6f7042a
72 changed files with 7413 additions and 81 deletions

View File

@ -0,0 +1,81 @@
"use server"
import { prisma } from "@/lib/prisma";
import { artworkSchema } from "@/schemas/artworks/imageSchema";
import { z } from "zod/v4";
export async function updateArtwork(
values: z.infer<typeof artworkSchema>,
id: string
) {
const validated = artworkSchema.safeParse(values);
// console.log(validated)
if (!validated.success) {
throw new Error("Invalid image data");
}
const {
name,
needsWork,
nsfw,
published,
setAsHeader,
altText,
description,
notes,
month,
year,
creationDate,
tagIds,
categoryIds
} = validated.data;
if(setAsHeader) {
await prisma.artwork.updateMany({
where: { setAsHeader: true },
data: { setAsHeader: false },
})
}
const updatedArtwork = await prisma.artwork.update({
where: { id: id },
data: {
name,
needsWork,
nsfw,
published,
setAsHeader,
altText,
description,
notes,
month,
year,
creationDate
}
});
if (tagIds) {
await prisma.artwork.update({
where: { id: id },
data: {
tags: {
set: tagIds.map(id => ({ id }))
}
}
});
}
if (categoryIds) {
await prisma.artwork.update({
where: { id: id },
data: {
categories: {
set: categoryIds.map(id => ({ id }))
}
}
});
}
return updatedArtwork
}