mirror of
https://github.com/Drop-OSS/drop.git
synced 2025-11-15 17:21:13 +10:00
feat: add server side redist patching
This commit is contained in:
38
server/api/v1/admin/redist/[id]/index.get.ts
Normal file
38
server/api/v1/admin/redist/[id]/index.get.ts
Normal file
@ -0,0 +1,38 @@
|
||||
import aclManager from "~/server/internal/acls";
|
||||
import prisma from "~/server/internal/db/database";
|
||||
import libraryManager from "~/server/internal/library";
|
||||
|
||||
export default defineEventHandler(async (h3) => {
|
||||
const allowed = await aclManager.allowSystemACL(h3, ["redist:read"]);
|
||||
if (!allowed) throw createError({ statusCode: 403 });
|
||||
|
||||
const id = getRouterParam(h3, "id")!;
|
||||
|
||||
const redist = await prisma.redist.findUnique({
|
||||
where: {
|
||||
id,
|
||||
},
|
||||
include: {
|
||||
platform: true,
|
||||
versions: true,
|
||||
},
|
||||
});
|
||||
if (!redist)
|
||||
throw createError({
|
||||
statusCode: 404,
|
||||
message: "Redistributable not found.",
|
||||
});
|
||||
|
||||
const unimportedVersions = await libraryManager.fetchUnimportedGameVersions(
|
||||
redist.libraryId,
|
||||
redist.libraryPath,
|
||||
);
|
||||
|
||||
if (!unimportedVersions)
|
||||
throw createError({
|
||||
statusCode: 500,
|
||||
message: "Failed to fetch unimported versions for redistributable.",
|
||||
});
|
||||
|
||||
return { redist, unimportedVersions };
|
||||
});
|
||||
27
server/api/v1/admin/redist/[id]/index.patch.ts
Normal file
27
server/api/v1/admin/redist/[id]/index.patch.ts
Normal file
@ -0,0 +1,27 @@
|
||||
import aclManager from "~/server/internal/acls";
|
||||
import prisma from "~/server/internal/db/database";
|
||||
|
||||
export default defineEventHandler(async (h3) => {
|
||||
const allowed = await aclManager.allowSystemACL(h3, ["redist:update"]);
|
||||
if (!allowed) throw createError({ statusCode: 403 });
|
||||
|
||||
const body = await readBody(h3);
|
||||
|
||||
const id = body.id;
|
||||
if (!id || typeof id !== "string")
|
||||
throw createError({ statusCode: 400, message: "ID required in body." });
|
||||
|
||||
const updateParams = body;
|
||||
delete updateParams["id"];
|
||||
|
||||
try {
|
||||
return await prisma.redist.update({
|
||||
where: {
|
||||
id,
|
||||
},
|
||||
data: updateParams,
|
||||
});
|
||||
} catch (e) {
|
||||
throw createError({ statusCode: 400, message: (e as string)?.toString() });
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user