partial: annotate rest of admin routes

This commit is contained in:
DecDuck
2025-08-10 09:26:20 +10:00
parent 90b02b7f8e
commit 80f7757558
19 changed files with 119 additions and 58 deletions

View File

@ -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;

View File

@ -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 });

View File

@ -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, [

View File

@ -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",

View File

@ -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, [

View File

@ -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, [

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -11,7 +11,11 @@ const CreateNews = type({
tags: "string = '[]'",
});
export default defineEventHandler(async (h3) => {
/**
* 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 });
@ -58,4 +62,5 @@ export default defineEventHandler(async (h3) => {
await pull();
return article;
});
},
);

View File

@ -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 });

View File

@ -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"]);

View File

@ -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"]);

View File

@ -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 });

View File

@ -7,7 +7,11 @@ const CreateTag = type({
name: "string",
}).configure(throwingArktype);
export default defineEventHandler(async (h3) => {
/**
* 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 });
@ -19,4 +23,5 @@ export default defineEventHandler(async (h3) => {
},
});
return tag;
});
},
);

View File

@ -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 });

View File

@ -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)

View File

@ -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 });

View File

@ -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 });