feat: version hiding

This commit is contained in:
DecDuck
2025-08-19 16:37:29 +10:00
parent 6d89b7e510
commit e63f701148
8 changed files with 78 additions and 69 deletions

View File

@ -308,8 +308,10 @@
"umuLauncherId": "UMU Launcher ID",
"umuOverride": "Override UMU Launcher Game ID",
"umuOverrideDesc": "By default, Drop uses a non-ID when launching with UMU Launcher. In order to get the right patches for some games, you may have to manually set this field.",
"updateMode": "Update mode",
"updateMode": "Update/delta mode",
"updateModeDesc": "When enabled, these files will be installed on top of (overwriting) the previous version's. If multiple \"update modes\" are chained together, they are applied in order.",
"hide": "Hide version",
"hideDesc": "Hide version so clients cannot install it. Useful if you are using delta versions to save space, but don't want to allow users to install partial games.",
"version": "Select version to import"
},
"withoutMetadata": "Import without metadata"

View File

@ -398,6 +398,36 @@
/>
</Switch>
</SwitchGroup>
<!-- setup mode -->
<SwitchGroup as="div" class="flex items-center justify-between">
<span class="flex flex-grow flex-col">
<SwitchLabel
as="span"
class="text-sm font-medium leading-6 text-zinc-100"
passive
>{{ $t("library.admin.import.version.hide") }}</SwitchLabel
>
<SwitchDescription as="span" class="text-sm text-zinc-400">{{
$t("library.admin.import.version.hideDesc")
}}</SwitchDescription>
</span>
<Switch
v-model="versionSettings.hide"
:class="[
versionSettings.hide ? 'bg-blue-600' : 'bg-zinc-800',
'relative inline-flex h-6 w-11 flex-shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out focus:outline-none focus:ring-2 focus:ring-blue-600 focus:ring-offset-2',
]"
>
<span
aria-hidden="true"
:class="[
versionSettings.hide ? 'translate-x-5' : 'translate-x-0',
'pointer-events-none inline-block h-5 w-5 transform rounded-full bg-white shadow ring-0 transition duration-200 ease-in-out',
]"
/>
</Switch>
</SwitchGroup>
<Disclosure v-slot="{ open }" as="div" class="py-2">
<dt>
<DisclosureButton
@ -548,6 +578,7 @@ import {
import { XCircleIcon } from "@heroicons/vue/16/solid";
import { CheckIcon, ChevronUpDownIcon } from "@heroicons/vue/20/solid";
import { ChevronDownIcon, ChevronUpIcon } from "@heroicons/vue/24/solid";
import type { ImportVersion } from "~/server/api/v1/admin/import/version/index.post";
definePageMeta({
layout: "admin",
@ -561,18 +592,7 @@ const versions = await $dropFetch(
`/api/v1/admin/import/version?id=${encodeURIComponent(gameId)}`,
);
const currentlySelectedVersion = ref(-1);
const versionSettings = ref<{
platform: PlatformClient | undefined;
onlySetup: boolean;
launch: string;
launchArgs: string;
setup: string;
setupArgs: string;
delta: boolean;
umuId: string;
}>({
const versionSettings = ref<Partial<typeof ImportVersion.infer>>({
platform: undefined,
launch: "",
launchArgs: "",
@ -581,6 +601,7 @@ const versionSettings = ref<{
delta: false,
onlySetup: false,
umuId: "",
hide: false,
});
const versionGuesses =

View File

@ -0,0 +1,8 @@
-- DropIndex
DROP INDEX "GameTag_name_idx";
-- AlterTable
ALTER TABLE "GameVersion" ADD COLUMN "hidden" BOOLEAN NOT NULL DEFAULT false;
-- CreateIndex
CREATE INDEX "GameTag_name_idx" ON "GameTag" USING GIST ("name" gist_trgm_ops(siglen=32));

View File

@ -56,12 +56,11 @@ model GameTag {
id String @id @default(uuid())
name String @unique
games Game[]
games Game[]
@@index([name(ops: raw("gist_trgm_ops(siglen=32)"))], type: Gist)
}
model GameRating {
id String @id @default(uuid())
@ -95,6 +94,7 @@ model GameVersion {
setupCommand String @default("") // Command to setup game (dependencies and such)
setupArgs String[]
onlySetup Boolean @default(false)
hidden Boolean @default(false)
umuIdOverride String?

View File

@ -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,

View File

@ -17,6 +17,7 @@ export default defineClientEventHandler(async (h3) => {
gameId: id,
versionName: version,
},
hidden: false,
},
});

View File

@ -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

View File

@ -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!");