partial: add admin game annotations

This commit is contained in:
DecDuck
2025-08-09 22:41:53 +10:00
parent e3feaeb970
commit 29fdfcbdd4
10 changed files with 56 additions and 16 deletions

View File

@ -1,6 +1,10 @@
import aclManager from "~/server/internal/acls";
import prisma from "~/server/internal/db/database";
/**
* Delete a game from this instance
* @param id Game ID
*/
export default defineEventHandler(async (h3) => {
const allowed = await aclManager.allowSystemACL(h3, ["game:delete"]);
if (!allowed) throw createError({ statusCode: 403 });

View File

@ -2,6 +2,10 @@ import aclManager from "~/server/internal/acls";
import prisma from "~/server/internal/db/database";
import libraryManager from "~/server/internal/library";
/**
* Fetch a game by ID
* @param id Game ID
*/
export default defineEventHandler(async (h3) => {
const allowed = await aclManager.allowSystemACL(h3, ["game:read"]);
if (!allowed) throw createError({ statusCode: 403 });

View File

@ -1,6 +1,11 @@
import aclManager from "~/server/internal/acls";
import prisma from "~/server/internal/db/database";
/**
* Update a game's metadata
* @request Partial of data returned by GET
* @param id Game ID
*/
export default defineEventHandler(async (h3) => {
const allowed = await aclManager.allowSystemACL(h3, ["game:update"]);
if (!allowed) throw createError({ statusCode: 403 });

View File

@ -3,6 +3,11 @@ import aclManager from "~/server/internal/acls";
import prisma from "~/server/internal/db/database";
import { handleFileUpload } from "~/server/internal/utils/handlefileupload";
/**
* Update icon, name, and/or description
* @request `multipart/form-data`, any file will become the icon, and `name` and `description` will become their respective fields.
* @param id Game ID
*/
export default defineEventHandler(async (h3) => {
const allowed = await aclManager.allowSystemACL(h3, ["game:update"]);
if (!allowed) throw createError({ statusCode: 403 });

View File

@ -7,23 +7,29 @@ const PatchTags = type({
tags: "string[]",
}).configure(throwingArktype);
export default defineEventHandler(async (h3) => {
const allowed = await aclManager.allowSystemACL(h3, ["game:update"]);
if (!allowed) throw createError({ statusCode: 403 });
/**
* Update the tags associated with this game.
* @param id Game ID
*/
export default defineEventHandler<{ body: typeof PatchTags.infer }>(
async (h3) => {
const allowed = await aclManager.allowSystemACL(h3, ["game:update"]);
if (!allowed) throw createError({ statusCode: 403 });
const body = await readDropValidatedBody(h3, PatchTags);
const id = getRouterParam(h3, "id")!;
const body = await readDropValidatedBody(h3, PatchTags);
const id = getRouterParam(h3, "id")!;
await prisma.game.update({
where: {
id,
},
data: {
tags: {
connect: body.tags.map((e) => ({ id: e })),
await prisma.game.update({
where: {
id,
},
},
});
data: {
tags: {
connect: body.tags.map((e) => ({ id: e })),
},
},
});
return;
});
return;
},
);

View File

@ -9,6 +9,9 @@ const DeleteGameImage = type({
imageId: "string",
}).configure(throwingArktype);
/**
* Delete a game's image
*/
export default defineEventHandler<{
body: typeof DeleteGameImage.infer;
}>(async (h3) => {

View File

@ -2,6 +2,10 @@ import aclManager from "~/server/internal/acls";
import prisma from "~/server/internal/db/database";
import { handleFileUpload } from "~/server/internal/utils/handlefileupload";
/**
* Upload a game to a game's image library
* @request `multipart/form-data`. All files will be uploaded as images. Set the game ID in the `id` field.
*/
export default defineEventHandler(async (h3) => {
const allowed = await aclManager.allowSystemACL(h3, ["game:image:new"]);
if (!allowed) throw createError({ statusCode: 403 });

View File

@ -1,6 +1,9 @@
import aclManager from "~/server/internal/acls";
import prisma from "~/server/internal/db/database";
/**
* Fetch brief metadata on all games connected to this instance
*/
export default defineEventHandler(async (h3) => {
const allowed = await aclManager.allowSystemACL(h3, ["game:read"]);
if (!allowed) throw createError({ statusCode: 403 });

View File

@ -8,6 +8,9 @@ const DeleteVersion = type({
versionName: "string",
}).configure(throwingArktype);
/**
* Delete a game's version
*/
export default defineEventHandler<{ body: typeof DeleteVersion.infer }>(
async (h3) => {
const allowed = await aclManager.allowSystemACL(h3, [

View File

@ -8,6 +8,9 @@ const UpdateVersionOrder = type({
versions: "string[]",
}).configure(throwingArktype);
/**
* Update the version order of a game.
*/
export default defineEventHandler<{ body: typeof UpdateVersionOrder.infer }>(
async (h3) => {
const allowed = await aclManager.allowSystemACL(h3, [