mirror of
https://github.com/Drop-OSS/drop.git
synced 2026-01-31 15:37:09 +01:00
feat: version hiding
This commit is contained in:
@@ -1,20 +1,25 @@
|
||||
import { type } from "arktype";
|
||||
import { PlatformClient } from "~/composables/types";
|
||||
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",
|
||||
|
||||
platform: "string",
|
||||
platform: type.valueOf(PlatformClient),
|
||||
|
||||
launch: "string = ''",
|
||||
launchArgs: "string = ''",
|
||||
|
||||
setup: "string = ''",
|
||||
setupArgs: "string = ''",
|
||||
|
||||
onlySetup: "boolean = false",
|
||||
hide: "boolean = false",
|
||||
|
||||
delta: "boolean = false",
|
||||
umuId: "string = ''",
|
||||
}).configure(throwingArktype);
|
||||
@@ -34,15 +39,12 @@ export default defineEventHandler(async (h3) => {
|
||||
onlySetup,
|
||||
delta,
|
||||
umuId,
|
||||
hide,
|
||||
} = await readDropValidatedBody(h3, ImportVersion);
|
||||
|
||||
const platformParsed = parsePlatform(platform);
|
||||
if (!platformParsed)
|
||||
throw createError({ statusCode: 400, statusMessage: "Invalid platform." });
|
||||
|
||||
if (delta) {
|
||||
const validOverlayVersions = await prisma.gameVersion.count({
|
||||
where: { gameId: id, platform: platformParsed, delta: false },
|
||||
where: { gameId: id, platform, delta: false },
|
||||
});
|
||||
if (validOverlayVersions == 0)
|
||||
throw createError({
|
||||
@@ -75,6 +77,7 @@ export default defineEventHandler(async (h3) => {
|
||||
launchArgs,
|
||||
setup,
|
||||
setupArgs,
|
||||
hide,
|
||||
|
||||
umuId,
|
||||
delta,
|
||||
|
||||
@@ -17,6 +17,7 @@ export default defineClientEventHandler(async (h3) => {
|
||||
gameId: id,
|
||||
versionName: version,
|
||||
},
|
||||
hidden: false,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ export default defineClientEventHandler(async (h3) => {
|
||||
const versions = await prisma.gameVersion.findMany({
|
||||
where: {
|
||||
gameId: id,
|
||||
hidden: false,
|
||||
},
|
||||
orderBy: {
|
||||
versionIndex: "desc", // Latest one first
|
||||
|
||||
@@ -15,6 +15,7 @@ import { GameNotFoundError, type LibraryProvider } from "./provider";
|
||||
import { logger } from "../logging";
|
||||
import type { GameModel } from "~/prisma/client/models";
|
||||
import { createHash } from "node:crypto";
|
||||
import type { ImportVersion } from "~/server/api/v1/admin/import/version/index.post";
|
||||
|
||||
export function createGameImportTaskId(libraryId: string, libraryPath: string) {
|
||||
return createHash("md5")
|
||||
@@ -231,18 +232,7 @@ class LibraryManager {
|
||||
async importVersion(
|
||||
gameId: string,
|
||||
versionName: string,
|
||||
metadata: {
|
||||
platform: string;
|
||||
onlySetup: boolean;
|
||||
|
||||
setup: string;
|
||||
setupArgs: string;
|
||||
launch: string;
|
||||
launchArgs: string;
|
||||
delta: boolean;
|
||||
|
||||
umuId: string;
|
||||
},
|
||||
metadata: Omit<typeof ImportVersion.infer, "id" | "version">,
|
||||
) {
|
||||
const taskId = createVersionImportTaskId(gameId, versionName);
|
||||
|
||||
@@ -286,41 +276,24 @@ class LibraryManager {
|
||||
});
|
||||
|
||||
// Then, create the database object
|
||||
if (metadata.onlySetup) {
|
||||
await prisma.gameVersion.create({
|
||||
data: {
|
||||
gameId: gameId,
|
||||
versionName: versionName,
|
||||
dropletManifest: manifest,
|
||||
versionIndex: currentIndex,
|
||||
delta: metadata.delta,
|
||||
umuIdOverride: metadata.umuId,
|
||||
platform: platform,
|
||||
await prisma.gameVersion.create({
|
||||
data: {
|
||||
gameId: gameId,
|
||||
versionName: versionName,
|
||||
dropletManifest: manifest,
|
||||
versionIndex: currentIndex,
|
||||
delta: metadata.delta,
|
||||
umuIdOverride: metadata.umuId,
|
||||
platform: platform,
|
||||
|
||||
onlySetup: true,
|
||||
setupCommand: metadata.setup,
|
||||
setupArgs: metadata.setupArgs.split(" "),
|
||||
},
|
||||
});
|
||||
} else {
|
||||
await prisma.gameVersion.create({
|
||||
data: {
|
||||
gameId: gameId,
|
||||
versionName: versionName,
|
||||
dropletManifest: manifest,
|
||||
versionIndex: currentIndex,
|
||||
delta: metadata.delta,
|
||||
umuIdOverride: metadata.umuId,
|
||||
platform: platform,
|
||||
|
||||
onlySetup: false,
|
||||
setupCommand: metadata.setup,
|
||||
setupArgs: metadata.setupArgs.split(" "),
|
||||
launchCommand: metadata.launch,
|
||||
launchArgs: metadata.launchArgs.split(" "),
|
||||
},
|
||||
});
|
||||
}
|
||||
hidden: metadata.hide,
|
||||
onlySetup: metadata.onlySetup,
|
||||
setupCommand: metadata.setup,
|
||||
setupArgs: metadata.setupArgs.split(" "),
|
||||
launchCommand: metadata.launch,
|
||||
launchArgs: metadata.launchArgs.split(" "),
|
||||
},
|
||||
});
|
||||
|
||||
logger.info("Successfully created version!");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user