feat: add server side redist patching

This commit is contained in:
DecDuck
2025-08-28 11:14:38 +10:00
parent ca7a89bbcf
commit cf3a458bdf
9 changed files with 218 additions and 71 deletions

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

View 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() });
}
});