diff --git a/server/api/v1/admin/index.get.ts b/server/api/v1/admin/index.get.ts index 9d52d0f..5ef72c0 100644 --- a/server/api/v1/admin/index.get.ts +++ b/server/api/v1/admin/index.get.ts @@ -1,5 +1,8 @@ import aclManager from "~/server/internal/acls"; +/** + * Check if we are an admin/system + */ export default defineEventHandler(async (h3) => { const allowed = await aclManager.allowSystemACL(h3, []); if (!allowed) return false; diff --git a/server/api/v1/admin/library/index.get.ts b/server/api/v1/admin/library/index.get.ts index d0a0047..5a23f81 100644 --- a/server/api/v1/admin/library/index.get.ts +++ b/server/api/v1/admin/library/index.get.ts @@ -1,6 +1,9 @@ import aclManager from "~/server/internal/acls"; import libraryManager from "~/server/internal/library"; +/** + * Fetch library data for admin UI + */ export default defineEventHandler(async (h3) => { const allowed = await aclManager.allowSystemACL(h3, ["library:read"]); if (!allowed) throw createError({ statusCode: 403 }); diff --git a/server/api/v1/admin/library/sources/index.delete.ts b/server/api/v1/admin/library/sources/index.delete.ts index 165a9b2..172b962 100644 --- a/server/api/v1/admin/library/sources/index.delete.ts +++ b/server/api/v1/admin/library/sources/index.delete.ts @@ -8,6 +8,9 @@ const DeleteLibrarySource = type({ id: "string", }).configure(throwingArktype); +/** + * Delete a given library source + */ export default defineEventHandler<{ body: typeof DeleteLibrarySource.infer }>( async (h3) => { const allowed = await aclManager.allowSystemACL(h3, [ diff --git a/server/api/v1/admin/library/sources/index.get.ts b/server/api/v1/admin/library/sources/index.get.ts index bf56134..68bf9a2 100644 --- a/server/api/v1/admin/library/sources/index.get.ts +++ b/server/api/v1/admin/library/sources/index.get.ts @@ -4,6 +4,9 @@ import libraryManager from "~/server/internal/library"; export type WorkingLibrarySource = LibraryModel & { working: boolean }; +/** + * Fetch all library sources on this instance + */ export default defineEventHandler(async (h3) => { const allowed = await aclManager.allowSystemACL(h3, [ "library:sources:read", diff --git a/server/api/v1/admin/library/sources/index.patch.ts b/server/api/v1/admin/library/sources/index.patch.ts index f098b7a..dca73f7 100644 --- a/server/api/v1/admin/library/sources/index.patch.ts +++ b/server/api/v1/admin/library/sources/index.patch.ts @@ -12,6 +12,9 @@ const UpdateLibrarySource = type({ options: "object", }).configure(throwingArktype); +/** + * Update a library source's options. Validates options and live-updates the source. + */ export default defineEventHandler<{ body: typeof UpdateLibrarySource.infer }>( async (h3) => { const allowed = await aclManager.allowSystemACL(h3, [ diff --git a/server/api/v1/admin/library/sources/index.post.ts b/server/api/v1/admin/library/sources/index.post.ts index ae32b75..a2a6ee6 100644 --- a/server/api/v1/admin/library/sources/index.post.ts +++ b/server/api/v1/admin/library/sources/index.post.ts @@ -14,6 +14,9 @@ const CreateLibrarySource = type({ options: "object", }).configure(throwingArktype); +/** + * Create a new library source with options + */ export default defineEventHandler<{ body: typeof CreateLibrarySource.infer }>( async (h3) => { const allowed = await aclManager.allowSystemACL(h3, [ diff --git a/server/api/v1/admin/news/[id]/index.delete.ts b/server/api/v1/admin/news/[id]/index.delete.ts index 30c4913..d239bb4 100644 --- a/server/api/v1/admin/news/[id]/index.delete.ts +++ b/server/api/v1/admin/news/[id]/index.delete.ts @@ -2,6 +2,10 @@ import { defineEventHandler, createError } from "h3"; import aclManager from "~/server/internal/acls"; import newsManager from "~/server/internal/news"; +/** + * Delete a news article + * @param id Article ID + */ export default defineEventHandler(async (h3) => { const allowed = await aclManager.allowSystemACL(h3, ["news:delete"]); if (!allowed) diff --git a/server/api/v1/admin/news/[id]/index.get.ts b/server/api/v1/admin/news/[id]/index.get.ts index 50161e3..61a65ec 100644 --- a/server/api/v1/admin/news/[id]/index.get.ts +++ b/server/api/v1/admin/news/[id]/index.get.ts @@ -2,6 +2,10 @@ import { defineEventHandler, createError } from "h3"; import aclManager from "~/server/internal/acls"; import newsManager from "~/server/internal/news"; +/** + * Fetch a single news article + * @param id Article ID + */ export default defineEventHandler(async (h3) => { const allowed = await aclManager.allowSystemACL(h3, ["news:read"]); if (!allowed) diff --git a/server/api/v1/admin/news/index.get.ts b/server/api/v1/admin/news/index.get.ts index 392f4b7..d0e6133 100644 --- a/server/api/v1/admin/news/index.get.ts +++ b/server/api/v1/admin/news/index.get.ts @@ -2,6 +2,9 @@ import { defineEventHandler, getQuery } from "h3"; import aclManager from "~/server/internal/acls"; import newsManager from "~/server/internal/news"; +/** + * Fetch all news articles. + */ export default defineEventHandler(async (h3) => { const allowed = await aclManager.allowSystemACL(h3, ["news:read"]); if (!allowed) diff --git a/server/api/v1/admin/news/index.post.ts b/server/api/v1/admin/news/index.post.ts index fb09c2e..386e108 100644 --- a/server/api/v1/admin/news/index.post.ts +++ b/server/api/v1/admin/news/index.post.ts @@ -11,51 +11,56 @@ const CreateNews = type({ tags: "string = '[]'", }); -export default defineEventHandler(async (h3) => { - const allowed = await aclManager.allowSystemACL(h3, ["news:create"]); - if (!allowed) throw createError({ statusCode: 403 }); +/** + * Create a new news article + */ +export default defineEventHandler<{ body: typeof CreateNews.infer }>( + async (h3) => { + const allowed = await aclManager.allowSystemACL(h3, ["news:create"]); + 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 form = await readMultipartFormData(h3); + if (!form) + throw createError({ + statusCode: 400, + statusMessage: "This endpoint requires multipart form data.", + }); + + const uploadResult = await handleFileUpload(h3, {}, ["internal:read"], 1); + if (!uploadResult) + throw createError({ + statusCode: 400, + statusMessage: "Failed to upload file", + }); + + const [imageIds, options, pull, _dump] = uploadResult; + + const body = await CreateNews(options); + if (body instanceof ArkErrors) + throw createError({ statusCode: 400, statusMessage: body.summary }); + + const parsedTags = JSON.parse(body.tags); + if (typeof parsedTags !== "object" || !Array.isArray(parsedTags)) + throw createError({ + statusCode: 400, + statusMessage: "Tags must be an array", + }); + + const imageId = imageIds.at(0); + + const article = await newsManager.create({ + title: body.title, + description: body.description, + content: body.content, + + tags: parsedTags, + + ...(imageId && { imageObjectId: imageId }), + authorId: "system", }); - const uploadResult = await handleFileUpload(h3, {}, ["internal:read"], 1); - if (!uploadResult) - throw createError({ - statusCode: 400, - statusMessage: "Failed to upload file", - }); + await pull(); - const [imageIds, options, pull, _dump] = uploadResult; - - const body = await CreateNews(options); - if (body instanceof ArkErrors) - throw createError({ statusCode: 400, statusMessage: body.summary }); - - const parsedTags = JSON.parse(body.tags); - if (typeof parsedTags !== "object" || !Array.isArray(parsedTags)) - throw createError({ - statusCode: 400, - statusMessage: "Tags must be an array", - }); - - const imageId = imageIds.at(0); - - const article = await newsManager.create({ - title: body.title, - description: body.description, - content: body.content, - - tags: parsedTags, - - ...(imageId && { imageObjectId: imageId }), - authorId: "system", - }); - - await pull(); - - return article; -}); + return article; + }, +); diff --git a/server/api/v1/admin/settings/dummy-data.get.ts b/server/api/v1/admin/settings/dummy-data.get.ts index 6f62372..af7d0c8 100644 --- a/server/api/v1/admin/settings/dummy-data.get.ts +++ b/server/api/v1/admin/settings/dummy-data.get.ts @@ -1,6 +1,9 @@ import aclManager from "~/server/internal/acls"; import prisma from "~/server/internal/db/database"; +/** + * Fetch dummy data for rendering the settings page. + */ export default defineEventHandler(async (h3) => { const allowed = await aclManager.getUserACL(h3, ["settings:read"]); if (!allowed) throw createError({ statusCode: 403 }); diff --git a/server/api/v1/admin/settings/index.patch.ts b/server/api/v1/admin/settings/index.patch.ts index ef99441..7282777 100644 --- a/server/api/v1/admin/settings/index.patch.ts +++ b/server/api/v1/admin/settings/index.patch.ts @@ -8,6 +8,9 @@ const UpdateSettings = type({ showGamePanelTextDecoration: "boolean", }); +/** + * Update global Drop settings. + */ export default defineEventHandler<{ body: typeof UpdateSettings.infer }>( async (h3) => { const allowed = await aclManager.allowSystemACL(h3, ["settings:update"]); diff --git a/server/api/v1/admin/tags/[id]/index.delete.ts b/server/api/v1/admin/tags/[id]/index.delete.ts index 69a865f..be15ac3 100644 --- a/server/api/v1/admin/tags/[id]/index.delete.ts +++ b/server/api/v1/admin/tags/[id]/index.delete.ts @@ -2,9 +2,8 @@ import aclManager from "~/server/internal/acls"; import prisma from "~/server/internal/db/database"; /** - * This route allows you to delete game organization tags. - * - * @param {string} id test + * Delete game tags. + * @param id Tag ID */ export default defineEventHandler(async (h3) => { const allowed = await aclManager.allowSystemACL(h3, ["tags:delete"]); diff --git a/server/api/v1/admin/tags/index.get.ts b/server/api/v1/admin/tags/index.get.ts index d8f1c1e..09f5330 100644 --- a/server/api/v1/admin/tags/index.get.ts +++ b/server/api/v1/admin/tags/index.get.ts @@ -1,6 +1,9 @@ import aclManager from "~/server/internal/acls"; import prisma from "~/server/internal/db/database"; +/** + * Fetch all game tags + */ export default defineEventHandler(async (h3) => { const allowed = await aclManager.allowSystemACL(h3, ["tags:read"]); if (!allowed) throw createError({ statusCode: 403 }); diff --git a/server/api/v1/admin/tags/index.post.ts b/server/api/v1/admin/tags/index.post.ts index 15698e7..8961378 100644 --- a/server/api/v1/admin/tags/index.post.ts +++ b/server/api/v1/admin/tags/index.post.ts @@ -7,16 +7,21 @@ const CreateTag = type({ name: "string", }).configure(throwingArktype); -export default defineEventHandler(async (h3) => { - const allowed = await aclManager.allowSystemACL(h3, ["tags:read"]); - if (!allowed) throw createError({ statusCode: 403 }); +/** + * Create a game tag + */ +export default defineEventHandler<{ body: typeof CreateTag.infer }>( + async (h3) => { + const allowed = await aclManager.allowSystemACL(h3, ["tags:read"]); + if (!allowed) throw createError({ statusCode: 403 }); - const body = await readDropValidatedBody(h3, CreateTag); + const body = await readDropValidatedBody(h3, CreateTag); - const tag = await prisma.gameTag.create({ - data: { - ...body, - }, - }); - return tag; -}); + const tag = await prisma.gameTag.create({ + data: { + ...body, + }, + }); + return tag; + }, +); diff --git a/server/api/v1/admin/task/index.get.ts b/server/api/v1/admin/task/index.get.ts index a81492c..e7cd55f 100644 --- a/server/api/v1/admin/task/index.get.ts +++ b/server/api/v1/admin/task/index.get.ts @@ -2,6 +2,9 @@ import aclManager from "~/server/internal/acls"; import prisma from "~/server/internal/db/database"; import taskHandler from "~/server/internal/tasks"; +/** + * Fetches all tasks that the current token has access to (ACL-based) + */ export default defineEventHandler(async (h3) => { const allowed = await aclManager.allowSystemACL(h3, ["task:read"]); if (!allowed) throw createError({ statusCode: 403 }); diff --git a/server/api/v1/admin/users/[id]/index.delete.ts b/server/api/v1/admin/users/[id]/index.delete.ts index c514817..bad194e 100644 --- a/server/api/v1/admin/users/[id]/index.delete.ts +++ b/server/api/v1/admin/users/[id]/index.delete.ts @@ -2,6 +2,10 @@ import { defineEventHandler, createError } from "h3"; import aclManager from "~/server/internal/acls"; import prisma from "~/server/internal/db/database"; +/** + * Delete a user + * @param id User ID + */ export default defineEventHandler(async (h3) => { const allowed = await aclManager.allowSystemACL(h3, ["user:delete"]); if (!allowed) diff --git a/server/api/v1/admin/users/[id]/index.get.ts b/server/api/v1/admin/users/[id]/index.get.ts index f90db23..2f2a7a0 100644 --- a/server/api/v1/admin/users/[id]/index.get.ts +++ b/server/api/v1/admin/users/[id]/index.get.ts @@ -1,6 +1,10 @@ import aclManager from "~/server/internal/acls"; import prisma from "~/server/internal/db/database"; +/** + * Fetch a user by ID + * @param id User ID + */ export default defineEventHandler(async (h3) => { const allowed = await aclManager.allowSystemACL(h3, ["user:read"]); if (!allowed) throw createError({ statusCode: 403 }); diff --git a/server/api/v1/admin/users/index.get.ts b/server/api/v1/admin/users/index.get.ts index 43a90fe..0aaddb4 100644 --- a/server/api/v1/admin/users/index.get.ts +++ b/server/api/v1/admin/users/index.get.ts @@ -1,6 +1,9 @@ import aclManager from "~/server/internal/acls"; import prisma from "~/server/internal/db/database"; +/** + * Fetch all users and their enabled authentication mechanisms + */ export default defineEventHandler(async (h3) => { const allowed = await aclManager.allowSystemACL(h3, ["user:read"]); if (!allowed) throw createError({ statusCode: 403 });