mirror of
https://github.com/Drop-OSS/drop.git
synced 2025-11-18 18:51:13 +10:00
working commit
This commit is contained in:
@ -12,14 +12,18 @@ export const LaunchCommands = type({
|
||||
launchArgs: "string = ''",
|
||||
}).array();
|
||||
|
||||
export const ImportVersion = type({
|
||||
const ImportVersionBase = type({
|
||||
id: "string",
|
||||
version: "string",
|
||||
name: "string?",
|
||||
|
||||
platform: "string",
|
||||
onlySetup: "boolean = false",
|
||||
delta: "boolean = false",
|
||||
});
|
||||
|
||||
const ImportGameVersion = type({
|
||||
mode: "'game'",
|
||||
onlySetup: "boolean = false",
|
||||
umuId: "string = ''",
|
||||
|
||||
install: "string?",
|
||||
@ -27,7 +31,26 @@ export const ImportVersion = type({
|
||||
launches: LaunchCommands,
|
||||
uninstall: "string?",
|
||||
uninstallArgs: "string?",
|
||||
}).configure(throwingArktype);
|
||||
});
|
||||
|
||||
const ImportRedistVersion = type({
|
||||
mode: "'redist'",
|
||||
install: "string?",
|
||||
installArgs: "string?",
|
||||
launches: LaunchCommands,
|
||||
uninstall: "string?",
|
||||
uninstallArgs: "string?",
|
||||
});
|
||||
|
||||
export const ImportVersion = ImportVersionBase.and(
|
||||
ImportGameVersion.or(ImportRedistVersion),
|
||||
).configure(throwingArktype);
|
||||
|
||||
export type ImportGameVersion = typeof ImportVersionBase.infer &
|
||||
typeof ImportGameVersion.infer;
|
||||
|
||||
export type ImportRedistVersion = typeof ImportVersionBase.infer &
|
||||
typeof ImportRedistVersion.infer;
|
||||
|
||||
export default defineEventHandler(async (h3) => {
|
||||
const allowed = await aclManager.allowSystemACL(h3, ["import:version:new"]);
|
||||
@ -35,48 +58,10 @@ export default defineEventHandler(async (h3) => {
|
||||
|
||||
const body = await readDropValidatedBody(h3, ImportVersion);
|
||||
|
||||
const platform = await convertIDToLink(body.platform);
|
||||
if (!platform)
|
||||
throw createError({ statusCode: 400, message: "Invalid platform." });
|
||||
|
||||
if (body.delta) {
|
||||
const validOverlayVersions = await prisma.gameVersion.count({
|
||||
where: {
|
||||
version: {
|
||||
gameId: body.id,
|
||||
},
|
||||
delta: false,
|
||||
platform,
|
||||
},
|
||||
});
|
||||
if (validOverlayVersions == 0)
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
message:
|
||||
"Update mode requires a pre-existing version for this platform.",
|
||||
});
|
||||
}
|
||||
|
||||
if (body.onlySetup) {
|
||||
if (!body.install)
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
message: 'Install required in "setup mode".',
|
||||
});
|
||||
} else {
|
||||
if (!body.delta && body.launches.length == 0)
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
message:
|
||||
"At least one launch command is required for non-delta versions",
|
||||
});
|
||||
}
|
||||
|
||||
// startup & delta require more complex checking logic
|
||||
const taskId = await libraryManager.importVersion(
|
||||
body.id,
|
||||
body.version,
|
||||
"game",
|
||||
body,
|
||||
);
|
||||
if (!taskId)
|
||||
|
||||
@ -1,22 +1,26 @@
|
||||
import { ArkErrors, type } from "arktype";
|
||||
import aclManager from "~~/server/internal/acls";
|
||||
import libraryManager from "~~/server/internal/library";
|
||||
import libraryManager, { VersionImportModes } from "~~/server/internal/library";
|
||||
|
||||
export const PreloadQuery = type({
|
||||
id: "string",
|
||||
version: "string",
|
||||
mode: type.enumerated(...VersionImportModes),
|
||||
});
|
||||
|
||||
export default defineEventHandler(async (h3) => {
|
||||
const allowed = await aclManager.allowSystemACL(h3, ["import:version:read"]);
|
||||
if (!allowed) throw createError({ statusCode: 403 });
|
||||
|
||||
const query = await getQuery(h3);
|
||||
const gameId = query.id?.toString();
|
||||
const versionName = query.version?.toString();
|
||||
if (!gameId || !versionName)
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
message: "Missing id or version in request params",
|
||||
});
|
||||
const rawQuery = await getQuery(h3);
|
||||
const query = PreloadQuery(rawQuery);
|
||||
if (query instanceof ArkErrors)
|
||||
throw createError({ statusCode: 400, message: query.summary });
|
||||
|
||||
const preload = await libraryManager.fetchUnimportedVersionInformation(
|
||||
gameId,
|
||||
versionName,
|
||||
query.id,
|
||||
query.mode,
|
||||
query.version,
|
||||
);
|
||||
if (!preload)
|
||||
throw createError({
|
||||
|
||||
Reference in New Issue
Block a user