mirror of
https://github.com/Drop-OSS/drop.git
synced 2025-11-13 16:22:39 +10:00
feat: rearchitecture of database schemas, migration reset, and #180
This commit is contained in:
@ -14,14 +14,26 @@ export default defineEventHandler(async (h3) => {
|
||||
},
|
||||
include: {
|
||||
versions: {
|
||||
where: {
|
||||
gameVersion: {
|
||||
isNot: null,
|
||||
},
|
||||
},
|
||||
orderBy: {
|
||||
versionIndex: "asc",
|
||||
gameVersion: {
|
||||
versionIndex: "asc",
|
||||
},
|
||||
},
|
||||
select: {
|
||||
versionIndex: true,
|
||||
versionId: true,
|
||||
versionName: true,
|
||||
platform: true,
|
||||
delta: true,
|
||||
gameVersion: {
|
||||
select: {
|
||||
versionIndex: true,
|
||||
delta: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
tags: true,
|
||||
|
||||
@ -5,7 +5,6 @@ import prisma from "~/server/internal/db/database";
|
||||
|
||||
const DeleteVersion = type({
|
||||
id: "string",
|
||||
versionName: "string",
|
||||
}).configure(throwingArktype);
|
||||
|
||||
export default defineEventHandler<{ body: typeof DeleteVersion }>(
|
||||
@ -17,15 +16,9 @@ export default defineEventHandler<{ body: typeof DeleteVersion }>(
|
||||
|
||||
const body = await readDropValidatedBody(h3, DeleteVersion);
|
||||
|
||||
const gameId = body.id.toString();
|
||||
const version = body.versionName.toString();
|
||||
|
||||
await prisma.gameVersion.delete({
|
||||
await prisma.version.delete({
|
||||
where: {
|
||||
gameId_versionName: {
|
||||
gameId: gameId,
|
||||
versionName: version,
|
||||
},
|
||||
versionId: body.id,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@ -16,32 +16,24 @@ export default defineEventHandler<{ body: typeof UpdateVersionOrder }>(
|
||||
if (!allowed) throw createError({ statusCode: 403 });
|
||||
|
||||
const body = await readDropValidatedBody(h3, UpdateVersionOrder);
|
||||
const gameId = body.id;
|
||||
// We expect an array of the version names for this game
|
||||
const versions = body.versions;
|
||||
|
||||
const newVersions = await prisma.$transaction(
|
||||
versions.map((versionName, versionIndex) =>
|
||||
await prisma.$transaction(
|
||||
versions.map((versionId, versionIndex) =>
|
||||
prisma.gameVersion.update({
|
||||
where: {
|
||||
gameId_versionName: {
|
||||
gameId: gameId,
|
||||
versionName: versionName,
|
||||
},
|
||||
versionId,
|
||||
},
|
||||
data: {
|
||||
versionIndex: versionIndex,
|
||||
},
|
||||
select: {
|
||||
versionIndex: true,
|
||||
versionName: true,
|
||||
platform: true,
|
||||
delta: true,
|
||||
},
|
||||
select: {},
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
return newVersions;
|
||||
setResponseStatus(h3, 201);
|
||||
return;
|
||||
},
|
||||
);
|
||||
|
||||
@ -1,48 +1,42 @@
|
||||
import { type } from "arktype";
|
||||
import { Platform } from "~/prisma/client/enums";
|
||||
import { readDropValidatedBody, throwingArktype } from "~/server/arktype";
|
||||
import aclManager from "~/server/internal/acls";
|
||||
import prisma from "~/server/internal/db/database";
|
||||
import libraryManager from "~/server/internal/library";
|
||||
import { parsePlatform } from "~/server/internal/utils/parseplatform";
|
||||
|
||||
const ImportVersion = type({
|
||||
export const ImportVersion = type({
|
||||
id: "string",
|
||||
version: "string",
|
||||
name: "string?",
|
||||
|
||||
platform: "string",
|
||||
launch: "string = ''",
|
||||
launchArgs: "string = ''",
|
||||
platform: type.valueOf(Platform),
|
||||
setup: "string = ''",
|
||||
setupArgs: "string = ''",
|
||||
onlySetup: "boolean = false",
|
||||
delta: "boolean = false",
|
||||
umuId: "string = ''",
|
||||
|
||||
launches: type({
|
||||
name: "string > 0",
|
||||
description: "string = ''",
|
||||
launchCommand: "string > 0",
|
||||
launchArgs: "string = ''",
|
||||
}).array(),
|
||||
}).configure(throwingArktype);
|
||||
|
||||
export default defineEventHandler(async (h3) => {
|
||||
const allowed = await aclManager.allowSystemACL(h3, ["import:version:new"]);
|
||||
if (!allowed) throw createError({ statusCode: 403 });
|
||||
|
||||
const {
|
||||
id,
|
||||
version,
|
||||
platform,
|
||||
launch,
|
||||
launchArgs,
|
||||
setup,
|
||||
setupArgs,
|
||||
onlySetup,
|
||||
delta,
|
||||
umuId,
|
||||
} = await readDropValidatedBody(h3, ImportVersion);
|
||||
const body = await readDropValidatedBody(h3, ImportVersion);
|
||||
|
||||
const platformParsed = parsePlatform(platform);
|
||||
if (!platformParsed)
|
||||
throw createError({ statusCode: 400, statusMessage: "Invalid platform." });
|
||||
|
||||
if (delta) {
|
||||
if (body.delta) {
|
||||
const validOverlayVersions = await prisma.gameVersion.count({
|
||||
where: { gameId: id, platform: platformParsed, delta: false },
|
||||
where: {
|
||||
version: { gameId: body.id, platform: body.platform },
|
||||
delta: false,
|
||||
},
|
||||
});
|
||||
if (validOverlayVersions == 0)
|
||||
throw createError({
|
||||
@ -52,33 +46,27 @@ export default defineEventHandler(async (h3) => {
|
||||
});
|
||||
}
|
||||
|
||||
if (onlySetup) {
|
||||
if (!setup)
|
||||
if (body.onlySetup) {
|
||||
if (!body.setup)
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: 'Setup required in "setup mode".',
|
||||
});
|
||||
} else {
|
||||
if (!delta && !launch)
|
||||
if (!body.delta && body.launches.length == 0)
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "Launch executable is required for non-update versions",
|
||||
statusMessage:
|
||||
"At least one launch command is required for non-delta versions",
|
||||
});
|
||||
}
|
||||
|
||||
// startup & delta require more complex checking logic
|
||||
const taskId = await libraryManager.importVersion(id, version, {
|
||||
platform,
|
||||
onlySetup,
|
||||
|
||||
launch,
|
||||
launchArgs,
|
||||
setup,
|
||||
setupArgs,
|
||||
|
||||
umuId,
|
||||
delta,
|
||||
});
|
||||
const taskId = await libraryManager.importVersion(
|
||||
body.id,
|
||||
body.version,
|
||||
body,
|
||||
);
|
||||
if (!taskId)
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
|
||||
@ -4,14 +4,13 @@ import manifestGenerator from "~/server/internal/downloads/manifest";
|
||||
export default defineClientEventHandler(async (h3) => {
|
||||
const query = getQuery(h3);
|
||||
const id = query.id?.toString();
|
||||
const version = query.version?.toString();
|
||||
if (!id || !version)
|
||||
if (!id)
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "Missing id or version in query",
|
||||
statusMessage: "Missing version id in query",
|
||||
});
|
||||
|
||||
const manifest = await manifestGenerator.generateManifest(id, version);
|
||||
const manifest = await manifestGenerator.generateManifest(id);
|
||||
if (!manifest)
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
|
||||
@ -13,10 +13,7 @@ export default defineClientEventHandler(async (h3) => {
|
||||
|
||||
const gameVersion = await prisma.gameVersion.findUnique({
|
||||
where: {
|
||||
gameId_versionName: {
|
||||
gameId: id,
|
||||
versionName: version,
|
||||
},
|
||||
versionId: id,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@ -12,26 +12,15 @@ export default defineClientEventHandler(async (h3) => {
|
||||
|
||||
const versions = await prisma.gameVersion.findMany({
|
||||
where: {
|
||||
gameId: id,
|
||||
version: {
|
||||
gameId: id,
|
||||
},
|
||||
hidden: false,
|
||||
},
|
||||
orderBy: {
|
||||
versionIndex: "desc", // Latest one first
|
||||
},
|
||||
});
|
||||
|
||||
const mappedVersions = versions
|
||||
.map((version) => {
|
||||
if (!version.dropletManifest) return undefined;
|
||||
|
||||
const newVersion = { ...version, dropletManifest: undefined };
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore idk why we delete an undefined object
|
||||
delete newVersion.dropletManifest;
|
||||
return {
|
||||
...newVersion,
|
||||
};
|
||||
})
|
||||
.filter((e) => e);
|
||||
|
||||
return mappedVersions;
|
||||
return versions;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user