mirror of
https://github.com/trafficlunar/tomodachi-share.git
synced 2026-05-13 13:17:45 +00:00
fix: can't remove custom images
This commit is contained in:
parent
c24cc3dc01
commit
ed9a480385
2 changed files with 8 additions and 6 deletions
|
|
@ -156,6 +156,8 @@ export async function POST(request: NextRequest, { params }: { params: Promise<{
|
||||||
if (quarantined && needsFixingReason && session.user?.id?.toString() !== process.env.NEXT_PUBLIC_ADMIN_USER_ID)
|
if (quarantined && needsFixingReason && session.user?.id?.toString() !== process.env.NEXT_PUBLIC_ADMIN_USER_ID)
|
||||||
return rateLimit.sendResponse({ error: `You're not an admin!` }, 401);
|
return rateLimit.sendResponse({ error: `You're not an admin!` }, 401);
|
||||||
|
|
||||||
|
const clearImages = formData.get("clearImages") === "true";
|
||||||
|
|
||||||
// Edit Mii in database
|
// Edit Mii in database
|
||||||
const updateData: Prisma.MiiUpdateInput = {};
|
const updateData: Prisma.MiiUpdateInput = {};
|
||||||
if (name !== undefined) updateData.name = profanity.censor(name); // Censor potentially inappropriate words
|
if (name !== undefined) updateData.name = profanity.censor(name); // Censor potentially inappropriate words
|
||||||
|
|
@ -168,8 +170,9 @@ export async function POST(request: NextRequest, { params }: { params: Promise<{
|
||||||
if (youtubeId !== undefined) updateData.youtubeId = youtubeId;
|
if (youtubeId !== undefined) updateData.youtubeId = youtubeId;
|
||||||
if (instructions !== undefined) updateData.instructions = instructions;
|
if (instructions !== undefined) updateData.instructions = instructions;
|
||||||
if (customImages.length > 0) updateData.imageCount = customImages.length;
|
if (customImages.length > 0) updateData.imageCount = customImages.length;
|
||||||
|
else if (clearImages) updateData.imageCount = 0;
|
||||||
|
|
||||||
const imagesChanged = customImages.length > 0 || miiPortraitImage || miiFeaturesImage;
|
const imagesChanged = customImages.length > 0 || clearImages || miiPortraitImage || miiFeaturesImage;
|
||||||
if (settings.queueEnabled && imagesChanged) updateData.in_queue = true;
|
if (settings.queueEnabled && imagesChanged) updateData.in_queue = true;
|
||||||
|
|
||||||
if (Object.keys(updateData).length === 0) return rateLimit.sendResponse({ error: "Nothing was changed" }, 400);
|
if (Object.keys(updateData).length === 0) return rateLimit.sendResponse({ error: "Nothing was changed" }, 400);
|
||||||
|
|
@ -192,7 +195,7 @@ export async function POST(request: NextRequest, { params }: { params: Promise<{
|
||||||
await fs.mkdir(miiUploadsDirectory, { recursive: true });
|
await fs.mkdir(miiUploadsDirectory, { recursive: true });
|
||||||
|
|
||||||
// Only touch files if new images were uploaded
|
// Only touch files if new images were uploaded
|
||||||
if (customImages.length > 0) {
|
if (customImages.length > 0 || clearImages) {
|
||||||
// Delete all custom images
|
// Delete all custom images
|
||||||
const files = await fs.readdir(miiUploadsDirectory);
|
const files = await fs.readdir(miiUploadsDirectory);
|
||||||
await Promise.all(files.filter((file) => file.startsWith("image")).map((file) => fs.unlink(path.join(miiUploadsDirectory, file))));
|
await Promise.all(files.filter((file) => file.startsWith("image")).map((file) => fs.unlink(path.join(miiUploadsDirectory, file))));
|
||||||
|
|
|
||||||
|
|
@ -87,10 +87,9 @@ export default function EditMiiPage() {
|
||||||
formData.append("instructions", JSON.stringify(instructions.current));
|
formData.append("instructions", JSON.stringify(instructions.current));
|
||||||
|
|
||||||
if (hasCustomImagesChanged.current) {
|
if (hasCustomImagesChanged.current) {
|
||||||
files.forEach((file, index) => {
|
|
||||||
// image1, image2, etc.
|
// image1, image2, etc.
|
||||||
formData.append(`image${index + 1}`, file);
|
files.forEach((file, index) => formData.append(`image${index + 1}`, file));
|
||||||
});
|
if (files.length === 0) formData.append("clearImages", "true");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Switch pictures
|
// Switch pictures
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue