From 29fdfcbdd4f4b75cd04cbe726ce99f1e18f0cbfa Mon Sep 17 00:00:00 2001 From: DecDuck Date: Sat, 9 Aug 2025 22:41:53 +1000 Subject: [PATCH] partial: add admin game annotations --- server/api/v1/admin/game/[id]/index.delete.ts | 4 ++ server/api/v1/admin/game/[id]/index.get.ts | 4 ++ server/api/v1/admin/game/[id]/index.patch.ts | 5 +++ .../api/v1/admin/game/[id]/metadata.post.ts | 5 +++ server/api/v1/admin/game/[id]/tags.patch.ts | 38 +++++++++++-------- .../api/v1/admin/game/image/index.delete.ts | 3 ++ server/api/v1/admin/game/image/index.post.ts | 4 ++ server/api/v1/admin/game/index.get.ts | 3 ++ .../api/v1/admin/game/version/index.delete.ts | 3 ++ .../api/v1/admin/game/version/index.patch.ts | 3 ++ 10 files changed, 56 insertions(+), 16 deletions(-) diff --git a/server/api/v1/admin/game/[id]/index.delete.ts b/server/api/v1/admin/game/[id]/index.delete.ts index 2a0645d..3f8a377 100644 --- a/server/api/v1/admin/game/[id]/index.delete.ts +++ b/server/api/v1/admin/game/[id]/index.delete.ts @@ -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 }); diff --git a/server/api/v1/admin/game/[id]/index.get.ts b/server/api/v1/admin/game/[id]/index.get.ts index 44693dc..fe7697d 100644 --- a/server/api/v1/admin/game/[id]/index.get.ts +++ b/server/api/v1/admin/game/[id]/index.get.ts @@ -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 }); diff --git a/server/api/v1/admin/game/[id]/index.patch.ts b/server/api/v1/admin/game/[id]/index.patch.ts index 410adee..58b39b0 100644 --- a/server/api/v1/admin/game/[id]/index.patch.ts +++ b/server/api/v1/admin/game/[id]/index.patch.ts @@ -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 }); diff --git a/server/api/v1/admin/game/[id]/metadata.post.ts b/server/api/v1/admin/game/[id]/metadata.post.ts index cd1dcbc..f0d6610 100644 --- a/server/api/v1/admin/game/[id]/metadata.post.ts +++ b/server/api/v1/admin/game/[id]/metadata.post.ts @@ -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 }); diff --git a/server/api/v1/admin/game/[id]/tags.patch.ts b/server/api/v1/admin/game/[id]/tags.patch.ts index d7192ad..388b670 100644 --- a/server/api/v1/admin/game/[id]/tags.patch.ts +++ b/server/api/v1/admin/game/[id]/tags.patch.ts @@ -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; + }, +); diff --git a/server/api/v1/admin/game/image/index.delete.ts b/server/api/v1/admin/game/image/index.delete.ts index d89ae76..7b5ac46 100644 --- a/server/api/v1/admin/game/image/index.delete.ts +++ b/server/api/v1/admin/game/image/index.delete.ts @@ -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) => { diff --git a/server/api/v1/admin/game/image/index.post.ts b/server/api/v1/admin/game/image/index.post.ts index e230e9f..8199ba7 100644 --- a/server/api/v1/admin/game/image/index.post.ts +++ b/server/api/v1/admin/game/image/index.post.ts @@ -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 }); diff --git a/server/api/v1/admin/game/index.get.ts b/server/api/v1/admin/game/index.get.ts index c7ca363..3a4d4ea 100644 --- a/server/api/v1/admin/game/index.get.ts +++ b/server/api/v1/admin/game/index.get.ts @@ -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 }); diff --git a/server/api/v1/admin/game/version/index.delete.ts b/server/api/v1/admin/game/version/index.delete.ts index 58850ff..72600e8 100644 --- a/server/api/v1/admin/game/version/index.delete.ts +++ b/server/api/v1/admin/game/version/index.delete.ts @@ -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, [ diff --git a/server/api/v1/admin/game/version/index.patch.ts b/server/api/v1/admin/game/version/index.patch.ts index cc9b5fa..bf59b58 100644 --- a/server/api/v1/admin/game/version/index.patch.ts +++ b/server/api/v1/admin/game/version/index.patch.ts @@ -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, [