mirror of
https://github.com/Drop-OSS/drop.git
synced 2025-11-12 07:42:40 +10:00
Store overhaul (#142)
* feat: small library tweaks + company page * feat: new store view * fix: ci merge error * feat: add genres to store page * feat: sorting * feat: lock game/version imports while their tasks are running * feat: feature games * feat: tag based filtering * fix: make tags alphabetical * refactor: move a bunch of i18n to common * feat: add localizations for everything * fix: title description on panel * fix: feature carousel text * fix: i18n footer strings * feat: add tag page * fix: develop merge * feat: offline games support (don't error out if provider throws) * feat: tag management * feat: show library next to game import + small fixes * feat: most of the company and tag managers * feat: company text field editing * fix: small fixes + tsgo experiemental * feat: upload icon and banner * feat: store infinite scrolling and bulk import mode * fix: lint * fix: add drop-base to prettier ignore
This commit is contained in:
63
server/api/v1/admin/game/[id]/metadata.post.ts
Normal file
63
server/api/v1/admin/game/[id]/metadata.post.ts
Normal file
@ -0,0 +1,63 @@
|
||||
import type { Prisma } from "~/prisma/client/client";
|
||||
import aclManager from "~/server/internal/acls";
|
||||
import prisma from "~/server/internal/db/database";
|
||||
import { handleFileUpload } from "~/server/internal/utils/handlefileupload";
|
||||
|
||||
export default defineEventHandler(async (h3) => {
|
||||
const allowed = await aclManager.allowSystemACL(h3, ["game:update"]);
|
||||
if (!allowed) throw createError({ statusCode: 403 });
|
||||
|
||||
const form = await readMultipartFormData(h3);
|
||||
if (!form)
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "This endpoint requires multipart form data.",
|
||||
});
|
||||
|
||||
const gameId = getRouterParam(h3, "id")!;
|
||||
|
||||
const uploadResult = await handleFileUpload(h3, {}, ["internal:read"], 1);
|
||||
if (!uploadResult)
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "Failed to upload file",
|
||||
});
|
||||
|
||||
const [ids, options, pull, dump] = uploadResult;
|
||||
|
||||
const id = ids.at(0);
|
||||
|
||||
// handleFileUpload reads the rest of the options for us.
|
||||
const name = options.name;
|
||||
const description = options.description;
|
||||
|
||||
const updateModel: Prisma.GameUpdateInput = {
|
||||
mName: name,
|
||||
mShortDescription: description,
|
||||
};
|
||||
|
||||
// handle if user uploaded new icon
|
||||
if (id) {
|
||||
updateModel.mIconObjectId = id;
|
||||
await pull();
|
||||
} else {
|
||||
dump();
|
||||
}
|
||||
|
||||
// If the API call doesn't provide values, don't set them
|
||||
for (const [key, value] of Object.entries(updateModel)) {
|
||||
if (value === undefined) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
||||
delete updateModel[key as keyof typeof updateModel];
|
||||
}
|
||||
}
|
||||
|
||||
const newObject = await prisma.game.update({
|
||||
where: {
|
||||
id: gameId,
|
||||
},
|
||||
data: updateModel,
|
||||
});
|
||||
|
||||
return newObject;
|
||||
});
|
||||
Reference in New Issue
Block a user