Game specialisation & delta versions (#323)

* feat: game specialisation, auto-guess extensions

* fix: enforce specialisation specific schema at API level

* fix: lint

* feat: partial work on depot endpoints

* feat: bump torrential

* feat: dummy version creation for depot uploads

* fix: lint

* fix: types

* fix: lint

* feat: depot version import

* fix: lint

* fix: remove any type

* fix: lint

* fix: push update interval

* fix: cpu usage calculation

* feat: delta version support

* feat: style tweaks for selectlaunch.vue

* fix: lint
This commit is contained in:
DecDuck
2026-01-23 05:04:38 +00:00
committed by GitHub
parent d8db5b5b85
commit 00adab21c2
46 changed files with 1164 additions and 347 deletions

View File

@@ -33,7 +33,7 @@
"username": "drop" "username": "drop"
} }
], ],
"typescript.experimental.useTsgo": false, "typescript.experimental.useTsgo": true,
// prioritize ArkType's "type" for autoimports // prioritize ArkType's "type" for autoimports
"typescript.preferences.autoImportSpecifierExcludeRegexes": ["^(node:)?os$"] "typescript.preferences.autoImportSpecifierExcludeRegexes": ["^(node:)?os$"]
} }

View File

@@ -4,7 +4,7 @@
class="flex space-x-4 rounded-md bg-zinc-900/50 px-6 outline -outline-offset-1 outline-white/10 w-fit text-xs font-bold text-zinc-100" class="flex space-x-4 rounded-md bg-zinc-900/50 px-6 outline -outline-offset-1 outline-white/10 w-fit text-xs font-bold text-zinc-100"
> >
<div class="inline-flex gap-x-2 items-center"> <div class="inline-flex gap-x-2 items-center">
<img :src="executor.gameIcon" class="size-6" /> <img :src="useObject(executor.gameIcon)" class="size-6" />
<span>{{ executor.gameName }}</span> <span>{{ executor.gameName }}</span>
</div> </div>
<div class="flex items-center"> <div class="flex items-center">

View File

@@ -28,12 +28,9 @@
:executor="{ :executor="{
launchId: props.config.launchId, launchId: props.config.launchId,
gameName: props.config.executor.gameVersion.game.mName, gameName: props.config.executor.gameVersion.game.mName,
gameIcon: useObject( gameIcon: props.config.executor.gameVersion.game.mIconObjectId,
props.config.executor.gameVersion.game.mIconObjectId, versionName: (props.config.executor.gameVersion.displayName ??
), props.config.executor.gameVersion.versionPath)!,
versionName:
props.config.executor.gameVersion.displayName ??
props.config.executor.gameVersion.versionPath,
launchName: props.config.executor.name, launchName: props.config.executor.name,
platform: props.config.executor.platform, platform: props.config.executor.platform,
}" }"

View File

@@ -1,6 +1,9 @@
<template> <template>
<div class="flex flex-row items-center gap-x-2"> <div class="flex flex-row items-center gap-x-2">
<img :src="game.icon" class="w-12 h-12 rounded-sm object-cover" /> <img
:src="rawIcon ? game.icon : useObject(game.icon)"
class="w-12 h-12 rounded-sm object-cover"
/>
<div class="flex flex-col items-left"> <div class="flex flex-col items-left">
<h1 class="font-semibold font-display text-lg text-zinc-100"> <h1 class="font-semibold font-display text-lg text-zinc-100">
{{ game.name }} {{ game.name }}
@@ -18,7 +21,8 @@
<script setup lang="ts"> <script setup lang="ts">
import type { GameMetadataSearchResult } from "~/server/internal/metadata/types"; import type { GameMetadataSearchResult } from "~/server/internal/metadata/types";
const { game } = defineProps<{ const { game, rawIcon = true } = defineProps<{
game: Omit<GameMetadataSearchResult, "year"> & { sourceName?: string }; game: Omit<GameMetadataSearchResult, "year"> & { sourceName?: string };
rawIcon?: boolean;
}>(); }>();
</script> </script>

View File

@@ -87,6 +87,11 @@
:is="PLATFORM_ICONS[guess.platform]" :is="PLATFORM_ICONS[guess.platform]"
class="size-5" class="size-5"
/> />
<img
v-if="guess.type === 'executor'"
:src="useObject(guess.icon)"
class="size-5"
/>
</span> </span>
<span <span
@@ -119,7 +124,7 @@
<span <span
:class="['block truncate', selected && 'font-semibold']" :class="['block truncate', selected && 'font-semibold']"
> >
{{ launchProcessQuery }} '{{ launchProcessQuery }}'
</span> </span>
<span <span
@@ -137,6 +142,28 @@
</div> </div>
</Combobox> </Combobox>
</div> </div>
<div
v-if="props.type && props.type === 'Executor'"
class="ml-1 mt-2 rounded-lg bg-blue-900/10 p-1 outline outline-blue-900"
>
<div class="flex items-center">
<div class="shrink-0">
<InformationCircleIcon
class="size-5 text-blue-500"
aria-hidden="true"
/>
</div>
<div class="ml-2 inline-flex items-center">
<p class="text-sm text-blue-200">
<span
class="font-mono bg-zinc-950 text-zinc-100 py-1 px-0.5 rounded-xl"
>{executor}</span
>
is replaced with the game's launch command for executors.
</p>
</div>
</div>
</div>
</div> </div>
<SelectorPlatform <SelectorPlatform
:model-value="launchConfiguration.platform" :model-value="launchConfiguration.platform"
@@ -145,7 +172,7 @@
> >
{{ $t("library.admin.import.version.platform") }} {{ $t("library.admin.import.version.platform") }}
</SelectorPlatform> </SelectorPlatform>
<div> <div v-if="props.type && props.type === 'Game' && props.allowExecutor">
<h1 class="block text-sm font-medium leading-6 text-zinc-100"> <h1 class="block text-sm font-medium leading-6 text-zinc-100">
Executor Executor
</h1> </h1>
@@ -170,6 +197,15 @@
</button> </button>
</div> </div>
</div> </div>
<div v-if="props.type && props.type === 'Executor'">
<p class="block text-sm font-medium leading-6 text-zinc-100">
Auto-suggest extensions
</p>
<SelectorFileExtension
v-model="launchConfiguration.suggestions!"
class="mt-2"
/>
</div>
<ModalSelectLaunch <ModalSelectLaunch
v-model="selectLaunchOpen" v-model="selectLaunchOpen"
class="-mt-2" class="-mt-2"
@@ -190,9 +226,10 @@ import {
import { CheckIcon, ChevronUpDownIcon } from "@heroicons/vue/20/solid"; import { CheckIcon, ChevronUpDownIcon } from "@heroicons/vue/20/solid";
import { InformationCircleIcon, TrashIcon } from "@heroicons/vue/24/outline"; import { InformationCircleIcon, TrashIcon } from "@heroicons/vue/24/outline";
import type { ExecutorLaunchObject } from "~/composables/frontend"; import type { ExecutorLaunchObject } from "~/composables/frontend";
import type { Platform } from "~/prisma/client/enums"; import type { GameType, Platform } from "~/prisma/client/enums";
import type { ImportVersion } from "~/server/api/v1/admin/import/version/index.post"; import type { ImportVersion } from "~/server/api/v1/admin/import/version/index.post";
import type { VersionGuess } from "~/server/internal/library";
const launchProcessQuery = ref(""); const launchProcessQuery = ref("");
@@ -227,10 +264,15 @@ function updatePlatform(v: Platform | undefined) {
} }
const props = defineProps<{ const props = defineProps<{
versionGuesses: Array<{ platform: Platform; filename: string }> | undefined; versionGuesses: Array<VersionGuess> | undefined;
needsName: boolean; needsName: boolean;
allowExecutor?: boolean;
type?: GameType;
}>(); }>();
if (props.type && props.type === "Executor")
launchConfiguration.value.suggestions ??= [];
const selectLaunchOpen = ref(false); const selectLaunchOpen = ref(false);
const launchFilteredVersionGuesses = computed(() => const launchFilteredVersionGuesses = computed(() =>
@@ -246,7 +288,20 @@ function updateLaunchCommand(command: string) {
(v) => v.filename == command, (v) => v.filename == command,
); );
if (autosetGuess) { if (autosetGuess) {
launchConfiguration.value.platform = autosetGuess.platform; if (autosetGuess.type === "platform") {
launchConfiguration.value.platform = autosetGuess.platform;
} else if (autosetGuess.type === "executor") {
console.log(autosetGuess.executorId);
executor.value = {
launchId: autosetGuess.executorId,
gameName: autosetGuess.gameName,
gameIcon: autosetGuess.icon,
versionName: autosetGuess.launchName,
launchName: autosetGuess.launchName,
platform: autosetGuess.platform,
} satisfies ExecutorLaunchObject;
launchConfiguration.value.platform = autosetGuess.platform;
}
} }
} }
} }

View File

@@ -164,6 +164,8 @@ async function addGame() {
} }
async function search(query: string) { async function search(query: string) {
return await $dropFetch("/api/v1/admin/search/game", { query: { q: query } }); return await $dropFetch("/api/v1/admin/search/game?type=Game", {
query: { q: query },
});
} }
</script> </script>

View File

@@ -3,7 +3,7 @@
<template #default> <template #default>
<div> <div>
<h1 as="h3" class="text-lg font-medium leading-6 text-white"> <h1 as="h3" class="text-lg font-medium leading-6 text-white">
Pick a launch option Select a launch option
</h1> </h1>
<p class="mt-1 text-zinc-400 text-sm"> <p class="mt-1 text-zinc-400 text-sm">
Select a launch option as an executor for your new launch option. Select a launch option as an executor for your new launch option.
@@ -28,14 +28,14 @@
</div> </div>
</div> </div>
<div class="mt-2 space-y-4"> <div class="mt-2 space-y-4">
<div <div>
class="inline-flex items-center w-full gap-x-2 text-zinc-100 font-bold" <h1 class="block text-sm font-medium leading-6 text-zinc-100">
> Search for an executor
Game: </h1>
<SelectorGame <SelectorGame
:search="search" :search="search"
:model-value="game" :model-value="game"
class="w-full" class="w-full mt-2"
@update:model-value="(value) => updateGame(value)" @update:model-value="(value) => updateGame(value)"
/> />
</div> </div>
@@ -45,28 +45,27 @@
> >
No versions imported. No versions imported.
</div> </div>
<div <div v-else-if="versions !== undefined">
v-else-if="versions !== undefined" <h1 class="block text-sm font-medium leading-6 text-zinc-100">
class="inline-flex items-center w-full gap-x-2 text-zinc-100 font-bold" Select a version
> </h1>
Version:
<SelectorCombox <SelectorCombox
:search=" :search="
(v) => (v) =>
Object.values(versions!) Object.values(versions!)
.filter((k) => .filter((k) =>
(k.displayName || k.versionPath) (k.displayName || k.versionPath)!
.toLowerCase() .toLowerCase()
.includes(v.toLowerCase()), .includes(v.toLowerCase()),
) )
.map((v) => ({ .map((v) => ({
id: v.versionId, id: v.versionId,
name: v.displayName ?? v.versionPath, name: (v.displayName ?? v.versionPath)!,
})) }))
" "
:display="(v) => v.name" :display="(v) => v.name"
:model-value="version" :model-value="version"
class="w-full" class="w-full mt-2"
@update:model-value="updateVersion" @update:model-value="updateVersion"
> >
<template #default="{ value }"> <template #default="{ value }">
@@ -74,11 +73,10 @@
</template> </template>
</SelectorCombox> </SelectorCombox>
</div> </div>
<div <div v-if="versions && version">
v-if="versions && version" <h1 class="block text-sm font-medium leading-6 text-zinc-100">
class="inline-flex items-center w-full gap-x-2 text-zinc-100 font-bold" Select a launch command
> </h1>
Launch:
<SelectorCombox <SelectorCombox
:search=" :search="
(v) => (v) =>
@@ -99,7 +97,7 @@
" "
:display="(v) => v.name" :display="(v) => v.name"
:model-value="launchId" :model-value="launchId"
class="w-full" class="w-full mt-2"
@update:model-value="(v) => (launchId = v)" @update:model-value="(v) => (launchId = v)"
> >
<template #default="{ value }"> <template #default="{ value }">
@@ -169,7 +167,7 @@ const versions = ref<
platform: Platform; platform: Platform;
}[]; }[];
versionId: string; versionId: string;
versionPath: string; versionPath: string | null;
}; };
} }
| undefined | undefined
@@ -180,7 +178,9 @@ const emit = defineEmits<{
}>(); }>();
async function search(query: string) { async function search(query: string) {
return await $dropFetch("/api/v1/admin/search/game", { query: { q: query } }); return await $dropFetch("/api/v1/admin/search/game", {
query: { q: query, type: "Executor" },
});
} }
function updateGame(value: GameMetadataSearchResult | undefined) { function updateGame(value: GameMetadataSearchResult | undefined) {

View File

@@ -0,0 +1,118 @@
<template>
<div>
<div class="flex gap-1 flex-wrap">
<span
v-for="extension in model"
:key="extension"
class="inline-flex items-center gap-x-0.5 rounded-md bg-blue-400/10 px-2 py-1 text-xs font-medium text-blue-400 inset-ring inset-ring-blue-400/30"
>
{{ extension }}
<button
type="button"
class="group relative -mr-1 size-3.5 rounded-xs hover:bg-blue-500/30"
@click="() => removeFileExtension(extension)"
>
<span class="sr-only">Remove</span>
<svg
viewBox="0 0 14 14"
class="size-3.5 stroke-blue-400 group-hover:stroke-blue-300"
>
<path d="M4 4l6 6m0-6l-6 6" />
</svg>
<span class="absolute -inset-1"></span>
</button>
</span>
<span v-if="model.length == 0" class="text-zinc-500 text-xs"
>No extensions selected.</span
>
</div>
<Combobox
as="div"
nullable
:immediate="true"
:model-value="model"
class="mt-2 bg-zinc-800 rounded"
@update:model-value="addFileExtension"
>
<div class="relative">
<ComboboxInput
class="block flex-1 border-0 py-1.5 pl-2 bg-transparent text-zinc-100 placeholder:text-zinc-400 focus:ring-0 sm:text-sm sm:leading-6 w-full"
placeholder="Start typing..."
:display-value="(_) => ''"
@change="query = $event.target.value"
@blur="query = ''"
/>
<ComboboxButton
class="absolute inset-0 right-0 flex items-center justify-end rounded-r-md px-2 focus:outline-none"
>
<ChevronUpDownIcon class="size-5 text-gray-400" aria-hidden="true" />
</ComboboxButton>
<ComboboxOptions
class="absolute z-10 mt-1 max-h-60 w-full overflow-auto rounded-md bg-zinc-900 py-1 text-base shadow-lg ring-1 ring-white/5 focus:outline-none sm:text-sm"
>
<ComboboxOption
v-if="query"
v-slot="{ active, selected }"
:value="query"
as="template"
>
<li
:class="[
'relative cursor-default select-none py-2 pl-3 pr-9',
active
? 'bg-blue-600 text-white outline-none'
: 'text-zinc-100',
]"
>
<span> Add "{{ normalize(query) }}" </span>
<span
v-if="selected"
:class="[
'absolute inset-y-0 right-0 flex items-center pr-4',
active ? 'text-white' : 'text-blue-600',
]"
>
<CheckIcon class="size-5" aria-hidden="true" />
</span>
</li>
</ComboboxOption>
</ComboboxOptions>
</div>
</Combobox>
</div>
</template>
<script setup lang="ts">
import {
Combobox,
ComboboxButton,
ComboboxInput,
ComboboxOption,
ComboboxOptions,
} from "@headlessui/vue";
import { CheckIcon, ChevronUpDownIcon } from "@heroicons/vue/24/outline";
const model = defineModel<string[]>({ required: true });
const query = ref("");
function normalize(v: string) {
const k = v.toLowerCase().replaceAll(/[^a-zA-Z0-9]*/g, "");
if (k.startsWith(".")) return k;
return `.${k}`;
}
function addFileExtension(raw: string) {
const value = normalize(raw);
if (model.value.includes(value)) return;
model.value.push(value);
}
function removeFileExtension(extension: string) {
const index = model.value.findIndex((v) => v === extension);
if (index == -1) return;
model.value.splice(index, 1);
}
</script>

View File

@@ -51,9 +51,9 @@
</div> </div>
<div <div
v-else-if="results.length == 0" v-else-if="results.length == 0"
class="text-zinc-300 uppercase font-display font-bold text-center p-4" class="text-zinc-500 uppercase font-display font-bold text-center p-4"
> >
No results. No results
</div> </div>
<ComboboxOption <ComboboxOption
v-for="result in results" v-for="result in results"
@@ -70,7 +70,7 @@
]" ]"
> >
<span> <span>
<GameSearchResultWidget :game="result" /> <GameSearchResultWidget :game="result" :raw-icon="false" />
</span> </span>
<span <span
@@ -123,8 +123,7 @@ watch(gameSearchQuery, async (v) => {
if (timeout) clearTimeout(timeout); if (timeout) clearTimeout(timeout);
resultsLoading.value = true; resultsLoading.value = true;
timeout = setTimeout(async () => { timeout = setTimeout(async () => {
const newResults = await props.search(v); results.value = await props.search(v);
results.value = newResults.map((v) => ({ ...v, icon: useObject(v.icon) }));
resultsLoading.value = false; resultsLoading.value = false;
timeout = undefined; timeout = undefined;
}, 600); }, 600);

View File

@@ -21,11 +21,6 @@ async function signIn() {
redirect: `/auth/signin?redirect=${encodeURIComponent(route.fullPath)}`, redirect: `/auth/signin?redirect=${encodeURIComponent(route.fullPath)}`,
}); });
} }
switch (statusCode) {
case 401:
case 403:
await signIn();
}
useHead({ useHead({
title: t("errors.pageTitle", [statusCode ?? message]), title: t("errors.pageTitle", [statusCode ?? message]),

View File

@@ -65,6 +65,7 @@ export default defineNuxtConfig({
experimental: { experimental: {
buildCache: true, buildCache: true,
viewTransition: false, viewTransition: false,
appManifest: false,
componentIslands: true, componentIslands: true,
}, },

View File

@@ -27,6 +27,7 @@
"@lobomfz/prismark": "0.0.3", "@lobomfz/prismark": "0.0.3",
"@nuxt/fonts": "^0.11.0", "@nuxt/fonts": "^0.11.0",
"@nuxt/image": "^1.10.0", "@nuxt/image": "^1.10.0",
"@nuxt/kit": "3.20.1",
"@nuxtjs/i18n": "^9.5.5", "@nuxtjs/i18n": "^9.5.5",
"@prisma/client": "^6.11.1", "@prisma/client": "^6.11.1",
"@simplewebauthn/browser": "^13.2.2", "@simplewebauthn/browser": "^13.2.2",

View File

@@ -1,5 +1,5 @@
<template> <template>
<div class="flex flex-col gap-y-4 max-w-[35vw]"> <div class="flex flex-col gap-y-4 sm:max-w-[40rem]">
<Listbox <Listbox
as="div" as="div"
:model-value="currentlySelectedVersion" :model-value="currentlySelectedVersion"
@@ -13,7 +13,7 @@
class="relative w-full cursor-default rounded-md bg-zinc-950 py-1.5 pl-3 pr-10 text-left text-zinc-100 shadow-sm ring-1 ring-inset ring-zinc-800 focus:outline-none focus:ring-2 focus:ring-blue-600 sm:text-sm sm:leading-6" class="relative w-full cursor-default rounded-md bg-zinc-950 py-1.5 pl-3 pr-10 text-left text-zinc-100 shadow-sm ring-1 ring-inset ring-zinc-800 focus:outline-none focus:ring-2 focus:ring-blue-600 sm:text-sm sm:leading-6"
> >
<span v-if="currentlySelectedVersion != -1" class="block truncate">{{ <span v-if="currentlySelectedVersion != -1" class="block truncate">{{
versions[currentlySelectedVersion] versions[currentlySelectedVersion].name
}}</span> }}</span>
<span v-else class="block truncate text-zinc-600">{{ <span v-else class="block truncate text-zinc-600">{{
$t("library.admin.import.selectDir") $t("library.admin.import.selectDir")
@@ -38,7 +38,7 @@
> >
<ListboxOption <ListboxOption
v-for="(version, versionIdx) in versions" v-for="(version, versionIdx) in versions"
:key="version" :key="version.identifier"
v-slot="{ active, selected }" v-slot="{ active, selected }"
as="template" as="template"
:value="versionIdx" :value="versionIdx"
@@ -54,7 +54,7 @@
selected ? 'font-semibold' : 'font-normal', selected ? 'font-semibold' : 'font-normal',
'block truncate', 'block truncate',
]" ]"
>{{ version }}</span >{{ version.name }}</span
> >
<span <span
@@ -92,7 +92,7 @@
<li <li
v-for="(launch, launchIdx) in versionSettings.setups" v-for="(launch, launchIdx) in versionSettings.setups"
:key="launchIdx" :key="launchIdx"
class="py-2 inline-flex items-start gap-x-1" class="py-2 inline-flex items-start gap-x-1 w-full"
> >
<ImportVersionLaunchRow <ImportVersionLaunchRow
v-model="versionSettings.setups[launchIdx]" v-model="versionSettings.setups[launchIdx]"
@@ -122,37 +122,43 @@
> >
</div> </div>
<!-- setup mode --> <!-- setup mode -->
<SwitchGroup <div class="relative">
as="div" <SwitchGroup
class="bg-zinc-800 p-4 rounded-xl flex items-center justify-between gap-4" as="div"
> class="bg-zinc-800 p-4 rounded-xl flex items-center justify-between gap-4"
<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.setupMode") }}</SwitchLabel
>
<SwitchDescription as="span" class="text-sm text-zinc-400">{{
$t("library.admin.import.version.setupModeDesc")
}}</SwitchDescription>
</span>
<Switch
v-model="versionSettings.onlySetup"
:class="[
versionSettings.onlySetup ? 'bg-blue-600' : 'bg-zinc-900',
'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 <span class="flex flex-grow flex-col">
aria-hidden="true" <SwitchLabel
as="span"
class="text-sm font-medium leading-6 text-zinc-100"
passive
>{{ $t("library.admin.import.version.setupMode") }}</SwitchLabel
>
<SwitchDescription as="span" class="text-sm text-zinc-400">{{
$t("library.admin.import.version.setupModeDesc")
}}</SwitchDescription>
</span>
<Switch
v-model="versionSettings.onlySetup"
:class="[ :class="[
versionSettings.onlySetup ? 'translate-x-5' : 'translate-x-0', versionSettings.onlySetup ? 'bg-blue-600' : 'bg-zinc-900',
'pointer-events-none inline-block h-5 w-5 transform rounded-full bg-white shadow ring-0 transition duration-200 ease-in-out', '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',
]" ]"
/> >
</Switch> <span
</SwitchGroup> aria-hidden="true"
:class="[
versionSettings.onlySetup ? '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>
<div
v-if="type === GameType.Redist"
class="absolute inset-0 bg-zinc-900/50"
/>
</div>
<!-- launch executables --> <!-- launch executables -->
<div class="relative flex flex-col gap-y-2 bg-zinc-800 p-4 rounded-xl"> <div class="relative flex flex-col gap-y-2 bg-zinc-800 p-4 rounded-xl">
<div> <div>
@@ -172,19 +178,48 @@
:key="launchIdx" :key="launchIdx"
class="py-2 inline-flex items-start gap-x-1 w-full" class="py-2 inline-flex items-start gap-x-1 w-full"
> >
<ImportVersionLaunchRow <Disclosure
v-model="versionSettings.launches[launchIdx]" v-slot="{ open }"
:version-guesses="versionGuesses" :default-open="true"
:needs-name="true" as="div"
/> class="py-2 px-3 w-full bg-zinc-900 rounded-lg"
<button
class="transition rounded p-1 bg-zinc-900/30 group hover:bg-red-600/30"
@click="() => versionSettings.launches.splice(launchIdx, 1)"
> >
<TrashIcon <dt>
class="transition size-5 text-zinc-700 group-hover:text-red-700" <DisclosureButton
/> class="flex w-full items-center text-left text-white"
</button> >
<span v-if="launch.name" class="text-sm font-semibold">{{
launch.name
}}</span>
<span v-else class="text-sm text-zinc-500 italic"
>No name provided.</span
>
<span class="ml-auto flex h-7 items-center">
<PlusIcon v-if="!open" class="size-6" aria-hidden="true" />
<MinusIcon v-else class="size-6" aria-hidden="true" />
</span>
<button
class="ml-1 transition rounded p-1 bg-zinc-900/30 group hover:bg-red-600/30"
@click.prevent="
() => versionSettings.launches.splice(launchIdx, 1)
"
>
<TrashIcon
class="transition size-5 text-zinc-700 group-hover:text-red-700"
/>
</button>
</DisclosureButton>
</dt>
<DisclosurePanel as="dd" class="mt-2">
<ImportVersionLaunchRow
v-model="versionSettings.launches[launchIdx]"
:version-guesses="versionGuesses"
:needs-name="true"
:allow-executor="true"
:type="type"
/>
</DisclosurePanel>
</Disclosure>
</li> </li>
</ol> </ol>
<span <span
@@ -295,15 +330,21 @@ import {
SwitchDescription, SwitchDescription,
SwitchGroup, SwitchGroup,
SwitchLabel, SwitchLabel,
Disclosure,
DisclosureButton,
DisclosurePanel,
} from "@headlessui/vue"; } from "@headlessui/vue";
import { XCircleIcon } from "@heroicons/vue/16/solid"; import { XCircleIcon } from "@heroicons/vue/16/solid";
import { import {
CheckIcon, CheckIcon,
ChevronUpDownIcon, ChevronUpDownIcon,
TrashIcon, TrashIcon,
MinusIcon,
PlusIcon,
} from "@heroicons/vue/20/solid"; } from "@heroicons/vue/20/solid";
import type { Platform } from "~/prisma/client/enums"; import { GameType } from "~/prisma/client/enums";
import type { ImportVersion } from "~/server/api/v1/admin/import/version/index.post"; import type { ImportVersion } from "~/server/api/v1/admin/import/version/index.post";
import type { VersionGuess } from "~/server/internal/library";
definePageMeta({ definePageMeta({
layout: "admin", layout: "admin",
@@ -313,20 +354,21 @@ const router = useRouter();
const { t } = useI18n(); const { t } = useI18n();
const route = useRoute(); const route = useRoute();
const gameId = route.params.id.toString(); const gameId = route.params.id.toString();
const versions = await $dropFetch( const { versions, type } = await $dropFetch(
`/api/v1/admin/import/version?id=${encodeURIComponent(gameId)}`, `/api/v1/admin/import/version?id=${encodeURIComponent(gameId)}`,
); );
const currentlySelectedVersion = ref(-1); const currentlySelectedVersion = ref(-1);
const versionSettings = ref<typeof ImportVersion.infer>({ const versionSettings = ref<Omit<typeof ImportVersion.infer, "version" | "id">>(
id: gameId, {
version: "", delta: false,
delta: false, onlySetup: type === GameType.Redist,
onlySetup: false, launches: [],
launches: [], setups: [],
setups: [], requiredContent: [],
}); },
);
const versionGuesses = ref<Array<{ platform: Platform; filename: string }>>(); const versionGuesses = ref<Array<VersionGuess>>();
const importLoading = ref(false); const importLoading = ref(false);
const importError = ref<string | undefined>(); const importError = ref<string | undefined>();
@@ -336,14 +378,14 @@ async function updateCurrentlySelectedVersion(value: number) {
currentlySelectedVersion.value = value; currentlySelectedVersion.value = value;
const version = versions[currentlySelectedVersion.value]; const version = versions[currentlySelectedVersion.value];
try { try {
const results = await $dropFetch( const results = await $dropFetch(`/api/v1/admin/import/version/preload`, {
`/api/v1/admin/import/version/preload?id=${encodeURIComponent( failTitle: "Failed to fetch version information",
gameId, query: {
)}&version=${encodeURIComponent(version)}`, id: gameId,
{ type: version.type,
failTitle: "Failed to fetch version information", version: version.identifier,
}, },
); });
versionGuesses.value = results as typeof versionGuesses.value; versionGuesses.value = results as typeof versionGuesses.value;
} catch { } catch {
currentlySelectedVersion.value = -1; currentlySelectedVersion.value = -1;

View File

@@ -1,5 +1,5 @@
<template> <template>
<div class="flex flex-col gap-y-6 w-full max-w-md"> <div class="flex flex-col gap-y-6 w-full max-w-lg">
<Listbox <Listbox
as="div" as="div"
:model="currentlySelectedGame" :model="currentlySelectedGame"
@@ -114,6 +114,40 @@
</div> </div>
<div v-if="currentlySelectedGame !== -1" class="flex flex-col gap-y-4"> <div v-if="currentlySelectedGame !== -1" class="flex flex-col gap-y-4">
<fieldset>
<legend class="text-sm/6 font-semibold text-white">Import as</legend>
<div class="mt-6 grid grid-cols-1 gap-y-6 sm:grid-cols-3 sm:gap-x-4">
<label
v-for="[type, meta] in Object.entries(importModes)"
:key="type"
:aria-label="meta.title"
:aria-description="`Import as ${meta.title}`"
class="cursor-pointer group relative flex rounded-lg border border-white/10 bg-gray-800/50 p-4 has-checked:bg-blue-500/10 has-checked:outline-2 has-checked:-outline-offset-2 has-checked:outline-blue-500 has-focus-visible:outline-3 has-focus-visible:-outline-offset-1 has-disabled:bg-gray-800 has-disabled:opacity-25"
>
<input
v-model="importMode"
type="radio"
name="mailing-list"
:value="type"
:checked="importMode === type"
class="absolute inset-0 opacity-0 focus:outline-none"
/>
<div class="flex flex-col grow">
<span class="block text-sm font-medium text-white">{{
meta.title
}}</span>
<span class="mt-1 block text-xs text-gray-400">{{
meta.description
}}</span>
</div>
<CheckCircleIcon
class="invisible size-5 text-blue-500 group-has-checked:visible"
aria-hidden="true"
/>
</label>
</div>
</fieldset>
<!-- without metadata option --> <!-- without metadata option -->
<div> <div>
<LoadingButton <LoadingButton
@@ -309,6 +343,7 @@ import {
import { XCircleIcon } from "@heroicons/vue/16/solid"; import { XCircleIcon } from "@heroicons/vue/16/solid";
import { CheckIcon, ChevronUpDownIcon } from "@heroicons/vue/20/solid"; import { CheckIcon, ChevronUpDownIcon } from "@heroicons/vue/20/solid";
import { MagnifyingGlassIcon } from "@heroicons/vue/24/outline"; import { MagnifyingGlassIcon } from "@heroicons/vue/24/outline";
import type { GameType } from "~/prisma/client/enums";
import type { GameMetadataSearchResult } from "~/server/internal/metadata/types"; import type { GameMetadataSearchResult } from "~/server/internal/metadata/types";
definePageMeta({ definePageMeta({
@@ -326,6 +361,25 @@ const gameSearchTerm = ref("");
const gameSearchLoading = ref(false); const gameSearchLoading = ref(false);
const bulkImportMode = ref(false); const bulkImportMode = ref(false);
const importModes: {
[key in GameType]: { title: string; description: string };
} = {
Game: {
title: "Game",
description: "Games are shown in store, and are discoverable.",
},
Executor: {
title: "Executor",
description:
"Executors are used to launch games. Mainly emulators or wrappers.",
},
Redist: {
title: "Redistributable",
description:
"Additional content that must be downloaded and installed before running the game.",
},
};
async function updateSelectedGame(value: number) { async function updateSelectedGame(value: number) {
if (currentlySelectedGame.value == value) return; if (currentlySelectedGame.value == value) return;
currentlySelectedGame.value = value; currentlySelectedGame.value = value;
@@ -374,6 +428,7 @@ const router = useRouter();
const importLoading = ref(false); const importLoading = ref(false);
const importError = ref<string | undefined>(); const importError = ref<string | undefined>();
const importMode = ref<GameType>("Game");
async function importGame(useMetadata: boolean) { async function importGame(useMetadata: boolean) {
if (!metadataResults.value && useMetadata) return; if (!metadataResults.value && useMetadata) return;
@@ -389,6 +444,7 @@ async function importGame(useMetadata: boolean) {
path: option.game, path: option.game,
library: option.library.id, library: option.library.id,
metadata, metadata,
type: importMode.value,
}, },
}); });

View File

@@ -88,7 +88,7 @@
/> />
<div class="flex flex-col"> <div class="flex flex-col">
<h3 <h3
class="gap-x-2 text-sm inline-flex items-center font-medium text-zinc-100 font-display" class="gap-2 text-sm flex flex-wrap items-center font-medium text-zinc-100 font-display"
> >
{{ game.mName }} {{ game.mName }}
<button <button
@@ -128,6 +128,10 @@
class="inline-flex items-center rounded-full bg-blue-600/10 px-2 py-1 text-xs font-medium text-blue-600 ring-1 ring-inset ring-blue-600/20" class="inline-flex items-center rounded-full bg-blue-600/10 px-2 py-1 text-xs font-medium text-blue-600 ring-1 ring-inset ring-blue-600/20"
>{{ game.library!.name }}</span >{{ game.library!.name }}</span
> >
<span
class="inline-flex items-center rounded-full bg-green-600/10 px-2 py-1 text-xs font-medium text-green-600 ring-1 ring-inset ring-green-600/20"
>{{ game.type }}</span
>
</h3> </h3>
<dl class="mt-1 flex flex-col justify-between"> <dl class="mt-1 flex flex-col justify-between">
<dt class="sr-only">{{ $t("library.admin.shortDesc") }}</dt> <dt class="sr-only">{{ $t("library.admin.shortDesc") }}</dt>

139
pnpm-lock.yaml generated
View File

@@ -29,6 +29,9 @@ importers:
'@nuxt/image': '@nuxt/image':
specifier: ^1.10.0 specifier: ^1.10.0
version: 1.10.0(@netlify/blobs@9.1.2)(db0@0.3.4)(ioredis@5.8.2)(magicast@0.5.1) version: 1.10.0(@netlify/blobs@9.1.2)(db0@0.3.4)(ioredis@5.8.2)(magicast@0.5.1)
'@nuxt/kit':
specifier: 3.20.1
version: 3.20.1(magicast@0.5.1)
'@nuxtjs/i18n': '@nuxtjs/i18n':
specifier: ^9.5.5 specifier: ^9.5.5
version: 9.5.6(@vue/compiler-dom@3.5.27)(eslint@9.31.0(jiti@2.6.1))(magicast@0.5.1)(rollup@4.53.3)(vue@3.5.27(typescript@5.8.3)) version: 9.5.6(@vue/compiler-dom@3.5.27)(eslint@9.31.0(jiti@2.6.1))(magicast@0.5.1)(rollup@4.53.3)(vue@3.5.27(typescript@5.8.3))
@@ -1370,18 +1373,10 @@ packages:
resolution: {integrity: sha512-/B58GeEmme7bkmQUrXzEw8P9sJb9BkMaYZqLDtq8ZdDLEddE3P4nVya8RQPB+p4b7EdqWajpPqdy1A2ZPLev/A==} resolution: {integrity: sha512-/B58GeEmme7bkmQUrXzEw8P9sJb9BkMaYZqLDtq8ZdDLEddE3P4nVya8RQPB+p4b7EdqWajpPqdy1A2ZPLev/A==}
engines: {node: '>=18.20.6'} engines: {node: '>=18.20.6'}
'@nuxt/kit@3.18.0':
resolution: {integrity: sha512-svS1CBEx7gMgEIaNYrQt26J/t5bDSUdIf7GQWr5M6yszOzLw+IVzyfH7TBmuxZEbjovhLaJEG379mgKp82H/lA==}
engines: {node: '>=18.12.0'}
'@nuxt/kit@3.20.1': '@nuxt/kit@3.20.1':
resolution: {integrity: sha512-TIslaylfI5kd3AxX5qts0qyrIQ9Uq3HAA1bgIIJ+c+zpDfK338YS+YrCWxBBzDMECRCbAS58mqAd2MtJfG1ENA==} resolution: {integrity: sha512-TIslaylfI5kd3AxX5qts0qyrIQ9Uq3HAA1bgIIJ+c+zpDfK338YS+YrCWxBBzDMECRCbAS58mqAd2MtJfG1ENA==}
engines: {node: '>=18.12.0'} engines: {node: '>=18.12.0'}
'@nuxt/kit@4.0.2':
resolution: {integrity: sha512-OtLkVYHpfrm1FzGSGxl0H3QXLgO41yxOgni5S6zzLG4gblG71Fy82B2QTdqJLzTLKWObiILKDhrysBtmDkp3LA==}
engines: {node: '>=18.12.0'}
'@nuxt/kit@4.2.1': '@nuxt/kit@4.2.1':
resolution: {integrity: sha512-lLt8KLHyl7IClc3RqRpRikz15eCfTRlAWL9leVzPyg5N87FfKE/7EWgWvpiL/z4Tf3dQCIqQb88TmHE0JTIDvA==} resolution: {integrity: sha512-lLt8KLHyl7IClc3RqRpRikz15eCfTRlAWL9leVzPyg5N87FfKE/7EWgWvpiL/z4Tf3dQCIqQb88TmHE0JTIDvA==}
engines: {node: '>=18.12.0'} engines: {node: '>=18.12.0'}
@@ -7537,10 +7532,10 @@ snapshots:
find-up: 7.0.0 find-up: 7.0.0
get-port-please: 3.2.0 get-port-please: 3.2.0
h3: 1.15.5 h3: 1.15.5
mlly: 1.7.4 mlly: 1.8.0
mrmime: 2.0.1 mrmime: 2.0.1
open: 10.2.0 open: 10.2.0
tinyglobby: 0.2.14 tinyglobby: 0.2.15
ws: 8.18.3 ws: 8.18.3
transitivePeerDependencies: transitivePeerDependencies:
- bufferutil - bufferutil
@@ -7613,7 +7608,7 @@ snapshots:
escodegen: 2.1.0 escodegen: 2.1.0
estree-walker: 2.0.2 estree-walker: 2.0.2
jsonc-eslint-parser: 2.4.0 jsonc-eslint-parser: 2.4.0
mlly: 1.7.4 mlly: 1.8.0
source-map-js: 1.2.1 source-map-js: 1.2.1
yaml-eslint-parser: 1.3.0 yaml-eslint-parser: 1.3.0
optionalDependencies: optionalDependencies:
@@ -7960,7 +7955,7 @@ snapshots:
'@nuxt/devtools-kit@2.6.2(magicast@0.5.1)(vite@7.2.2(@types/node@22.16.5)(jiti@2.6.1)(lightningcss@1.30.1)(sass@1.89.2)(terser@5.43.1)(yaml@2.8.1))': '@nuxt/devtools-kit@2.6.2(magicast@0.5.1)(vite@7.2.2(@types/node@22.16.5)(jiti@2.6.1)(lightningcss@1.30.1)(sass@1.89.2)(terser@5.43.1)(yaml@2.8.1))':
dependencies: dependencies:
'@nuxt/kit': 3.18.0(magicast@0.5.1) '@nuxt/kit': 3.20.1(magicast@0.5.1)
execa: 8.0.1 execa: 8.0.1
vite: 7.2.2(@types/node@22.16.5)(jiti@2.6.1)(lightningcss@1.30.1)(sass@1.89.2)(terser@5.43.1)(yaml@2.8.1) vite: 7.2.2(@types/node@22.16.5)(jiti@2.6.1)(lightningcss@1.30.1)(sass@1.89.2)(terser@5.43.1)(yaml@2.8.1)
transitivePeerDependencies: transitivePeerDependencies:
@@ -8072,7 +8067,7 @@ snapshots:
'@nuxt/devtools-kit': 2.6.2(magicast@0.5.1)(vite@7.2.2(@types/node@22.16.5)(jiti@2.6.1)(lightningcss@1.30.1)(sass@1.89.2)(terser@5.43.1)(yaml@2.8.1)) '@nuxt/devtools-kit': 2.6.2(magicast@0.5.1)(vite@7.2.2(@types/node@22.16.5)(jiti@2.6.1)(lightningcss@1.30.1)(sass@1.89.2)(terser@5.43.1)(yaml@2.8.1))
'@nuxt/eslint-config': 1.7.1(@typescript-eslint/utils@8.50.0(eslint@9.31.0(jiti@2.6.1))(typescript@5.8.3))(@vue/compiler-sfc@3.5.27)(eslint@9.31.0(jiti@2.6.1))(typescript@5.8.3) '@nuxt/eslint-config': 1.7.1(@typescript-eslint/utils@8.50.0(eslint@9.31.0(jiti@2.6.1))(typescript@5.8.3))(@vue/compiler-sfc@3.5.27)(eslint@9.31.0(jiti@2.6.1))(typescript@5.8.3)
'@nuxt/eslint-plugin': 1.7.1(eslint@9.31.0(jiti@2.6.1))(typescript@5.8.3) '@nuxt/eslint-plugin': 1.7.1(eslint@9.31.0(jiti@2.6.1))(typescript@5.8.3)
'@nuxt/kit': 4.0.2(magicast@0.5.1) '@nuxt/kit': 4.2.1(magicast@0.5.1)
chokidar: 4.0.3 chokidar: 4.0.3
eslint: 9.31.0(jiti@2.6.1) eslint: 9.31.0(jiti@2.6.1)
eslint-flat-config-utils: 2.1.1 eslint-flat-config-utils: 2.1.1
@@ -8097,7 +8092,7 @@ snapshots:
'@nuxt/fonts@0.11.4(@netlify/blobs@9.1.2)(db0@0.3.4)(ioredis@5.8.2)(magicast@0.5.1)(vite@7.2.2(@types/node@22.16.5)(jiti@2.6.1)(lightningcss@1.30.1)(sass@1.89.2)(terser@5.43.1)(yaml@2.8.1))': '@nuxt/fonts@0.11.4(@netlify/blobs@9.1.2)(db0@0.3.4)(ioredis@5.8.2)(magicast@0.5.1)(vite@7.2.2(@types/node@22.16.5)(jiti@2.6.1)(lightningcss@1.30.1)(sass@1.89.2)(terser@5.43.1)(yaml@2.8.1))':
dependencies: dependencies:
'@nuxt/devtools-kit': 2.6.2(magicast@0.5.1)(vite@7.2.2(@types/node@22.16.5)(jiti@2.6.1)(lightningcss@1.30.1)(sass@1.89.2)(terser@5.43.1)(yaml@2.8.1)) '@nuxt/devtools-kit': 2.6.2(magicast@0.5.1)(vite@7.2.2(@types/node@22.16.5)(jiti@2.6.1)(lightningcss@1.30.1)(sass@1.89.2)(terser@5.43.1)(yaml@2.8.1))
'@nuxt/kit': 3.18.0(magicast@0.5.1) '@nuxt/kit': 3.20.1(magicast@0.5.1)
consola: 3.4.2 consola: 3.4.2
css-tree: 3.1.0 css-tree: 3.1.0
defu: 6.1.4 defu: 6.1.4
@@ -8141,7 +8136,7 @@ snapshots:
'@nuxt/image@1.10.0(@netlify/blobs@9.1.2)(db0@0.3.4)(ioredis@5.8.2)(magicast@0.5.1)': '@nuxt/image@1.10.0(@netlify/blobs@9.1.2)(db0@0.3.4)(ioredis@5.8.2)(magicast@0.5.1)':
dependencies: dependencies:
'@nuxt/kit': 3.18.0(magicast@0.5.1) '@nuxt/kit': 3.20.1(magicast@0.5.1)
consola: 3.4.2 consola: 3.4.2
defu: 6.1.4 defu: 6.1.4
h3: 1.15.5 h3: 1.15.5
@@ -8175,33 +8170,6 @@ snapshots:
- magicast - magicast
- uploadthing - uploadthing
'@nuxt/kit@3.18.0(magicast@0.5.1)':
dependencies:
c12: 3.2.0(magicast@0.5.1)
consola: 3.4.2
defu: 6.1.4
destr: 2.0.5
errx: 0.1.0
exsolve: 1.0.7
ignore: 7.0.5
jiti: 2.5.1
klona: 2.0.6
knitwork: 1.2.0
mlly: 1.7.4
ohash: 2.0.11
pathe: 2.0.3
pkg-types: 2.2.0
scule: 1.3.0
semver: 7.7.2
std-env: 3.9.0
tinyglobby: 0.2.14
ufo: 1.6.3
unctx: 2.4.1
unimport: 5.2.0
untyped: 2.0.0
transitivePeerDependencies:
- magicast
'@nuxt/kit@3.20.1(magicast@0.5.1)': '@nuxt/kit@3.20.1(magicast@0.5.1)':
dependencies: dependencies:
c12: 3.3.2(magicast@0.5.1) c12: 3.3.2(magicast@0.5.1)
@@ -8228,32 +8196,6 @@ snapshots:
transitivePeerDependencies: transitivePeerDependencies:
- magicast - magicast
'@nuxt/kit@4.0.2(magicast@0.5.1)':
dependencies:
c12: 3.2.0(magicast@0.5.1)
consola: 3.4.2
defu: 6.1.4
destr: 2.0.5
errx: 0.1.0
exsolve: 1.0.7
ignore: 7.0.5
jiti: 2.5.1
klona: 2.0.6
mlly: 1.7.4
ohash: 2.0.11
pathe: 2.0.3
pkg-types: 2.2.0
scule: 1.3.0
semver: 7.7.2
std-env: 3.9.0
tinyglobby: 0.2.14
ufo: 1.6.3
unctx: 2.4.1
unimport: 5.2.0
untyped: 2.0.0
transitivePeerDependencies:
- magicast
'@nuxt/kit@4.2.1(magicast@0.5.1)': '@nuxt/kit@4.2.1(magicast@0.5.1)':
dependencies: dependencies:
c12: 3.3.2(magicast@0.5.1) c12: 3.3.2(magicast@0.5.1)
@@ -8436,7 +8378,7 @@ snapshots:
'@intlify/unplugin-vue-i18n': 6.0.8(@vue/compiler-dom@3.5.27)(eslint@9.31.0(jiti@2.6.1))(rollup@4.53.3)(typescript@5.8.3)(vue-i18n@10.0.8(vue@3.5.27(typescript@5.8.3)))(vue@3.5.27(typescript@5.8.3)) '@intlify/unplugin-vue-i18n': 6.0.8(@vue/compiler-dom@3.5.27)(eslint@9.31.0(jiti@2.6.1))(rollup@4.53.3)(typescript@5.8.3)(vue-i18n@10.0.8(vue@3.5.27(typescript@5.8.3)))(vue@3.5.27(typescript@5.8.3))
'@intlify/utils': 0.13.0 '@intlify/utils': 0.13.0
'@miyaneee/rollup-plugin-json5': 1.2.0(rollup@4.53.3) '@miyaneee/rollup-plugin-json5': 1.2.0(rollup@4.53.3)
'@nuxt/kit': 3.18.0(magicast@0.5.1) '@nuxt/kit': 3.20.1(magicast@0.5.1)
'@oxc-parser/wasm': 0.60.0 '@oxc-parser/wasm': 0.60.0
'@rollup/plugin-yaml': 4.1.2(rollup@4.53.3) '@rollup/plugin-yaml': 4.1.2(rollup@4.53.3)
'@vue/compiler-sfc': 3.5.18 '@vue/compiler-sfc': 3.5.18
@@ -9427,7 +9369,7 @@ snapshots:
fast-glob: 3.3.3 fast-glob: 3.3.3
is-glob: 4.0.3 is-glob: 4.0.3
minimatch: 9.0.5 minimatch: 9.0.5
semver: 7.7.2 semver: 7.7.3
ts-api-utils: 2.1.0(typescript@5.8.3) ts-api-utils: 2.1.0(typescript@5.8.3)
typescript: 5.8.3 typescript: 5.8.3
transitivePeerDependencies: transitivePeerDependencies:
@@ -9826,7 +9768,7 @@ snapshots:
'@vueuse/nuxt@13.6.0(magicast@0.5.1)(nuxt@3.20.1(@netlify/blobs@9.1.2)(@parcel/watcher@2.5.1)(@types/node@22.16.5)(@vue/compiler-sfc@3.5.27)(db0@0.3.4)(eslint@9.31.0(jiti@2.6.1))(ioredis@5.8.2)(lightningcss@1.30.1)(magicast@0.5.1)(ms@2.1.3)(optionator@0.9.4)(rollup@4.53.3)(sass@1.89.2)(terser@5.43.1)(typescript@5.8.3)(vite@7.2.2(@types/node@22.16.5)(jiti@2.6.1)(lightningcss@1.30.1)(sass@1.89.2)(terser@5.43.1)(yaml@2.8.1))(vue-tsc@3.0.4(typescript@5.8.3))(yaml@2.8.1))(vue@3.5.27(typescript@5.8.3))': '@vueuse/nuxt@13.6.0(magicast@0.5.1)(nuxt@3.20.1(@netlify/blobs@9.1.2)(@parcel/watcher@2.5.1)(@types/node@22.16.5)(@vue/compiler-sfc@3.5.27)(db0@0.3.4)(eslint@9.31.0(jiti@2.6.1))(ioredis@5.8.2)(lightningcss@1.30.1)(magicast@0.5.1)(ms@2.1.3)(optionator@0.9.4)(rollup@4.53.3)(sass@1.89.2)(terser@5.43.1)(typescript@5.8.3)(vite@7.2.2(@types/node@22.16.5)(jiti@2.6.1)(lightningcss@1.30.1)(sass@1.89.2)(terser@5.43.1)(yaml@2.8.1))(vue-tsc@3.0.4(typescript@5.8.3))(yaml@2.8.1))(vue@3.5.27(typescript@5.8.3))':
dependencies: dependencies:
'@nuxt/kit': 4.0.2(magicast@0.5.1) '@nuxt/kit': 4.2.1(magicast@0.5.1)
'@vueuse/core': 13.6.0(vue@3.5.27(typescript@5.8.3)) '@vueuse/core': 13.6.0(vue@3.5.27(typescript@5.8.3))
'@vueuse/metadata': 13.6.0 '@vueuse/metadata': 13.6.0
local-pkg: 1.1.1 local-pkg: 1.1.1
@@ -10129,23 +10071,6 @@ snapshots:
optionalDependencies: optionalDependencies:
magicast: 0.3.5 magicast: 0.3.5
c12@3.2.0(magicast@0.5.1):
dependencies:
chokidar: 4.0.3
confbox: 0.2.2
defu: 6.1.4
dotenv: 17.2.3
exsolve: 1.0.7
giget: 2.0.0
jiti: 2.5.1
ohash: 2.0.11
pathe: 2.0.3
perfect-debounce: 1.0.0
pkg-types: 2.2.0
rc9: 2.1.2
optionalDependencies:
magicast: 0.5.1
c12@3.3.2(magicast@0.5.1): c12@3.3.2(magicast@0.5.1):
dependencies: dependencies:
chokidar: 4.0.3 chokidar: 4.0.3
@@ -10844,7 +10769,7 @@ snapshots:
eslint-import-context: 0.1.9(unrs-resolver@1.11.1) eslint-import-context: 0.1.9(unrs-resolver@1.11.1)
is-glob: 4.0.3 is-glob: 4.0.3
minimatch: 10.0.3 minimatch: 10.0.3
semver: 7.7.2 semver: 7.7.3
stable-hash-x: 0.2.0 stable-hash-x: 0.2.0
unrs-resolver: 1.11.1 unrs-resolver: 1.11.1
optionalDependencies: optionalDependencies:
@@ -10863,7 +10788,7 @@ snapshots:
espree: 10.4.0 espree: 10.4.0
esquery: 1.6.0 esquery: 1.6.0
parse-imports-exports: 0.2.4 parse-imports-exports: 0.2.4
semver: 7.7.2 semver: 7.7.3
spdx-expression-parse: 4.0.0 spdx-expression-parse: 4.0.0
transitivePeerDependencies: transitivePeerDependencies:
- supports-color - supports-color
@@ -10898,7 +10823,7 @@ snapshots:
pluralize: 8.0.0 pluralize: 8.0.0
regexp-tree: 0.1.27 regexp-tree: 0.1.27
regjsparser: 0.12.0 regjsparser: 0.12.0
semver: 7.7.2 semver: 7.7.3
strip-indent: 4.0.0 strip-indent: 4.0.0
eslint-plugin-vue@10.4.0(@typescript-eslint/parser@8.38.0(eslint@9.31.0(jiti@2.6.1))(typescript@5.8.3))(eslint@9.31.0(jiti@2.6.1))(vue-eslint-parser@10.2.0(eslint@9.31.0(jiti@2.6.1))): eslint-plugin-vue@10.4.0(@typescript-eslint/parser@8.38.0(eslint@9.31.0(jiti@2.6.1))(typescript@5.8.3))(eslint@9.31.0(jiti@2.6.1))(vue-eslint-parser@10.2.0(eslint@9.31.0(jiti@2.6.1))):
@@ -10908,7 +10833,7 @@ snapshots:
natural-compare: 1.4.0 natural-compare: 1.4.0
nth-check: 2.1.1 nth-check: 2.1.1
postcss-selector-parser: 6.1.2 postcss-selector-parser: 6.1.2
semver: 7.7.2 semver: 7.7.3
vue-eslint-parser: 10.2.0(eslint@9.31.0(jiti@2.6.1)) vue-eslint-parser: 10.2.0(eslint@9.31.0(jiti@2.6.1))
xml-name-validator: 4.0.0 xml-name-validator: 4.0.0
optionalDependencies: optionalDependencies:
@@ -11636,7 +11561,7 @@ snapshots:
acorn: 8.15.0 acorn: 8.15.0
eslint-visitor-keys: 3.4.3 eslint-visitor-keys: 3.4.3
espree: 9.6.1 espree: 9.6.1
semver: 7.7.2 semver: 7.7.3
jsonfile@4.0.0: jsonfile@4.0.0:
optionalDependencies: optionalDependencies:
@@ -11760,8 +11685,8 @@ snapshots:
local-pkg@1.1.1: local-pkg@1.1.1:
dependencies: dependencies:
mlly: 1.7.4 mlly: 1.8.0
pkg-types: 2.2.0 pkg-types: 2.3.0
quansync: 0.2.10 quansync: 0.2.10
local-pkg@1.1.2: local-pkg@1.1.2:
@@ -11819,7 +11744,7 @@ snapshots:
dependencies: dependencies:
estree-walker: 3.0.3 estree-walker: 3.0.3
magic-string: 0.30.17 magic-string: 0.30.17
mlly: 1.7.4 mlly: 1.8.0
regexp-tree: 0.1.27 regexp-tree: 0.1.27
type-level-regexp: 0.1.17 type-level-regexp: 0.1.17
ufo: 1.6.3 ufo: 1.6.3
@@ -12312,7 +12237,7 @@ snapshots:
node-abi@3.75.0: node-abi@3.75.0:
dependencies: dependencies:
semver: 7.7.2 semver: 7.7.3
optional: true optional: true
node-addon-api@6.1.0: node-addon-api@6.1.0:
@@ -12363,7 +12288,7 @@ snapshots:
normalize-package-data@6.0.2: normalize-package-data@6.0.2:
dependencies: dependencies:
hosted-git-info: 7.0.2 hosted-git-info: 7.0.2
semver: 7.7.2 semver: 7.7.3
validate-npm-package-license: 3.0.4 validate-npm-package-license: 3.0.4
normalize-path@2.1.1: normalize-path@2.1.1:
@@ -12391,7 +12316,7 @@ snapshots:
nuxt-csurf@1.6.5(magicast@0.5.1): nuxt-csurf@1.6.5(magicast@0.5.1):
dependencies: dependencies:
'@nuxt/kit': 3.18.0(magicast@0.5.1) '@nuxt/kit': 3.20.1(magicast@0.5.1)
defu: 6.1.4 defu: 6.1.4
uncsrf: 1.2.0 uncsrf: 1.2.0
transitivePeerDependencies: transitivePeerDependencies:
@@ -12399,7 +12324,7 @@ snapshots:
nuxt-security@2.2.0(magicast@0.5.1)(rollup@4.53.3): nuxt-security@2.2.0(magicast@0.5.1)(rollup@4.53.3):
dependencies: dependencies:
'@nuxt/kit': 3.18.0(magicast@0.5.1) '@nuxt/kit': 3.20.1(magicast@0.5.1)
basic-auth: 2.0.1 basic-auth: 2.0.1
defu: 6.1.4 defu: 6.1.4
nuxt-csurf: 1.6.5(magicast@0.5.1) nuxt-csurf: 1.6.5(magicast@0.5.1)
@@ -13424,7 +13349,7 @@ snapshots:
detect-libc: 2.0.4 detect-libc: 2.0.4
node-addon-api: 6.1.0 node-addon-api: 6.1.0
prebuild-install: 7.1.3 prebuild-install: 7.1.3
semver: 7.7.2 semver: 7.7.3
simple-get: 4.0.1 simple-get: 4.0.1
tar-fs: 3.1.1 tar-fs: 3.1.1
tunnel-agent: 0.6.0 tunnel-agent: 0.6.0
@@ -13902,13 +13827,13 @@ snapshots:
estree-walker: 3.0.3 estree-walker: 3.0.3
local-pkg: 1.1.1 local-pkg: 1.1.1
magic-string: 0.30.17 magic-string: 0.30.17
mlly: 1.7.4 mlly: 1.8.0
pathe: 2.0.3 pathe: 2.0.3
picomatch: 4.0.3 picomatch: 4.0.3
pkg-types: 2.2.0 pkg-types: 2.3.0
scule: 1.3.0 scule: 1.3.0
strip-literal: 3.0.0 strip-literal: 3.0.0
tinyglobby: 0.2.14 tinyglobby: 0.2.15
unplugin: 2.3.5 unplugin: 2.3.5
unplugin-utils: 0.2.4 unplugin-utils: 0.2.4
@@ -13969,7 +13894,7 @@ snapshots:
local-pkg: 1.1.1 local-pkg: 1.1.1
magic-string: 0.30.17 magic-string: 0.30.17
micromatch: 4.0.8 micromatch: 4.0.8
mlly: 1.7.4 mlly: 1.8.0
pathe: 2.0.3 pathe: 2.0.3
scule: 1.3.0 scule: 1.3.0
unplugin: 2.3.5 unplugin: 2.3.5
@@ -14266,7 +14191,7 @@ snapshots:
eslint-visitor-keys: 4.2.1 eslint-visitor-keys: 4.2.1
espree: 10.4.0 espree: 10.4.0
esquery: 1.6.0 esquery: 1.6.0
semver: 7.7.2 semver: 7.7.3
transitivePeerDependencies: transitivePeerDependencies:
- supports-color - supports-color
@@ -14290,7 +14215,7 @@ snapshots:
vue3-carousel-nuxt@1.1.6(magicast@0.5.1)(vue@3.5.27(typescript@5.8.3)): vue3-carousel-nuxt@1.1.6(magicast@0.5.1)(vue@3.5.27(typescript@5.8.3)):
dependencies: dependencies:
'@nuxt/kit': 3.18.0(magicast@0.5.1) '@nuxt/kit': 3.20.1(magicast@0.5.1)
vue3-carousel: 0.15.1(vue@3.5.27(typescript@5.8.3)) vue3-carousel: 0.15.1(vue@3.5.27(typescript@5.8.3))
transitivePeerDependencies: transitivePeerDependencies:
- magicast - magicast

View File

@@ -0,0 +1,17 @@
-- CreateEnum
CREATE TYPE "GameType" AS ENUM ('Game', 'Executor', 'Redist');
-- DropIndex
DROP INDEX "Game_mName_idx";
-- DropIndex
DROP INDEX "GameTag_name_idx";
-- AlterTable
ALTER TABLE "Game" ADD COLUMN "type" "GameType" NOT NULL DEFAULT 'Game';
-- CreateIndex
CREATE INDEX "Game_mName_idx" ON "Game" USING GIST ("mName" gist_trgm_ops(siglen=32));
-- CreateIndex
CREATE INDEX "GameTag_name_idx" ON "GameTag" USING GIST ("name" gist_trgm_ops(siglen=32));

View File

@@ -0,0 +1,64 @@
/*
Warnings:
- The primary key for the `GameVersion` table will be changed. If it partially fails, the table could be left without primary key constraint.
- You are about to drop the column `gameId` on the `LaunchConfiguration` table. All the data in the column will be lost.
- You are about to drop the column `gameId` on the `SetupConfiguration` table. All the data in the column will be lost.
*/
-- DropForeignKey
ALTER TABLE "LaunchConfiguration" DROP CONSTRAINT "LaunchConfiguration_executorId_fkey";
-- DropForeignKey
ALTER TABLE "LaunchConfiguration" DROP CONSTRAINT "LaunchConfiguration_gameId_versionId_fkey";
-- DropForeignKey
ALTER TABLE "SetupConfiguration" DROP CONSTRAINT "SetupConfiguration_gameId_versionId_fkey";
-- DropIndex
DROP INDEX "Game_mName_idx";
-- DropIndex
DROP INDEX "GameTag_name_idx";
-- AlterTable
ALTER TABLE "GameVersion" DROP CONSTRAINT "GameVersion_pkey",
ADD CONSTRAINT "GameVersion_pkey" PRIMARY KEY ("versionId");
-- AlterTable
ALTER TABLE "LaunchConfiguration" DROP COLUMN "gameId";
-- AlterTable
ALTER TABLE "SetupConfiguration" DROP COLUMN "gameId";
-- CreateTable
CREATE TABLE "_requiredContent" (
"A" TEXT NOT NULL,
"B" TEXT NOT NULL,
CONSTRAINT "_requiredContent_AB_pkey" PRIMARY KEY ("A","B")
);
-- CreateIndex
CREATE INDEX "_requiredContent_B_index" ON "_requiredContent"("B");
-- CreateIndex
CREATE INDEX "Game_mName_idx" ON "Game" USING GIST ("mName" gist_trgm_ops(siglen=32));
-- CreateIndex
CREATE INDEX "GameTag_name_idx" ON "GameTag" USING GIST ("name" gist_trgm_ops(siglen=32));
-- AddForeignKey
ALTER TABLE "SetupConfiguration" ADD CONSTRAINT "SetupConfiguration_versionId_fkey" FOREIGN KEY ("versionId") REFERENCES "GameVersion"("versionId") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "LaunchConfiguration" ADD CONSTRAINT "LaunchConfiguration_executorId_fkey" FOREIGN KEY ("executorId") REFERENCES "LaunchConfiguration"("launchId") ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "LaunchConfiguration" ADD CONSTRAINT "LaunchConfiguration_versionId_fkey" FOREIGN KEY ("versionId") REFERENCES "GameVersion"("versionId") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "_requiredContent" ADD CONSTRAINT "_requiredContent_A_fkey" FOREIGN KEY ("A") REFERENCES "GameVersion"("versionId") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "_requiredContent" ADD CONSTRAINT "_requiredContent_B_fkey" FOREIGN KEY ("B") REFERENCES "GameVersion"("versionId") ON DELETE CASCADE ON UPDATE CASCADE;

View File

@@ -0,0 +1,14 @@
-- DropIndex
DROP INDEX "Game_mName_idx";
-- DropIndex
DROP INDEX "GameTag_name_idx";
-- AlterTable
ALTER TABLE "LaunchConfiguration" ADD COLUMN "executorSuggestions" TEXT[];
-- CreateIndex
CREATE INDEX "Game_mName_idx" ON "Game" USING GIST ("mName" gist_trgm_ops(siglen=32));
-- CreateIndex
CREATE INDEX "GameTag_name_idx" ON "GameTag" USING GIST ("name" gist_trgm_ops(siglen=32));

View File

@@ -0,0 +1,27 @@
-- DropIndex
DROP INDEX "Game_mName_idx";
-- DropIndex
DROP INDEX "GameTag_name_idx";
-- AlterTable
ALTER TABLE "GameVersion" ALTER COLUMN "versionPath" DROP NOT NULL;
-- CreateTable
CREATE TABLE "UnimportedGameVersion" (
"id" TEXT NOT NULL,
"gameId" TEXT NOT NULL,
"versionName" TEXT NOT NULL,
"manifest" JSONB NOT NULL,
CONSTRAINT "UnimportedGameVersion_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE INDEX "Game_mName_idx" ON "Game" USING GIST ("mName" gist_trgm_ops(siglen=32));
-- CreateIndex
CREATE INDEX "GameTag_name_idx" ON "GameTag" USING GIST ("name" gist_trgm_ops(siglen=32));
-- AddForeignKey
ALTER TABLE "UnimportedGameVersion" ADD CONSTRAINT "UnimportedGameVersion_gameId_fkey" FOREIGN KEY ("gameId") REFERENCES "Game"("id") ON DELETE CASCADE ON UPDATE CASCADE;

View File

@@ -0,0 +1,14 @@
-- DropIndex
DROP INDEX "Game_mName_idx";
-- DropIndex
DROP INDEX "GameTag_name_idx";
-- AlterTable
ALTER TABLE "UnimportedGameVersion" ADD COLUMN "fileList" TEXT[];
-- CreateIndex
CREATE INDEX "Game_mName_idx" ON "Game" USING GIST ("mName" gist_trgm_ops(siglen=32));
-- CreateIndex
CREATE INDEX "GameTag_name_idx" ON "GameTag" USING GIST ("name" gist_trgm_ops(siglen=32));

View File

@@ -0,0 +1,15 @@
-- DropIndex
DROP INDEX "Game_mName_idx";
-- DropIndex
DROP INDEX "GameTag_name_idx";
-- AlterTable
ALTER TABLE "GameVersion" ADD COLUMN "fileList" TEXT[],
ADD COLUMN "negativeFileList" TEXT[];
-- CreateIndex
CREATE INDEX "Game_mName_idx" ON "Game" USING GIST ("mName" gist_trgm_ops(siglen=32));
-- CreateIndex
CREATE INDEX "GameTag_name_idx" ON "GameTag" USING GIST ("name" gist_trgm_ops(siglen=32));

View File

@@ -8,6 +8,12 @@ enum MetadataSource {
OpenCritic OpenCritic
} }
enum GameType {
Game
Executor
Redist
}
model Game { model Game {
id String @id @default(uuid()) id String @id @default(uuid())
@@ -15,6 +21,8 @@ model Game {
metadataId String metadataId String
created DateTime @default(now()) created DateTime @default(now())
type GameType @default(Game)
// Any field prefixed with m is filled in from metadata // Any field prefixed with m is filled in from metadata
// Acts as a cache so we can search and filter it // Acts as a cache so we can search and filter it
mName String // Name of game mName String // Name of game
@@ -47,8 +55,9 @@ model Game {
tags GameTag[] tags GameTag[]
playtime Playtime[] playtime Playtime[]
developers Company[] @relation(name: "developers") developers Company[] @relation(name: "developers")
publishers Company[] @relation(name: "publishers") publishers Company[] @relation(name: "publishers")
unimportedGameVersions UnimportedGameVersion[]
@@unique([metadataSource, metadataId], name: "metadataKey") @@unique([metadataSource, metadataId], name: "metadataKey")
@@unique([libraryId, libraryPath], name: "libraryKey") @@unique([libraryId, libraryPath], name: "libraryKey")
@@ -82,14 +91,24 @@ model GameRating {
@@unique([metadataSource, metadataId], name: "metadataKey") @@unique([metadataSource, metadataId], name: "metadataKey")
} }
model UnimportedGameVersion {
id String @id @default(uuid())
gameId String
game Game @relation(fields: [gameId], references: [id], onDelete: Cascade)
versionName String
manifest Json
fileList String[]
}
// A particular set of files that relate to the version // A particular set of files that relate to the version
model GameVersion { model GameVersion {
gameId String gameId String
game Game @relation(fields: [gameId], references: [id], onDelete: Cascade) game Game @relation(fields: [gameId], references: [id], onDelete: Cascade)
versionId String @default(uuid()) versionId String @id @default(uuid())
displayName String? displayName String?
versionPath String versionPath String?
created DateTime @default(now()) created DateTime @default(now())
@@ -98,12 +117,15 @@ model GameVersion {
onlySetup Boolean @default(false) onlySetup Boolean @default(false)
dropletManifest Json // Results from droplet dropletManifest Json // Results from droplet
fileList String[] // List of all files, for delta updates
negativeFileList String[] // List of files to remove, for delta updates
versionIndex Int versionIndex Int
delta Boolean @default(false) delta Boolean @default(false)
@@id([gameId, versionId]) requiredContent GameVersion[] @relation(name: "requiredContent")
requiringContent GameVersion[] @relation(name: "requiredContent")
} }
model SetupConfiguration { model SetupConfiguration {
@@ -113,9 +135,8 @@ model SetupConfiguration {
platform Platform platform Platform
gameId String
versionId String versionId String
gameVersion GameVersion @relation(fields: [gameId, versionId], references: [gameId, versionId], onDelete: Cascade, onUpdate: Cascade) gameVersion GameVersion @relation(fields: [versionId], references: [versionId], onDelete: Cascade, onUpdate: Cascade)
} }
model LaunchConfiguration { model LaunchConfiguration {
@@ -128,14 +149,14 @@ model LaunchConfiguration {
platform Platform platform Platform
// For emulation targets // For emulation targets
executorId String? executorId String?
executor LaunchConfiguration? @relation(fields: [executorId], references: [launchId], name: "executor", onDelete: Cascade, onUpdate: Cascade) executor LaunchConfiguration? @relation(fields: [executorId], references: [launchId], name: "executor")
executorSuggestions String[]
umuIdOverride String? umuIdOverride String?
gameId String
versionId String versionId String
gameVersion GameVersion @relation(fields: [gameId, versionId], references: [gameId, versionId], onDelete: Cascade, onUpdate: Cascade) gameVersion GameVersion @relation(fields: [versionId], references: [versionId], onDelete: Cascade, onUpdate: Cascade)
executions LaunchConfiguration[] @relation("executor") executions LaunchConfiguration[] @relation("executor")
} }

View File

@@ -0,0 +1,11 @@
import aclManager from "~/server/internal/acls";
import prisma from "~/server/internal/db/database";
export default defineEventHandler(async (h3) => {
const allowed = await aclManager.allowSystemACL(h3, ["depot:read"]);
if (!allowed) throw createError({ statusCode: 403 });
const depots = await prisma.depot.findMany({});
return depots;
});

View File

@@ -6,7 +6,6 @@ import { castManifest } from "~/server/internal/library/manifest";
const AUTHORIZATION_HEADER_PREFIX = "Bearer "; const AUTHORIZATION_HEADER_PREFIX = "Bearer ";
const Query = type({ const Query = type({
game: "string",
version: "string", version: "string",
}); });
@@ -31,10 +30,7 @@ export default defineEventHandler(async (h3) => {
const version = await prisma.gameVersion.findUnique({ const version = await prisma.gameVersion.findUnique({
where: { where: {
gameId_versionId: { versionId: query.version,
gameId: query.game,
versionId: query.version,
},
}, },
select: { select: {
dropletManifest: true, dropletManifest: true,

View File

@@ -11,6 +11,11 @@ export default defineEventHandler(async (h3) => {
select: { select: {
versionId: true, versionId: true,
}, },
where: {
versionPath: {
not: null
}
}
}, },
}, },
}); });

View File

@@ -0,0 +1,51 @@
import { type } from "arktype";
import { readDropValidatedBody, throwingArktype } from "~/server/arktype";
import aclManager from "~/server/internal/acls";
import prisma from "~/server/internal/db/database";
const UploadManifest = type({
gameId: "string",
versionName: "string",
manifest: type({
version: "'2'",
size: "number",
key: "16 <= number[] <= 16",
chunks: type({
["string"]: {
checksum: "string",
iv: "16 <= number[] <= 16",
files: type({
filename: "string",
start: "number",
length: "number",
permissions: "number",
}).array(),
},
}),
}),
fileList: "string[]",
}).configure(throwingArktype);
export default defineEventHandler(async (h3) => {
const allowed = await aclManager.allowSystemACL(h3, ["depot:upload:new"]);
if (!allowed) throw createError({ statusCode: 403 });
const { gameId, versionName, manifest, fileList } =
await readDropValidatedBody(h3, UploadManifest);
const version = await prisma.unimportedGameVersion.create({
data: {
game: {
connect: {
id: gameId,
},
},
versionName,
manifest,
fileList,
},
});
return { id: version.id };
});

View File

@@ -1,6 +1,7 @@
import type { GameVersion, Prisma } from "~/prisma/client/client"; import type { GameVersion, Prisma } from "~/prisma/client/client";
import aclManager from "~/server/internal/acls"; import aclManager from "~/server/internal/acls";
import prisma from "~/server/internal/db/database"; import prisma from "~/server/internal/db/database";
import type { UnimportedVersionInformation } from "~/server/internal/library";
import libraryManager from "~/server/internal/library"; import libraryManager from "~/server/internal/library";
async function getGameVersionSize< async function getGameVersionSize<
@@ -59,7 +60,7 @@ export default defineEventHandler<
{ body: never }, { body: never },
Promise<{ Promise<{
game: AdminFetchGameType; game: AdminFetchGameType;
unimportedVersions: string[] | undefined; unimportedVersions: UnimportedVersionInformation[] | undefined;
}> }>
>(async (h3) => { >(async (h3) => {
const allowed = await aclManager.allowSystemACL(h3, ["game:read"]); const allowed = await aclManager.allowSystemACL(h3, ["game:read"]);

View File

@@ -1,4 +1,5 @@
import { type } from "arktype"; import { type } from "arktype";
import { GameType } from "~/prisma/client/enums";
import { readDropValidatedBody, throwingArktype } from "~/server/arktype"; import { readDropValidatedBody, throwingArktype } from "~/server/arktype";
import aclManager from "~/server/internal/acls"; import aclManager from "~/server/internal/acls";
import libraryManager from "~/server/internal/library"; import libraryManager from "~/server/internal/library";
@@ -7,6 +8,7 @@ import metadataHandler from "~/server/internal/metadata";
const ImportGameBody = type({ const ImportGameBody = type({
library: "string", library: "string",
path: "string", path: "string",
type: type.valueOf(GameType),
["metadata?"]: { ["metadata?"]: {
id: "string", id: "string",
sourceId: "string", sourceId: "string",
@@ -19,7 +21,7 @@ export default defineEventHandler<{ body: typeof ImportGameBody.infer }>(
const allowed = await aclManager.allowSystemACL(h3, ["import:game:new"]); const allowed = await aclManager.allowSystemACL(h3, ["import:game:new"]);
if (!allowed) throw createError({ statusCode: 403 }); if (!allowed) throw createError({ statusCode: 403 });
const { library, path, metadata } = await readDropValidatedBody( const { library, path, metadata, type } = await readDropValidatedBody(
h3, h3,
ImportGameBody, ImportGameBody,
); );
@@ -38,8 +40,8 @@ export default defineEventHandler<{ body: typeof ImportGameBody.infer }>(
}); });
const taskId = metadata const taskId = metadata
? await metadataHandler.createGame(metadata, library, path) ? await metadataHandler.createGame(metadata, library, path, type)
: await metadataHandler.createGameWithoutMetadata(library, path); : await metadataHandler.createGameWithoutMetadata(library, path, type);
if (!taskId) if (!taskId)
throw createError({ throw createError({

View File

@@ -16,7 +16,7 @@ export default defineEventHandler(async (h3) => {
const game = await prisma.game.findUnique({ const game = await prisma.game.findUnique({
where: { id: gameId }, where: { id: gameId },
select: { libraryId: true, libraryPath: true }, select: { libraryId: true, libraryPath: true, type: true },
}); });
if (!game || !game.libraryId) if (!game || !game.libraryId)
throw createError({ statusCode: 404, statusMessage: "Game not found" }); throw createError({ statusCode: 404, statusMessage: "Game not found" });
@@ -28,5 +28,5 @@ export default defineEventHandler(async (h3) => {
if (!unimportedVersions) if (!unimportedVersions)
throw createError({ statusCode: 400, statusMessage: "Invalid game ID" }); throw createError({ statusCode: 400, statusMessage: "Invalid game ID" });
return unimportedVersions; return { versions: unimportedVersions, type: game.type };
}); });

View File

@@ -7,7 +7,11 @@ import libraryManager from "~/server/internal/library";
export const ImportVersion = type({ export const ImportVersion = type({
id: "string", id: "string",
version: "string", version: type({
type: "'depot' | 'local'",
identifier: "string",
name: "string",
}),
displayName: "string?", displayName: "string?",
launches: type({ launches: type({
@@ -16,6 +20,7 @@ export const ImportVersion = type({
launch: "string", launch: "string",
umuId: "string?", umuId: "string?",
executorId: "string?", executorId: "string?",
suggestions: "string[]?",
}).array(), }).array(),
setups: type({ setups: type({
@@ -25,6 +30,10 @@ export const ImportVersion = type({
onlySetup: "boolean = false", onlySetup: "boolean = false",
delta: "boolean = false", delta: "boolean = false",
requiredContent: type("string")
.array()
.default(() => []),
}).configure(throwingArktype); }).configure(throwingArktype);
export default defineEventHandler(async (h3) => { export default defineEventHandler(async (h3) => {
@@ -47,7 +56,7 @@ export default defineEventHandler(async (h3) => {
if (validOverlayVersions == 0) if (validOverlayVersions == 0)
throw createError({ throw createError({
statusCode: 400, statusCode: 400,
statusMessage: "Update mode requires a pre-existing version.", statusMessage: `Update mode requires a pre-existing version for platform: ${platformObject.platform}`,
}); });
} }
} }

View File

@@ -1,35 +1,43 @@
import { ArkErrors, type } from "arktype";
import aclManager from "~/server/internal/acls"; import aclManager from "~/server/internal/acls";
import libraryManager from "~/server/internal/library"; import libraryManager from "~/server/internal/library";
const Query = type({
id: "string",
type: "'depot' | 'local'",
version: "string",
});
export default defineEventHandler(async (h3) => { export default defineEventHandler(async (h3) => {
const allowed = await aclManager.allowSystemACL(h3, ["import:version:read"]); const allowed = await aclManager.allowSystemACL(h3, ["import:version:read"]);
if (!allowed) throw createError({ statusCode: 403 }); if (!allowed) throw createError({ statusCode: 403 });
const query = await getQuery(h3); const query = Query(getQuery(h3));
const gameId = query.id?.toString(); if (query instanceof ArkErrors)
const versionName = query.version?.toString();
if (!gameId || !versionName)
throw createError({ throw createError({
statusCode: 400, statusCode: 400,
statusMessage: "Missing id or version in request params", message: query.summary,
}); });
try { try {
const preload = await libraryManager.fetchUnimportedVersionInformation( const preload = await libraryManager.fetchUnimportedVersionInformation(
gameId, query.id,
versionName, {
type: query.type,
identifier: query.version,
},
); );
if (!preload) if (!preload)
throw createError({ throw createError({
statusCode: 400, statusCode: 400,
statusMessage: "Invalid game or version id/name", message: "Invalid game or version id/name",
}); });
return preload; return preload;
} catch (e) { } catch (e) {
throw createError({ throw createError({
statusCode: 500, statusCode: 500,
message: `Failed to fetch preload information for ${gameId}: ${e}`, message: `Failed to fetch preload information for ${query.id}: ${e}`,
}); });
} }
}); });

View File

@@ -1,14 +1,19 @@
import { ArkErrors, type } from "arktype"; import { ArkErrors, type } from "arktype";
import { GameType } from "~/prisma/client/enums";
import aclManager from "~/server/internal/acls"; import aclManager from "~/server/internal/acls";
import prisma from "~/server/internal/db/database"; import prisma from "~/server/internal/db/database";
import type { GameMetadataSearchResult } from "~/server/internal/metadata/types"; import type { GameMetadataSearchResult } from "~/server/internal/metadata/types";
const Query = type({ const Query = type({
q: "string", q: "string",
type: type.valueOf(GameType).optional(),
}); });
export default defineEventHandler(async (h3) => { export default defineEventHandler(async (h3) => {
const allowed = await aclManager.allowSystemACL(h3, ["game:read"]); const allowed = await aclManager.allowSystemACL(h3, [
"game:read",
"depot:read",
]);
if (!allowed) throw createError({ statusCode: 403 }); if (!allowed) throw createError({ statusCode: 403 });
const query = Query(getQuery(h3)); const query = Query(getQuery(h3));
@@ -22,7 +27,7 @@ export default defineEventHandler(async (h3) => {
mShortDescription: string; mShortDescription: string;
mReleased: string; mReleased: string;
}[] = }[] =
await prisma.$queryRaw`SELECT id, "mName", "mIconObjectId", "mShortDescription", "mReleased" FROM "Game" WHERE SIMILARITY("mName", ${query.q}) > 0.2 ORDER BY SIMILARITY("mName", ${query.q}) DESC;`; await prisma.$queryRaw`SELECT id, "mName", "mIconObjectId", "mShortDescription", "mReleased" FROM "Game" WHERE SIMILARITY("mName", ${query.q}) > 0.2 AND (${query.type || "undefined"} = 'undefined' OR type::text = ${query.type}) ORDER BY SIMILARITY("mName", ${query.q}) DESC;`;
const resultsMapped = results.map( const resultsMapped = results.map(
(v) => (v) =>

View File

@@ -13,15 +13,24 @@ export default defineClientEventHandler(async (h3) => {
const gameVersion = await prisma.gameVersion.findUnique({ const gameVersion = await prisma.gameVersion.findUnique({
where: { where: {
gameId_versionId: { versionId: version,
gameId: id,
versionId: version,
},
}, },
include: { include: {
launches: { launches: {
include: { include: {
executor: true, executor: {
include: {
gameVersion: {
select: {
game: {
select: {
id: true,
},
},
},
},
},
},
}, },
}, },
setups: true, setups: true,
@@ -34,8 +43,22 @@ export default defineClientEventHandler(async (h3) => {
statusMessage: "Game version not found", statusMessage: "Game version not found",
}); });
return { const gameVersionMapped = {
...gameVersion, ...gameVersion,
launches: gameVersion.launches.map((launch) => ({
...launch,
executor: launch.executor
? {
...launch.executor,
gameVersion: undefined,
gameId: launch.executor.gameVersion.game.id,
}
: undefined,
})),
};
return {
...gameVersionMapped,
size: libraryManager.getGameVersionSize(id, version), size: libraryManager.getGameVersionSize(id, version),
}; };
}); });

View File

@@ -1,24 +1,15 @@
import { defineClientEventHandler } from "~/server/internal/clients/event-handler"; import { defineClientEventHandler } from "~/server/internal/clients/event-handler";
import prisma from "~/server/internal/db/database"; import { createDownloadManifestDetails } from "~/server/internal/library/manifest/index";
export default defineClientEventHandler(async (h3) => { export default defineClientEventHandler(async (h3) => {
const query = getQuery(h3); const query = getQuery(h3);
const id = query.id?.toString();
const version = query.version?.toString(); const version = query.version?.toString();
if (!id || !version) if (!version)
throw createError({ throw createError({
statusCode: 400, statusCode: 400,
statusMessage: "Missing id or version in query", statusMessage: "Missing version ID in query",
}); });
const manifest = await prisma.gameVersion.findUnique({ const result = await createDownloadManifestDetails(version);
where: { gameId_versionId: { gameId: id, versionId: version } }, return result;
select: { dropletManifest: true },
});
if (!manifest)
throw createError({
statusCode: 400,
statusMessage: "Invalid game or version, or no versions added.",
});
return manifest.dropletManifest;
}); });

View File

@@ -5,8 +5,8 @@ import gameSizeManager from "~/server/internal/gamesize";
type VersionDownloadOption = { type VersionDownloadOption = {
versionId: string; versionId: string;
displayName?: string; displayName?: string | undefined;
versionPath: string; versionPath?: string | undefined;
platform: Platform; platform: Platform;
size: number; size: number;
requiredContent: Array<{ requiredContent: Array<{
@@ -106,7 +106,8 @@ export default defineClientEventHandler(async (h3) => {
([platform, requiredContent]) => ([platform, requiredContent]) =>
({ ({
versionId: v.versionId, versionId: v.versionId,
versionPath: v.versionPath, displayName: v.displayName || undefined,
versionPath: v.versionPath || undefined,
platform, platform,
requiredContent, requiredContent,
size: size!, size: size!,

View File

@@ -1,5 +1,6 @@
import { ArkErrors, type } from "arktype"; import { ArkErrors, type } from "arktype";
import type { Prisma } from "~/prisma/client/client"; import type { Prisma } from "~/prisma/client/client";
import { GameType } from "~/prisma/client/enums";
import aclManager from "~/server/internal/acls"; import aclManager from "~/server/internal/acls";
import prisma from "~/server/internal/db/database"; import prisma from "~/server/internal/db/database";
import { parsePlatform } from "~/server/internal/utils/parseplatform"; import { parsePlatform } from "~/server/internal/utils/parseplatform";
@@ -100,6 +101,7 @@ export default defineEventHandler(async (h3) => {
...tagFilter, ...tagFilter,
...platformFilter, ...platformFilter,
...companyFilter, ...companyFilter,
type: GameType.Game,
}; };
const sort: Prisma.GameOrderByWithRelationInput = {}; const sort: Prisma.GameOrderByWithRelationInput = {};

View File

@@ -108,8 +108,11 @@ export const systemACLDescriptions: ObjectFromList<typeof systemACLs> = {
"settings:update": "Update system settings.", "settings:update": "Update system settings.",
"depot:read": "Read depot information, and search for games",
"depot:new": "Create a new download depot", "depot:new": "Create a new download depot",
"depot:delete": "Remove a download depot", "depot:delete": "Remove a download depot",
"depot:upload:new": "Upload a new version to a depot",
"depot:upload:delete": "Remove a depot version",
"system-data:listen": "system-data:listen":
"Connect to a websocket to receive system data updates.", "Connect to a websocket to receive system data updates.",

View File

@@ -47,8 +47,11 @@ export type UserACL = Array<(typeof userACLs)[number]>;
export const systemACLs = [ export const systemACLs = [
"setup", "setup",
"depot:read",
"depot:new", "depot:new",
"depot:delete", "depot:delete",
"depot:upload:new",
"depot:upload:delete",
"auth:read", "auth:read",
"auth:simple:invitation:read", "auth:simple:invitation:read",

View File

@@ -69,7 +69,7 @@ class GameSizeManager {
} }
const { dropletManifest } = (await prisma.gameVersion.findUnique({ const { dropletManifest } = (await prisma.gameVersion.findUnique({
where: { gameId_versionId: { versionId, gameId } }, where: { versionId },
}))!; }))!;
return castManifest(dropletManifest).size; return castManifest(dropletManifest).size;

View File

@@ -18,6 +18,8 @@ import type { WorkingLibrarySource } from "~/server/api/v1/admin/library/sources
import gameSizeManager from "~/server/internal/gamesize"; import gameSizeManager from "~/server/internal/gamesize";
import { TORRENTIAL_SERVICE } from "../services/services/torrential"; import { TORRENTIAL_SERVICE } from "../services/services/torrential";
import type { ImportVersion } from "~/server/api/v1/admin/import/version/index.post"; import type { ImportVersion } from "~/server/api/v1/admin/import/version/index.post";
import { GameType, type Platform } from "~/prisma/client/enums";
import { castManifest } from "./manifest";
export function createGameImportTaskId(libraryId: string, libraryPath: string) { export function createGameImportTaskId(libraryId: string, libraryPath: string) {
return createHash("md5") return createHash("md5")
@@ -34,6 +36,30 @@ export function createVersionImportTaskKey(
.digest("hex"); .digest("hex");
} }
export interface ExecutorVersionGuess {
type: "executor";
executorId: string;
icon: string;
gameName: string;
versionName: string;
launchName: string;
platform: Platform;
}
export interface PlatformVersionGuess {
platform: Platform;
type: "platform";
}
export type VersionGuess = {
filename: string;
match: number;
} & (PlatformVersionGuess | ExecutorVersionGuess);
export interface UnimportedVersionInformation {
type: "local" | "depot";
name: string;
identifier: string;
}
class LibraryManager { class LibraryManager {
private libraries: Map<string, LibraryProvider<unknown>> = new Map(); private libraries: Map<string, LibraryProvider<unknown>> = new Map();
@@ -95,7 +121,10 @@ class LibraryManager {
return unimportedGames; return unimportedGames;
} }
async fetchUnimportedGameVersions(libraryId: string, libraryPath: string) { async fetchUnimportedGameVersions(
libraryId: string,
libraryPath: string,
): Promise<UnimportedVersionInformation[] | undefined> {
const provider = this.libraries.get(libraryId); const provider = this.libraries.get(libraryId);
if (!provider) return undefined; if (!provider) return undefined;
const game = await prisma.game.findUnique({ const game = await prisma.game.findUnique({
@@ -115,14 +144,40 @@ class LibraryManager {
try { try {
const versions = await provider.listVersions( const versions = await provider.listVersions(
libraryPath, libraryPath,
game.versions.map((v) => v.versionPath), game.versions.map((v) => v.versionPath).filter((v) => v !== null),
); );
const unimportedVersions = versions.filter( const unimportedVersions = versions
(e) => .filter(
game.versions.findIndex((v) => v.versionPath == e) == -1 && (e) =>
!taskHandler.hasTaskKey(createVersionImportTaskKey(game.id, e)), game.versions.findIndex((v) => v.versionPath == e) == -1 &&
!taskHandler.hasTaskKey(createVersionImportTaskKey(game.id, e)),
)
.map(
(v) =>
({
type: "local",
name: v,
identifier: v,
}) satisfies UnimportedVersionInformation,
);
const depotVersions = await prisma.unimportedGameVersion.findMany({
where: {
gameId: game.id,
},
select: {
versionName: true,
id: true,
},
});
const mappedDepotVersions = depotVersions.map(
(v) =>
({
type: "depot",
name: v.versionName,
identifier: v.id,
}) satisfies UnimportedVersionInformation,
); );
return unimportedVersions; return [...unimportedVersions, ...mappedDepotVersions];
} catch (e) { } catch (e) {
if (e instanceof GameNotFoundError) { if (e instanceof GameNotFoundError) {
logger.warn(e); logger.warn(e);
@@ -165,10 +220,13 @@ class LibraryManager {
/** /**
* Fetches recommendations and extra data about the version. Doesn't actually check if it's been imported. * Fetches recommendations and extra data about the version. Doesn't actually check if it's been imported.
* @param gameId * @param gameId
* @param versionName * @param versionIdentifier
* @returns * @returns
*/ */
async fetchUnimportedVersionInformation(gameId: string, versionName: string) { async fetchUnimportedVersionInformation(
gameId: string,
versionIdentifier: Omit<UnimportedVersionInformation, "name">,
) {
const game = await prisma.game.findUnique({ const game = await prisma.game.findUnique({
where: { id: gameId }, where: { id: gameId },
select: { libraryPath: true, libraryId: true, mName: true }, select: { libraryPath: true, libraryId: true, mName: true },
@@ -178,7 +236,7 @@ class LibraryManager {
const library = this.libraries.get(game.libraryId); const library = this.libraries.get(game.libraryId);
if (!library) return undefined; if (!library) return undefined;
const fileExts: { [key: string]: string[] } = { const fileExts: { [key in Platform]: string[] } = {
Linux: [ Linux: [
// Ext for Unity games // Ext for Unity games
".x86_64", ".x86_64",
@@ -196,13 +254,60 @@ class LibraryManager {
], ],
}; };
const options: Array<{ const executorSuggestions = await prisma.launchConfiguration.findMany({
filename: string; where: {
platform: string; executorSuggestions: {
match: number; isEmpty: false,
}> = []; },
gameVersion: {
game: {
type: GameType.Executor,
},
},
},
select: {
executorSuggestions: true,
gameVersion: {
select: {
game: {
select: {
mIconObjectId: true,
mName: true,
},
},
displayName: true,
versionPath: true,
},
},
name: true,
launchId: true,
platform: true,
},
});
const options: Array<VersionGuess> = [];
let files;
if (versionIdentifier.type === "local") {
files = await library.versionReaddir(
game.libraryPath,
versionIdentifier.identifier,
);
} else if (versionIdentifier.type === "depot") {
const unimported = await prisma.unimportedGameVersion.findUnique({
where: {
id: versionIdentifier.identifier,
},
select: {
fileList: true,
},
});
if (!unimported) return undefined;
files = unimported.fileList;
} else {
return undefined;
}
const files = await library.versionReaddir(game.libraryPath, versionName);
for (const filename of files) { for (const filename of files) {
const basename = path.basename(filename); const basename = path.basename(filename);
const dotLocation = filename.lastIndexOf("."); const dotLocation = filename.lastIndexOf(".");
@@ -213,12 +318,32 @@ class LibraryManager {
if (checkExt != ext) continue; if (checkExt != ext) continue;
const fuzzyValue = fuzzy(basename, game.mName); const fuzzyValue = fuzzy(basename, game.mName);
options.push({ options.push({
type: "platform",
filename: filename.replaceAll(" ", "\\ "), filename: filename.replaceAll(" ", "\\ "),
platform, platform: platform as Platform,
match: fuzzyValue, match: fuzzyValue,
}); });
} }
} }
for (const executorSuggestion of executorSuggestions) {
for (const suggestion of executorSuggestion.executorSuggestions) {
if (suggestion != ext) continue;
const fuzzyValue = fuzzy(basename, game.mName);
options.push({
type: "executor",
filename: filename.replaceAll(" ", "\\ "),
match: fuzzyValue,
executorId: executorSuggestion.launchId,
icon: executorSuggestion.gameVersion.game.mIconObjectId,
gameName: executorSuggestion.gameVersion.game.mName,
versionName: (executorSuggestion.gameVersion.displayName ??
executorSuggestion.gameVersion.versionPath)!,
launchName: executorSuggestion.name,
platform: executorSuggestion.platform,
});
}
}
} }
const sortedOptions = options.sort((a, b) => b.match - a.match); const sortedOptions = options.sort((a, b) => b.match - a.match);
@@ -247,49 +372,79 @@ class LibraryManager {
async importVersion( async importVersion(
gameId: string, gameId: string,
versionPath: string, version: UnimportedVersionInformation,
metadata: typeof ImportVersion.infer, metadata: typeof ImportVersion.infer,
) { ) {
const taskKey = createVersionImportTaskKey(gameId, versionPath); const taskKey = createVersionImportTaskKey(gameId, version.identifier);
const game = await prisma.game.findUnique({ const game = await prisma.game.findUnique({
where: { id: gameId }, where: { id: gameId },
select: { mName: true, libraryId: true, libraryPath: true }, select: { mName: true, libraryId: true, libraryPath: true, type: true },
}); });
if (!game || !game.libraryId) return undefined; if (!game || !game.libraryId) return undefined;
if (game.type === GameType.Redist && !metadata.onlySetup)
throw createError({
statusCode: 400,
message: "Redistributables can only be in setup-only mode.",
});
const library = this.libraries.get(game.libraryId); const library = this.libraries.get(game.libraryId);
if (!library) return undefined; if (!library) return undefined;
const unimportedVersion =
version.type === "depot"
? await prisma.unimportedGameVersion.findUnique({
where: { id: version.identifier },
})
: undefined;
return await taskHandler.create({ return await taskHandler.create({
key: taskKey, key: taskKey,
taskGroup: "import:game", taskGroup: "import:game",
name: `Importing version ${versionPath} for ${game.mName}`, name: `Importing version ${version.name} for ${game.mName}`,
acls: ["system:import:version:read"], acls: ["system:import:version:read"],
async run({ progress, logger }) { async run({ progress, logger }) {
// First, create the manifest via droplet. let versionPath: string | null = null;
// This takes up 90% of our progress, so we wrap it in a *0.9 let manifest;
const manifest = await library.generateDropletManifest( let fileList;
game.libraryPath,
versionPath,
(err, value) => {
if (err) throw err;
progress(value * 0.9);
},
(err, value) => {
if (err) throw err;
logger.info(value);
},
);
logger.info("Created manifest successfully!"); if (version.type === "local") {
versionPath = version.identifier;
// First, create the manifest via droplet.
// This takes up 90% of our progress, so we wrap it in a *0.9
manifest = await library.generateDropletManifest(
game.libraryPath,
versionPath,
(err, value) => {
if (err) throw err;
progress(value * 0.9);
},
(err, value) => {
if (err) throw err;
logger.info(value);
},
);
fileList = await library.versionReaddir(
game.libraryPath,
versionPath,
);
logger.info("Created manifest successfully!");
} else if (version.type === "depot" && unimportedVersion) {
manifest = castManifest(unimportedVersion.manifest);
fileList = unimportedVersion.fileList;
progress(90);
} else {
throw "Could not find or create manifest for this version.";
}
const currentIndex = await prisma.gameVersion.count({ const currentIndex = await prisma.gameVersion.count({
where: { gameId: gameId }, where: { gameId: gameId },
}); });
// Then, create the database object // Then, create the database object
await prisma.gameVersion.create({ const newVersion = await prisma.gameVersion.create({
data: { data: {
game: { game: {
connect: { connect: {
@@ -301,6 +456,7 @@ class LibraryManager {
versionPath, versionPath,
dropletManifest: manifest, dropletManifest: manifest,
fileList,
versionIndex: currentIndex, versionIndex: currentIndex,
delta: metadata.delta, delta: metadata.delta,
@@ -321,9 +477,13 @@ class LibraryManager {
name: v.name, name: v.name,
command: v.launch, command: v.launch,
platform: v.platform, platform: v.platform,
...(v.executorId ...(v.executorId && game.type === "Game"
? { executorId: v.executorId } ? {
executorId: v.executorId,
}
: undefined), : undefined),
executorSuggestions:
game.type === "Executor" ? (v.suggestions ?? []) : [],
})), })),
} }
: { data: [] }, : { data: [] },
@@ -333,17 +493,30 @@ class LibraryManager {
logger.info("Successfully created version!"); logger.info("Successfully created version!");
notificationSystem.systemPush({ notificationSystem.systemPush({
nonce: `version-create-${gameId}-${versionPath}`, nonce: `version-create-${gameId}-${version}`,
title: `'${game.mName}' ('${versionPath}') finished importing.`, title: `'${game.mName}' ('${version}') finished importing.`,
description: `Drop finished importing version ${versionPath} for ${game.mName}.`, description: `Drop finished importing version ${version} for ${game.mName}.`,
actions: [`View|/admin/library/${gameId}`], actions: [`View|/admin/library/${gameId}`],
acls: ["system:import:version:read"], acls: ["system:import:version:read"],
}); });
await libraryManager.cacheCombinedGameSize(gameId); await libraryManager.cacheCombinedGameSize(gameId);
await libraryManager.cacheGameVersionSize(gameId, versionPath); await libraryManager.cacheGameVersionSize(gameId, newVersion.versionId);
await TORRENTIAL_SERVICE.utils().invalidate(gameId, versionPath); await TORRENTIAL_SERVICE.utils().invalidate(
gameId,
newVersion.versionId,
);
if (version.type === "depot") {
// SAFETY: we can only reach this if the type is depot and identifier is valid
// eslint-disable-next-line drop/no-prisma-delete
await prisma.unimportedGameVersion.delete({
where: {
id: version.identifier,
},
});
}
progress(100); progress(100);
}, },
}); });
@@ -390,6 +563,20 @@ class LibraryManager {
}, },
}); });
await gameSizeManager.deleteGame(gameId); await gameSizeManager.deleteGame(gameId);
// Delete all game versions that depended on this game
await prisma.gameVersion.deleteMany({
where: {
launches: {
some: {
executor: {
gameVersion: {
gameId,
},
},
},
},
},
});
} }
async getGameVersionSize( async getGameVersionSize(
@@ -421,7 +608,7 @@ class LibraryManager {
await gameSizeManager.cacheCombinedGame(game); await gameSizeManager.cacheCombinedGame(game);
} }
async cacheGameVersionSize(gameId: string, versionName: string) { async cacheGameVersionSize(gameId: string, versionId: string) {
const game = await prisma.game.findFirst({ const game = await prisma.game.findFirst({
where: { id: gameId }, where: { id: gameId },
include: { versions: true }, include: { versions: true },
@@ -429,7 +616,7 @@ class LibraryManager {
if (!game) { if (!game) {
return; return;
} }
await gameSizeManager.cacheGameVersion(game, versionName); await gameSizeManager.cacheGameVersion(game, versionId);
} }
} }

View File

@@ -1,12 +1,12 @@
import type { JsonValue } from "@prisma/client/runtime/library"; import type { JsonValue } from "@prisma/client/runtime/library";
export type Manifest = V2Manifest; export type DropletManifest = V2Manifest;
export type V2Manifest = { export type V2Manifest = {
version: "2"; version: "2";
size: number; size: number;
key: number[]; key: number[];
chunks: { [key: string]: V2ChunkData[] }; chunks: { [key: string]: V2ChunkData };
}; };
export type V2ChunkData = { export type V2ChunkData = {
@@ -22,6 +22,6 @@ export type V2FileEntry = {
permissions: number; permissions: number;
}; };
export function castManifest(manifest: JsonValue): Manifest { export function castManifest(manifest: JsonValue): DropletManifest {
return JSON.parse(manifest as string) as Manifest; return JSON.parse(manifest as string) as DropletManifest;
} }

View File

@@ -0,0 +1,100 @@
import prisma from "../../db/database";
import { castManifest, type DropletManifest } from "../manifest";
export type DownloadManifestDetails = {
manifests: { [key: string]: DropletManifest };
fileList: { [key: string]: string };
};
function convertMap<T>(map: Map<string, T>): { [key: string]: T } {
return Object.fromEntries(map.entries().toArray());
}
/**
*
* @param gameId Game ID
* @param versionId Version ID
*/
export async function createDownloadManifestDetails(
versionId: string,
): Promise<DownloadManifestDetails> {
const mainVersion = await prisma.gameVersion.findUnique({
where: { versionId },
select: {
versionId: true,
delta: true,
versionIndex: true,
fileList: true,
negativeFileList: true,
gameId: true,
dropletManifest: true,
},
});
if (!mainVersion)
throw createError({ statusCode: 404, message: "Version not found" });
const collectedVersions = [];
let versionIndex = mainVersion.versionIndex;
while (true) {
const nextVersion = await prisma.gameVersion.findFirst({
where: { gameId: mainVersion.gameId, versionIndex: { lt: versionIndex } },
orderBy: {
versionIndex: "desc",
},
select: {
versionId: true,
versionIndex: true,
delta: true,
fileList: true,
negativeFileList: true,
dropletManifest: true,
},
});
if (!nextVersion)
throw createError({
statusCode: 500,
message: "Delta version without version underneath it.",
});
versionIndex = nextVersion.versionIndex;
collectedVersions.push(nextVersion);
if (!nextVersion.delta) break;
}
collectedVersions.reverse();
// Apply fileList in lowest priority to newest priority
const versionOrder = [...collectedVersions, mainVersion];
const fileList = new Map<string, string>();
for (const version of versionOrder) {
for (const file of version.fileList) {
fileList.set(file, version.versionId);
}
for (const negFile of version.negativeFileList) {
fileList.delete(negFile);
}
}
// Now that we have our file list, filter the manifests
const manifests = new Map<string, DropletManifest>();
for (const version of versionOrder) {
const files = fileList
.entries()
.filter(([, versionId]) => version.versionId === versionId)
.toArray();
if (files.length == 0) continue;
const fileNames = Object.fromEntries(files);
const manifest = castManifest(version.dropletManifest);
const filteredChunks = Object.fromEntries(
Object.entries(manifest.chunks).filter(([, chunkData]) =>
chunkData.files.some((fileEntry) => !!fileNames[fileEntry.filename]),
),
);
manifests.set(version.versionId, {
...manifest,
chunks: filteredChunks,
});
}
return { fileList: convertMap(fileList), manifests: convertMap(manifests) };
}

View File

@@ -1,4 +1,5 @@
import type { Prisma } from "~/prisma/client/client"; import type { Prisma } from "~/prisma/client/client";
import type { GameType } from "~/prisma/client/enums";
import { MetadataSource } from "~/prisma/client/enums"; import { MetadataSource } from "~/prisma/client/enums";
import prisma from "../db/database"; import prisma from "../db/database";
import type { import type {
@@ -118,7 +119,11 @@ export class MetadataHandler {
return successfulResults; return successfulResults;
} }
async createGameWithoutMetadata(libraryId: string, libraryPath: string) { async createGameWithoutMetadata(
libraryId: string,
libraryPath: string,
type: GameType,
) {
return await this.createGame( return await this.createGame(
{ {
id: "", id: "",
@@ -127,6 +132,7 @@ export class MetadataHandler {
}, },
libraryId, libraryId,
libraryPath, libraryPath,
type,
); );
} }
@@ -174,6 +180,7 @@ export class MetadataHandler {
result: { sourceId: string; id: string; name: string }, result: { sourceId: string; id: string; name: string },
libraryId: string, libraryId: string,
libraryPath: string, libraryPath: string,
type: GameType,
) { ) {
const provider = this.providers.get(result.sourceId); const provider = this.providers.get(result.sourceId);
if (!provider) if (!provider)
@@ -286,6 +293,8 @@ export class MetadataHandler {
libraryId, libraryId,
libraryPath, libraryPath,
type,
}, },
}); });

View File

@@ -7,6 +7,33 @@ export type SystemData = {
cpuCores: number; cpuCores: number;
}; };
// See https://github.com/oscmejia/os-utils/blob/master/lib/osutils.js
function getCPUInfo() {
const cpus = os.cpus();
let user = 0;
let nice = 0;
let sys = 0;
let idle = 0;
let irq = 0;
for (const cpu in cpus) {
if (!Object.prototype.hasOwnProperty.call(cpus, cpu)) continue;
user += cpus[cpu].times.user;
nice += cpus[cpu].times.nice;
sys += cpus[cpu].times.sys;
irq += cpus[cpu].times.irq;
idle += cpus[cpu].times.idle;
}
const total = user + nice + sys + idle + irq;
return {
idle: idle,
total: total,
};
}
class SystemManager { class SystemManager {
// userId to acl to listenerId // userId to acl to listenerId
private listeners = new Map< private listeners = new Map<
@@ -14,6 +41,20 @@ class SystemManager {
Map<string, { callback: (systemData: SystemData) => void }> Map<string, { callback: (systemData: SystemData) => void }>
>(); >();
private lastCPUUpdate: { idle: number; total: number } | undefined;
constructor() {
setInterval(() => {
const systemData = this.getSystemData();
if (!systemData) return;
for (const [, map] of this.listeners.entries()) {
for (const [, { callback }] of map.entries()) {
callback(systemData);
}
}
}, 3000);
}
listen( listen(
userId: string, userId: string,
id: string, id: string,
@@ -22,25 +63,17 @@ class SystemManager {
if (!this.listeners.has(userId)) this.listeners.set(userId, new Map()); if (!this.listeners.has(userId)) this.listeners.set(userId, new Map());
// eslint-disable-next-line @typescript-eslint/no-extra-non-null-assertion // eslint-disable-next-line @typescript-eslint/no-extra-non-null-assertion
this.listeners.get(userId)!!.set(id, { callback }); this.listeners.get(userId)!!.set(id, { callback });
this.pushUpdate(userId, id);
setInterval(() => this.pushUpdate(userId, id), 3000);
} }
unlisten(userId: string, id: string) { unlisten(userId: string, id: string) {
this.listeners.get(userId)?.delete(id); this.listeners.get(userId)?.delete(id);
} }
private async pushUpdate(userId: string, id: string) { getSystemData(): SystemData | undefined {
const listener = this.listeners.get(userId)?.get(id); const cpu = this.cpuLoad();
if (!listener) { if (!cpu) return undefined;
throw new Error("Failed to catch-up listener: callback does not exist");
}
listener.callback(this.getSystemData());
}
getSystemData(): SystemData {
return { return {
cpuLoad: this.cpuLoad(), cpuLoad: cpu * 100,
totalRam: os.totalmem(), totalRam: os.totalmem(),
freeRam: os.freemem(), freeRam: os.freemem(),
cpuCores: os.cpus().length, cpuCores: os.cpus().length,
@@ -48,9 +81,15 @@ class SystemManager {
} }
private cpuLoad() { private cpuLoad() {
const [oneMinLoad, _fiveMinLoad, _fiftenMinLoad] = os.loadavg(); const last = this.lastCPUUpdate;
const numberCpus = os.cpus().length; this.lastCPUUpdate = getCPUInfo();
return 100 - ((numberCpus - oneMinLoad) / numberCpus) * 100; if (!last) return undefined;
const idle = this.lastCPUUpdate.idle - last.idle;
const total = this.lastCPUUpdate.total - last.total;
const perc = idle / total;
return 1 - perc;
} }
} }