Paginated admin library & upgrade manifests (#351)

* feat: new page layout + endpoint

* feat: non-parallel mass import

* feat: paginated admin library

* feat: lint and performance improvement

* feat: library filter util

* feat: link frontend features to backend

* fix: lint

* fix: small fixes

* feat: bump torrential

* fix: lint
This commit is contained in:
DecDuck
2026-02-25 02:17:33 +11:00
committed by GitHub
parent 3375e8c972
commit 7dc889852d
35 changed files with 1823 additions and 416 deletions
+2 -6
View File
@@ -4,11 +4,7 @@
"strings": "on"
},
"i18n-ally.extract.autoDetect": true,
"i18n-ally.extract.ignored": [
"string >= 14",
"string.alphanumeric >= 5",
"/api/v1/admin/import/version/preload?id=${encodeURIComponent(\n gameId,\n )}&version=${encodeURIComponent(version)}"
],
"i18n-ally.extract.ignored": ["string >= 14", "string.alphanumeric >= 5"],
"i18n-ally.extract.ignoredByFiles": {
"components/NewsArticleCreateButton.vue": ["[", "`", "Enter"],
"pages/admin/library/sources/index.vue": ["Filesystem"],
@@ -19,7 +15,7 @@
"i18n-ally.localesPaths": ["i18n", "i18n/locales"],
// i18n Ally settings
"i18n-ally.sortKeys": true,
"prisma.pinToPrisma6": true,
"prisma.pinToPrisma6": false,
"spellchecker.ignoreWordsList": ["mTLS", "Wireguard"],
"sqltools.connections": [
{
+10
View File
@@ -46,6 +46,12 @@
>
{{ $t("library.admin.version.table.path") }}
</th>
<th
scope="col"
class="px-3 py-3 text-left text-xs font-medium tracking-wide text-gray-400 uppercase"
>
{{ $t("library.admin.version.table.delta") }}
</th>
<th
scope="col"
class="px-3 py-3 text-left text-xs font-medium tracking-wide text-gray-400 uppercase"
@@ -91,6 +97,10 @@
<td class="px-3 py-4 text-sm whitespace-nowrap text-gray-400">
{{ version.versionPath }}
</td>
<td class="px-3 py-4 text-sm whitespace-nowrap text-gray-400">
{{ version.delta }}
</td>
<td class="px-3 py-4 text-sm whitespace-nowrap text-gray-400">
<ul class="space-y-2">
<GameEditorVersionConfig
+3 -4
View File
@@ -1,6 +1,6 @@
<template>
<span class="text-xs font-mono text-zinc-400 inline-flex items-top gap-x-2"
><span v-if="!short" class="text-zinc-500">{{ log.timestamp }}</span>
><span v-if="!short" class="text-zinc-500">{{ log.time }}</span>
<span
:class="[
colours[log.level] || 'text-green-400',
@@ -8,9 +8,8 @@
]"
>{{ log.level }}</span
>
<pre :class="[short ? 'line-clamp-1' : '', 'mt-[1px]']">{{
log.message
}}</pre>
<span v-if="log.prefix" class="text-zinc-200"> {{ log.prefix }}</span>
<pre :class="[short ? 'line-clamp-1' : '', 'mt-[1px]']">{{ log.msg }}</pre>
</span>
</template>
+1 -1
View File
@@ -13,7 +13,7 @@
class="absolute inset-0 flex items-center justify-center text-blue-200 text-sm font-bold font-display"
>
<!-- {{ $t("tasks.admin.progress", [Math.round(percentage * 10) / 10]) }} -->
{{ $n(Math.round(percentage) / 100, "percent") }}
{{ $n(Math.round(percentage * 100) / 10000, "percent") }}
</span>
</div>
</template>
+23
View File
@@ -452,6 +452,7 @@
},
"libraryHint": "No libraries configured.",
"libraryHintDocsLink": "What does this mean? {arrow}",
"massImportTool": "Mass Import Tool",
"metadata": {
"companies": {
"action": "Manage {arrow}",
@@ -507,6 +508,27 @@
}
},
"metadataProvider": "Metadata provider",
"nav": {
"backPagination": "Previous",
"clearAllFilters": "Clear all",
"filterCount": "{0} filters",
"filterLabel": "Filters",
"filters": {
"metadata": {
"emptyDescription": "Empty description",
"featured": "Featured",
"noCarousel": "No images in carousel",
"title": "Metadata"
},
"version": {
"available": "Available to import",
"none": "No versions imported",
"title": "Versions"
}
},
"nextPagination": "Next",
"sortLabel": "Sort"
},
"noGames": "No games imported",
"offline": "Drop couldn't access this game.",
"offlineTitle": "Game offline",
@@ -544,6 +566,7 @@
"noVersions": "You have no versions of this game available.",
"setupOnly": "Version configured as in setup-only mode.",
"table": {
"delta": "Update mode",
"launch": "Launch Configurations",
"name": "Name (ID)",
"path": "Path",
+3
View File
@@ -41,6 +41,7 @@
"cbor2": "^2.0.1",
"cheerio": "^1.0.0",
"cookie-es": "^2.0.0",
"deepmerge": "^4.3.1",
"dotenv": "^17.2.3",
"fast-fuzzy": "^1.12.0",
"file-type-mime": "^0.4.3",
@@ -73,6 +74,7 @@
"devDependencies": {
"@bufbuild/buf": "^1.65.0",
"@bufbuild/protoc-gen-es": "^2.11.0",
"@golar/vue": "^0.0.13",
"@intlify/eslint-plugin-vue-i18n": "^4.0.1",
"@nuxt/eslint": "^1.3.0",
"@tailwindcss/forms": "^0.5.9",
@@ -86,6 +88,7 @@
"autoprefixer": "^10.4.20",
"eslint": "^9.24.0",
"eslint-config-prettier": "^10.1.1",
"golar": "^0.0.13",
"h3": "^1.15.5",
"nitropack": "^2.11.12",
"ofetch": "^1.4.1",
+1 -1
View File
@@ -93,7 +93,7 @@
<NuxtLink
:href="`/store/${game.id}`"
type="button"
class="whitespace-nowrap inline-flex w-fit items-center gap-x-2 rounded-md bg-zinc-800 px-3 py-1 text-sm font-semibold font-display text-white shadow-sm hover:bg-zinc-700 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-600"
class="whitespace-nowrap inline-flex w-fit items-center gap-x-2 rounded-md bg-zinc-800 px-3 py-1 text-sm font-semibold font-display text-white shadow-sm hover:bg-zinc-700 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-600"
>
{{ $t("library.admin.openStore") }}
<ArrowTopRightOnSquareIcon
+6
View File
@@ -344,6 +344,7 @@ import {
import { XCircleIcon } from "@heroicons/vue/16/solid";
import { CheckIcon, ChevronUpDownIcon } from "@heroicons/vue/20/solid";
import { MagnifyingGlassIcon } from "@heroicons/vue/24/outline";
import { FetchError } from "ofetch";
import type { GameType } from "~/prisma/client/enums";
import type { GameMetadataSearchResult } from "~/server/internal/metadata/types";
@@ -406,6 +407,11 @@ async function searchGame() {
gameSearchLoading.value = false;
} catch (e) {
gameSearchLoading.value = false;
if (e instanceof FetchError) {
gameSearchResultsError.value = e.data?.message ?? t("errors.unknown");
} else {
gameSearchResultsError.value = (e as string)?.toString();
}
throw e;
}
+453 -52
View File
@@ -12,7 +12,7 @@
<div class="mt-4 sm:ml-16 sm:mt-0 sm:flex-none">
<NuxtLink
to="/admin/library/sources"
class="block rounded-md bg-blue-600 px-3 py-2 text-center text-sm font-semibold text-white shadow-sm transition-all duration-200 hover:bg-blue-500 hover:scale-105 hover:shadow-lg hover:shadow-blue-500/25 active:scale-95 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-600"
class="block rounded-md bg-blue-600 px-3 py-2 text-center text-sm font-semibold text-white shadow-sm transition-all duration-200 hover:bg-blue-500 hover:scale-105 hover:shadow-lg hover:shadow-blue-500/25 active:scale-95 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-600"
>
<i18n-t
keypath="library.admin.sources.link"
@@ -26,7 +26,40 @@
</NuxtLink>
</div>
</div>
<div v-if="toImport" class="rounded-md bg-blue-600/10 p-4">
<div class="flex flex-row justify-between gap-x-5">
<div v-if="toImport" class="rounded-md bg-zinc-600/10 p-3">
<div class="flex">
<div class="flex-shrink-0">
<WrenchScrewdriverIcon
class="h-5 w-5 text-zinc-400"
aria-hidden="true"
/>
</div>
<div class="ml-3 flex-1 md:flex md:justify-between">
<p class="text-sm text-zinc-400">
{{ $t("library.admin.massImportTool") }}
</p>
<p class="mt-3 text-sm md:ml-6 md:mt-0">
<NuxtLink
href="/admin/library/mass-import"
class="whitespace-nowrap font-medium text-zinc-400 hover:text-zinc-500"
>
<i18n-t
keypath="library.admin.import.link"
tag="span"
scope="global"
>
<template #arrow>
<span aria-hidden="true">{{ $t("chars.arrow") }}</span>
</template>
</i18n-t>
</NuxtLink>
</p>
</div>
</div>
</div>
<div v-if="toImport" class="rounded-md bg-blue-600/10 p-3">
<div class="flex">
<div class="flex-shrink-0">
<InformationCircleIcon
@@ -57,13 +90,104 @@
</div>
</div>
</div>
<div class="mt-2 grid grid-cols-1">
</div>
<!-- Search & filter -->
<Disclosure
as="section"
aria-labelledby="filter-heading"
class="mt-2 relative flex items-center border-y border-zinc-800 gap-x-4"
>
<h2 id="filter-heading" class="sr-only">
{{ $t("library.admin.nav.filterLabel") }}
</h2>
<div class="relative col-start-1 row-start-1 py-4">
<div class="mx-auto flex max-w-7xl divide-x divide-zinc-700 text-sm">
<div class="pr-6">
<DisclosureButton
class="group flex items-center font-medium text-zinc-400"
>
<FunnelIcon
class="mr-2 size-5 flex-none text-gray-400 group-hover:text-gray-500"
aria-hidden="true"
/>
{{
$t("library.admin.nav.filterCount", [
Object.values(currentFilters).filter((v) => v).length,
])
}}
</DisclosureButton>
</div>
<div class="pl-6">
<button type="button" class="text-zinc-400">
{{ $t("library.admin.nav.clearAllFilters") }}
</button>
</div>
</div>
</div>
<DisclosurePanel
class="absolute bottom-0 translate-y-full left-0 border border-zinc-800 py-4 bg-zinc-900 rounded-b-xl z-10 shadow"
>
<div
class="flex flex-wrap flex-col lg:flex-row max-w-7xl text-sm px-4 gap-4"
>
<fieldset v-for="filter in filterScaffold" :key="filter.value">
<legend class="block font-medium text-zinc-100">
{{ filter.title }}
</legend>
<div class="space-y-6 sm:space-y-4 pt-2">
<div
v-for="option in filter.values"
:key="option.value"
class="flex gap-3"
>
<div class="flex h-5 shrink-0 items-center">
<div class="group grid size-4 grid-cols-1">
<input
:id="createFilterKey(filter, option)"
v-model="currentFilters[createFilterKey(filter, option)]"
:value="createFilterKey(filter, option)"
type="checkbox"
class="col-start-1 row-start-1 appearance-none rounded-sm border border-zinc-700 bg-zinc-950 checked:border-blue-600 checked:bg-blue-600 indeterminate:border-blue-600 indeterminate:bg-blue-600 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-600 disabled:border-gray-300 disabled:bg-gray-100 disabled:checked:bg-gray-100 forced-colors:appearance-auto"
/>
<svg
class="pointer-events-none col-start-1 row-start-1 size-3.5 self-center justify-self-center stroke-white group-has-disabled:stroke-gray-950/25"
viewBox="0 0 14 14"
fill="none"
>
<path
class="opacity-0 group-has-checked:opacity-100"
d="M3 8L6 11L11 3.5"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
/>
<path
class="opacity-0 group-has-indeterminate:opacity-100"
d="M3 7H11"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
/>
</svg>
</div>
</div>
<label
:for="createFilterKey(filter, option)"
class="text-base text-zinc-300 sm:text-sm"
>{{ option.label }}</label
>
</div>
</div>
</fieldset>
</div>
</DisclosurePanel>
<div class="grow grid grid-cols-1">
<input
id="search"
v-model="searchQuery"
type="text"
name="search"
class="col-start-1 row-start-1 block w-full rounded-md bg-zinc-900 py-1.5 pl-10 pr-3 text-base text-zinc-100 outline outline-1 -outline-offset-1 outline-zinc-700 placeholder:text-gray-400 focus:outline focus:outline-2 focus:-outline-offset-2 focus:outline-blue-600 sm:pl-9 sm:text-sm/6"
class="col-start-1 row-start-1 block w-full rounded-md bg-zinc-900 py-1.5 pl-10 pr-3 text-base text-zinc-100 border-[0px] outline-[0px] placeholder:text-zinc-400 sm:pl-9 sm:text-sm/6"
:placeholder="$t('library.search')"
/>
<MagnifyingGlassIcon
@@ -71,12 +195,71 @@
aria-hidden="true"
/>
</div>
<div class="col-start-1 row-start-1 py-4">
<div class="mx-auto flex max-w-7xl justify-end px-2">
<Menu as="div" class="relative inline-block text-left">
<div>
<MenuButton
class="group inline-flex justify-center text-sm font-medium text-zinc-400 hover:text-zinc-100"
>
{{ $t("store.view.sort") }}
<ChevronDownIcon
class="-mr-1 ml-1 size-5 shrink-0 text-gray-400 group-hover:text-zinc-100"
aria-hidden="true"
/>
</MenuButton>
</div>
<transition
enter-active-class="transition ease-out duration-100"
enter-from-class="transform opacity-0 scale-95"
enter-to-class="transform opacity-100 scale-100"
leave-active-class="transition ease-in duration-75"
leave-from-class="transform opacity-100 scale-100"
leave-to-class="transform opacity-0 scale-95"
>
<MenuItems
class="absolute right-0 z-10 mt-2 w-40 origin-top-right rounded-md bg-zinc-950 shadow-2xl ring-1 ring-white/5 focus:outline-hidden"
>
<div class="py-1">
<MenuItem
v-for="option in sorts"
:key="option.param"
v-slot="{ active }"
>
<button
:class="[
currentSort == option.param
? 'font-medium text-zinc-100'
: 'text-zinc-400',
active ? 'bg-zinc-900 outline-hidden' : '',
'w-full text-left block px-4 py-2 text-sm',
]"
@click.prevent="handleSortClick(option, $event)"
>
{{ option.name }}
<span v-if="currentSort === option.param">
{{
sortOrder === "asc"
? $t("chars.arrowUp")
: $t("chars.arrowDown")
}}
</span>
</button>
</MenuItem>
</div>
</MenuItems>
</transition>
</Menu>
</div>
</div>
</Disclosure>
<ul
role="list"
class="grid grid-cols-1 gap-6 sm:grid-cols-2 md:grid-cols-3 xl:grid-cols-4"
class="relative grid grid-cols-1 gap-6 sm:grid-cols-2 md:grid-cols-3 xl:grid-cols-4"
>
<li
v-for="game in filteredLibraryGames"
v-for="game in libraryGames"
:key="game.id"
class="relative overflow-hidden col-span-1 flex flex-col justify-center divide-y divide-zinc-800 rounded-xl bg-zinc-950/30 text-left shadow-md border hover:scale-102 hover:shadow-xl hover:bg-zinc-950/70 border-zinc-800 transition-all duration-200 group"
>
@@ -240,23 +423,13 @@
</div>
</li>
<p
v-if="filteredLibraryGames.length == 0 && libraryGames.length != 0"
v-if="libraryGames.length == 0 && hasLibraries"
class="text-zinc-600 text-sm font-display font-bold uppercase text-center col-span-4"
>
{{ $t("common.noResults") }}
</p>
<p
v-if="
filteredLibraryGames.length == 0 &&
libraryGames.length == 0 &&
libraryState.hasLibraries
"
class="text-zinc-600 text-sm font-display font-bold uppercase text-center col-span-4"
>
{{ $t("library.admin.noGames") }}
</p>
<p
v-else-if="!libraryState.hasLibraries"
v-else-if="!hasLibraries"
class="flex flex-col gap-2 text-zinc-600 text-center col-span-4"
>
<span class="text-sm font-display font-bold uppercase">{{
@@ -280,7 +453,77 @@
</i18n-t>
</NuxtLink>
</p>
<div
v-if="gamesLoading"
class="absolute inset-0 bg-zinc-900/50 flex items-start p-4 justify-center"
>
<div role="status">
<svg
aria-hidden="true"
class="size-8 text-transparent animate-spin fill-white"
viewBox="0 0 100 101"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z"
fill="currentColor"
/>
<path
d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z"
fill="currentFill"
/>
</svg>
<span class="sr-only">{{ $t("common.srLoading") }}</span>
</div>
</div>
</ul>
<nav
class="flex items-center justify-between border-t border-white/10 px-4 sm:px-0"
>
<div class="-mt-px flex w-0 flex-1">
<button
class="group inline-flex items-center border-t-2 border-transparent pt-4 pr-1 text-sm font-medium text-zinc-400 disabled:text-zinc-700 hover:not-disabled:border-white/20 hover:not-disabled:text-zinc-200"
:disabled="currentIndex == 0"
@click="previousPage"
>
<ArrowLongLeftIcon
class="mr-3 size-5 text-zinc-500 group-disabled:text-zinc-700"
aria-hidden="true"
/>
{{ $t("library.admin.nav.backPagination") }}
</button>
</div>
<div class="hidden md:-mt-px md:flex">
<button
v-for="page in maxPages"
:key="page"
:class="[
currentIndex == page - 1
? 'border-blue-400 text-blue-400'
: 'border-transparent hover:not-disabled:text-zinc-white/20 text-zinc-400 hover:not-disabled:border-white/20',
'transition inline-flex items-center border-t-2 px-4 pt-4 text-sm font-medium',
]"
@click="currentIndex = page - 1"
>
{{ page }}
</button>
</div>
<div class="-mt-px flex w-0 flex-1 justify-end">
<button
class="group inline-flex items-center border-t-2 border-transparent pt-4 pl-1 text-sm font-medium text-zinc-400 disabled:text-zinc-700 hover:not-disabled:border-white/20 hover:not-disabled:text-zinc-200"
:disabled="currentIndex == maxPages - 1"
@click="nextPage"
>
{{ $t("library.admin.nav.nextPagination") }}
<ArrowLongRightIcon
class="ml-3 size-5 text-zinc-500 group-disabled:text-zinc-700"
aria-hidden="true"
/>
</button>
</div>
</nav>
</div>
</template>
@@ -293,8 +536,23 @@ import {
ArrowTopRightOnSquareIcon,
InformationCircleIcon,
StarIcon,
WrenchScrewdriverIcon,
ArrowLongLeftIcon,
ArrowLongRightIcon,
ChevronDownIcon,
FunnelIcon,
} from "@heroicons/vue/20/solid";
import { MagnifyingGlassIcon } from "@heroicons/vue/24/outline";
import type { AdminLibraryGame } from "~/server/api/v1/admin/library/index.get";
import {
Disclosure,
DisclosureButton,
DisclosurePanel,
Menu,
MenuButton,
MenuItem,
MenuItems,
} from "@headlessui/vue";
const { t } = useI18n();
@@ -306,33 +564,46 @@ useHead({
title: t("library.admin.title"),
});
const searchQuery = ref("");
const libraryState = await $dropFetch("/api/v1/admin/library");
type LibraryStateGame = (typeof libraryState.games)[number]["game"];
const toImport = ref(
Object.values(libraryState.unimportedGames).flat().length > 0,
const { unimportedGames, hasLibraries } = await $dropFetch(
"/api/v1/admin/library/libraries",
);
const libraryGames = ref<
Array<
LibraryStateGame & {
status: "online" | "offline";
hasNotifications?: boolean;
notifications: {
noVersions?: boolean;
toImport?: boolean;
offline?: boolean;
};
const route = useRoute();
const router = useRouter();
// Hard limit on server
const pageSize = 24;
const currentIndex = ref(
route.query.page ? parseInt(route.query.page.toString()) - 1 : 0,
);
const maxIndex = ref(0);
const maxPages = computed(() => Math.ceil(maxIndex.value / pageSize));
const games = ref<AdminLibraryGame[]>([]);
const gamesLoading = ref(false);
const searchQuery = ref("");
function nextPage() {
if (currentIndex.value < maxPages.value - 1) {
currentIndex.value++;
}
>
>(
libraryState.games.map((e) => {
}
function previousPage() {
if (currentIndex.value > 0) {
currentIndex.value--;
}
}
const toImport = ref(Object.values(unimportedGames).flat().length > 0);
const libraryGames = computed(() =>
games.value.map((e) => {
if (e.status == "offline") {
return {
...e.game,
status: "offline" as const,
status: "offline",
hasNotifications: true,
notifications: {
offline: true,
@@ -355,19 +626,6 @@ const libraryGames = ref<
}),
);
const filteredLibraryGames = computed(() =>
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore excessively deep ts
libraryGames.value.filter((e) => {
if (!searchQuery.value) return true;
const searchQueryLower = searchQuery.value.toLowerCase();
if (e.mName.toLowerCase().includes(searchQueryLower)) return true;
if (e.mShortDescription.toLowerCase().includes(searchQueryLower))
return true;
return false;
}),
);
async function deleteGame(id: string) {
await $dropFetch(`/api/v1/admin/game/${id}`, {
method: "DELETE",
@@ -396,4 +654,147 @@ async function featureGame(id: string) {
libraryGames.value[gameIndex].featured = !game.featured;
gameFeatureLoading.value[game.id] = false;
}
const currentFilters = ref<{ [key: string]: boolean }>({});
function createFilterKey(
filter: { value: string },
subfilter: { value: string },
) {
return `${filter.value}.${subfilter.value}`;
}
const filters = computed(
() =>
({
version: [
{
value: "none",
label: t("library.admin.nav.filters.version.none"),
},
/*{
value: "available",
label: t("library.admin.nav.filters.version.available"),
},*/
],
metadata: [
{
value: "featured",
label: t("library.admin.nav.filters.metadata.featured"),
},
{
value: "noCarousel",
label: t("library.admin.nav.filters.metadata.noCarousel"),
},
{
value: "emptyDescription",
label: t("library.admin.nav.filters.metadata.emptyDescription"),
},
],
}) as const,
);
const filterScaffold = computed(
() =>
({
version: {
title: t("library.admin.nav.filters.version.title"),
value: "version",
// eslint-disable-next-line @typescript-eslint/no-explicit-any
values: filters.value.version as any,
},
metadata: {
title: t("library.admin.nav.filters.metadata.title"),
value: "metadata",
// eslint-disable-next-line @typescript-eslint/no-explicit-any
values: filters.value.metadata as any,
},
}) satisfies {
[key in keyof typeof filters.value]: {
title: string;
value: string;
values: Array<{ value: string; label: string }>;
};
},
);
const sorts: Array<StoreSortOption> = [
{
name: "Default",
param: "default",
},
{
name: "Newest",
param: "newest",
},
{
name: "Recently Added",
param: "recent",
},
{
name: "Name",
param: "name",
},
];
const currentSort = ref(sorts[0].param);
const sortOrder = ref<"asc" | "desc">("desc");
function handleSortClick(option: StoreSortOption, event: MouseEvent) {
event.stopPropagation();
if (currentSort.value === option.param) {
sortOrder.value = sortOrder.value === "asc" ? "desc" : "asc";
} else {
currentSort.value = option.param;
sortOrder.value = option.param === "name" ? "asc" : "desc";
}
}
async function fetchPage() {
gamesLoading.value = true;
const { results, count } = await $dropFetch("/api/v1/admin/library", {
query: {
skip: currentIndex.value * pageSize,
limit: pageSize,
sort: currentSort.value,
order: sortOrder.value,
filters: Object.entries(currentFilters.value)
.filter(([_, enabled]) => enabled)
.map(([name, _]) => name)
.join(","),
query: searchQuery.value ? searchQuery.value : undefined,
},
failTitle: "Failed to fetch game library",
});
maxIndex.value = count;
games.value = results;
gamesLoading.value = false;
router.push({
path: route.path,
query: {
...route.query,
page: currentIndex.value + 1,
},
});
}
function watchHandler() {
fetchPage();
document.body.scrollTop = document.documentElement.scrollTop = 0;
}
watch([currentIndex, currentSort, sortOrder], watchHandler);
watch(currentFilters, watchHandler, { deep: true });
let searchTimeout: NodeJS.Timeout | undefined;
watch(searchQuery, () => {
if (searchTimeout) clearTimeout(searchTimeout);
gamesLoading.value = true;
searchTimeout = setTimeout(() => {
watchHandler();
}, 80);
});
await fetchPage();
</script>
+363
View File
@@ -0,0 +1,363 @@
<template>
<div>
<div class="sm:flex sm:items-center">
<div class="sm:flex-auto">
<h1
class="inline-flex items-center gap-x-2 text-base font-semibold text-white"
>
<WrenchScrewdriverIcon class="size-6" /> Mass Import Tool
</h1>
<p class="mt-2 text-sm text-zinc-300">
Quickly import a large amount of versions at once.
</p>
</div>
<div class="mt-4 sm:mt-0 sm:ml-16 sm:flex-none">
<LoadingButton
:loading="false"
:disabled="!hasSelected"
@click="triggerImport"
>
Import &rarr;
</LoadingButton>
</div>
</div>
<div class="mt-8 flow-root">
<div class="-mx-4 -my-2 overflow-x-auto sm:-mx-6 lg:-mx-8">
<div class="inline-block min-w-full py-2 align-middle sm:px-6 lg:px-8">
<div class="group/table relative">
<table
class="relative min-w-full table-fixed divide-y divide-white/15"
>
<thead>
<tr>
<th scope="col" class="relative px-7 sm:w-12 sm:px-6">
<div
class="group absolute top-1/2 left-4 -mt-2 grid size-4 grid-cols-1"
>
<input
v-model="globalState"
:indeterminate="globalState === 'indeterminate'"
type="checkbox"
class="col-start-1 row-start-1 appearance-none rounded-sm border border-white/20 bg-zinc-800/50 checked:border-blue-500 checked:bg-blue-500 indeterminate:border-blue-500 indeterminate:bg-blue-500 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-500 disabled:border-white/10 disabled:bg-zinc-800 disabled:checked:bg-zinc-800 forced-colors:appearance-auto"
/>
<svg
class="pointer-events-none col-start-1 row-start-1 size-3.5 self-center justify-self-center stroke-white group-has-disabled:stroke-zinc-50/25"
viewBox="0 0 14 14"
fill="none"
>
<path
class="opacity-0 group-has-checked:opacity-100"
d="M3 8L6 11L11 3.5"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
/>
<path
class="opacity-0 group-has-indeterminate:opacity-100"
d="M3 7H11"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
/>
</svg>
</div>
</th>
<th
scope="col"
class="w-full py-3.5 pr-3 text-left text-sm font-semibold text-white whitespace-nowrap"
>
Name
</th>
<th
scope="col"
class="px-3 py-3.5 text-left text-sm font-semibold text-white whitespace-nowrap"
>
Type
</th>
<th
scope="col"
class="px-3 py-3.5 text-left text-sm font-semibold text-white whitespace-nowrap"
>
Display Name
</th>
<th
scope="col"
class="px-3 py-3.5 text-left text-sm font-semibold text-white whitespace-nowrap"
>
Setup Mode
</th>
</tr>
</thead>
<tbody class="divide-y divide-white/10 bg-zinc-900">
<template v-for="game in massImport" :key="game.id">
<tr class="text-sm/6 text-zinc-100 bg-zinc-950">
<th scope="colgroup" colspan="5" class="py-2 text-left">
<div class="inline-flex gap-x-2 px-4">
<img
:src="useObject(game.icon)"
class="size-6 rounded-sm"
/>
{{ game.name }}
</div>
</th>
</tr>
<tr
v-for="version in game.versions"
:key="version.identifier"
class="group has-checked:bg-zinc-800/50"
>
<td class="relative px-7 sm:w-12 sm:px-6">
<div
className="hidden group-has-checked:block absolute inset-y-0 left-0 w-0.5 bg-blue-500"
/>
<div
class="absolute top-1/2 left-4 -mt-2 grid size-4 grid-cols-1"
>
<input
v-model="version.enabled"
type="checkbox"
class="col-start-1 row-start-1 appearance-none rounded-sm border border-white/20 bg-zinc-800/50 checked:border-blue-500 checked:bg-blue-500 indeterminate:border-blue-500 indeterminate:bg-blue-500 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-500 disabled:border-white/10 disabled:bg-zinc-800 disabled:checked:bg-zinc-800 forced-colors:appearance-auto"
/>
<svg
class="pointer-events-none col-start-1 row-start-1 size-3.5 self-center justify-self-center stroke-white group-has-disabled:stroke-zinc-50/25"
viewBox="0 0 14 14"
fill="none"
>
<path
class="opacity-0 group-has-checked:opacity-100"
d="M3 8L6 11L11 3.5"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
/>
<path
class="opacity-0 group-has-indeterminate:opacity-100"
d="M3 7H11"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
/>
</svg>
</div>
</td>
<td
class="py-4 pr-3 text-sm font-medium whitespace-nowrap text-white group-has-checked:text-blue-400"
>
{{ version.name }}
</td>
<td
class="px-3 py-4 text-sm whitespace-nowrap text-zinc-400"
>
{{ version.type }}
</td>
<td class="px-3 text-sm whitespace-nowrap text-zinc-400">
<input
id="display-name"
v-model="version.settings.displayName"
type="text"
class="min-w-48 block w-full rounded-md border-radius-md bg-zinc-900 px-3 py-1.5 text-white outline-2 -outline-offset-1 outline-zinc-800 placeholder:text-zinc-500 focus:outline-2 focus:-outline-offset-2 focus:outline-blue-500 sm:text-sm/6"
placeholder="My New Version"
/>
</td>
<td class="px-3 text-sm whitespace-nowrap text-zinc-400">
<Switch
v-model="version.settings.setupMode"
:class="[
version.settings.setupMode
? '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
aria-hidden="true"
:class="[
version.settings.setupMode
? '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>
</td>
</tr>
</template>
</tbody>
</table>
</div>
</div>
</div>
</div>
<TransitionRoot as="template" :show="open">
<Dialog class="relative z-10" @close="open = false">
<TransitionChild
as="template"
enter="ease-out duration-300"
enter-from="opacity-0"
enter-to=""
leave="ease-in duration-200"
leave-from=""
leave-to="opacity-0"
>
<div class="fixed inset-0 bg-zinc-900/70 transition-opacity"></div>
</TransitionChild>
<div class="fixed inset-0 z-10 w-screen overflow-y-auto">
<div
class="flex min-h-full items-end justify-center p-4 text-center sm:items-center sm:p-0"
>
<TransitionChild
as="template"
enter="ease-out duration-300"
enter-from="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
enter-to=" translate-y-0 sm:scale-100"
leave="ease-in duration-200"
leave-from=" translate-y-0 sm:scale-100"
leave-to="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
>
<DialogPanel
class="relative transform overflow-hidden rounded-lg bg-zinc-900 px-4 pt-5 pb-4 text-left shadow-xl outline -outline-offset-1 outline-white/10 transition-all sm:my-8 sm:w-full sm:max-w-sm sm:p-6"
>
<div>
<div
class="mx-auto flex size-12 items-center justify-center rounded-full bg-yellow-500/10"
>
<ExclamationTriangleIcon
class="size-6 text-yellow-400"
aria-hidden="true"
/>
</div>
<div class="mt-3 text-center sm:mt-5">
<DialogTitle
as="h3"
class="text-base font-semibold text-white"
>This tool is basic.</DialogTitle
>
<div class="mt-2">
<p class="text-sm text-zinc-400">
While it is useful to import a lot of versions at once,
this tool is designed for migrating from other projects,
rather than building your Drop library from scratch.
<span class="text-sm text-zinc-100 font-bold">
It is missing functionality present in the normal
import wizard.
</span>
</p>
</div>
</div>
</div>
<div class="mt-5 sm:mt-6">
<button
type="button"
class="inline-flex w-full justify-center rounded-md bg-zinc-800 px-3 py-2 text-sm font-semibold text-white hover:bg-zinc-700 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-zinc-800"
@click="open = false"
>
Accept
</button>
</div>
</DialogPanel>
</TransitionChild>
</div>
</div>
</Dialog>
</TransitionRoot>
</div>
</template>
<script setup lang="ts">
import {
WrenchScrewdriverIcon,
ExclamationTriangleIcon,
} from "@heroicons/vue/24/outline";
import {
Switch,
Dialog,
DialogPanel,
DialogTitle,
TransitionChild,
TransitionRoot,
} from "@headlessui/vue";
definePageMeta({
layout: "admin",
});
const open = ref(true);
const raw = await $dropFetch("/api/v1/admin/import/massversion");
const massImport = ref(
raw.map((game) => ({
...game,
versions: game.versions!.map((version) => ({
...version,
enabled: true,
settings: {
displayName: undefined,
setupMode: false,
},
})),
})),
);
const hasSelected = computed(
() =>
massImport.value
.map((v) => v.versions)
.flat()
.filter((e) => e.enabled).length > 0,
);
const globalState = computed({
get() {
let lastSeen = undefined;
for (const game of massImport.value) {
for (const version of game.versions!) {
if (lastSeen === undefined) {
lastSeen = version.enabled;
continue;
}
if (lastSeen != version.enabled) return "indeterminate" as const;
}
}
return lastSeen;
},
set(v) {
if (typeof v !== "boolean") return;
for (const game of massImport.value) {
for (const version of game.versions!) {
version.enabled = v;
}
}
},
});
const router = useRouter();
async function triggerImport() {
const { taskId } = await $dropFetch("/api/v1/admin/import/massversion", {
method: "POST",
body: {
versions: massImport.value
.map((game) =>
game.versions
.filter((version) => version.enabled)
.map((version) => ({
id: game.id,
version: {
type: version.type,
identifier: version.identifier,
name: version.name,
},
...version.settings,
})),
)
.flat(),
},
});
router.push(`/admin/task/${taskId}`);
}
</script>
+1 -1
View File
@@ -40,7 +40,7 @@
</div>
</div>
</div>
<ul class="flex flex-row items-center h-12 gap-x-3">
<ul class="flex flex-row flex-wrap items-center h-12 gap-x-3">
<li
v-for="[name, link] in task.actions.map((v) => v.split(':'))"
:key="link"
+60 -4
View File
@@ -23,18 +23,69 @@
{{ $t("tasks.admin.noTasksRunning") }}
</div>
</div>
<div class="mt-6 w-full grid lg:grid-cols-2 gap-8">
<div>
<div class="mt-6 w-full grid lg:grid-cols-3 gap-8">
<div class="col-span-2">
<h2 class="text-sm font-medium text-zinc-400">
{{ $t("tasks.admin.completedTasksTitle") }}
</h2>
<ul role="list" class="mt-4 grid grid-cols-1 gap-6 lg:grid-cols-2">
<ul
role="list"
class="mt-4 grid grid-cols-1 gap-2 lg:grid-cols-4 overflow-y-scroll max-h-[80vh]"
>
<li
v-for="task in historicalTasks"
:key="task.id"
class="col-span-1 divide-y divide-gray-200 rounded-lg bg-zinc-800 border border-zinc-700 shadow-sm"
>
<TaskWidget :task="task" />
<div class="flex w-full items-center justify-between space-x-6 p-2">
<div class="flex-1 truncate">
<div class="flex items-center space-x-1">
<div>
<CheckCircleIcon
v-if="task.success"
class="size-5 text-green-600"
/>
<XMarkIcon
v-else-if="task.error"
class="size-5 text-red-600"
/>
<div
v-else
class="size-2 bg-blue-600 rounded-full animate-pulse m-1"
/>
</div>
<h3 class="truncate text-sm font-medium text-zinc-100">
{{ task.name }}
</h3>
</div>
<ul v-if="task.actions" class="mt-1 flex flex-row gap-x-2">
<NuxtLink
v-for="[name, link] in task.actions.map((v) =>
v.split(':'),
)"
:key="link"
:href="link"
class="text-xs text-zinc-100 bg-blue-900 p-1 rounded"
>{{ name }}</NuxtLink
>
</ul>
<NuxtLink
type="button"
:href="`/admin/task/${task.id}`"
class="mt-3 ml-1 rounded-md text-xs font-medium text-zinc-100 hover:text-zinc-300 focus:outline-none focus:ring-2 focus:ring-zinc-100 focus:ring-offset-2"
>
<i18n-t
keypath="tasks.admin.viewTask"
tag="span"
scope="global"
>
<template #arrow>
<span aria-hidden="true">{{ $t("chars.arrow") }}</span>
</template>
</i18n-t>
</NuxtLink>
</div>
</div>
</li>
</ul>
</div>
@@ -120,6 +171,7 @@
</div>
</template>
<script lang="ts" setup>
import { CheckCircleIcon, XMarkIcon } from "@heroicons/vue/24/solid";
import { PlayIcon } from "@heroicons/vue/24/outline";
import type { TaskGroup } from "~/server/internal/tasks/group";
@@ -163,6 +215,10 @@ const scheduledTasks: {
name: "",
description: "",
},
"import:version": {
name: "",
description: "",
},
debug: {
name: "",
description: "",
+8
View File
@@ -9,4 +9,12 @@ useHead({
const router = useRouter();
router.push("/store");
onMounted(() => {
router.push("/store");
});
definePageMeta({
redirect: "/store",
});
</script>
+1 -1
View File
@@ -284,7 +284,7 @@ const ratingArray = Array(5)
useHead({
title: game.mName,
link: [{ rel: "icon", href: useObject(game.mIconObjectId) }],
// link: [{ rel: "icon", href: useObject(game.mIconObjectId) }], // Favicon doesn't get reset when we navigate off
});
</script>
+150
View File
@@ -71,6 +71,9 @@ importers:
cookie-es:
specifier: ^2.0.0
version: 2.0.0
deepmerge:
specifier: ^4.3.1
version: 4.3.1
dotenv:
specifier: ^17.2.3
version: 17.2.3
@@ -162,6 +165,9 @@ importers:
'@bufbuild/protoc-gen-es':
specifier: ^2.11.0
version: 2.11.0(@bufbuild/protobuf@2.11.0)
'@golar/vue':
specifier: ^0.0.13
version: 0.0.13
'@intlify/eslint-plugin-vue-i18n':
specifier: ^4.0.1
version: 4.0.1(eslint@9.31.0(jiti@2.6.1))(jsonc-eslint-parser@2.4.0)(vue-eslint-parser@10.2.0(eslint@9.31.0(jiti@2.6.1)))(yaml-eslint-parser@1.3.0)
@@ -201,6 +207,9 @@ importers:
eslint-config-prettier:
specifier: ^10.1.1
version: 10.1.8(eslint@9.31.0(jiti@2.6.1))
golar:
specifier: ^0.0.13
version: 0.0.13(@golar/vue@0.0.13)
h3:
specifier: ^1.15.5
version: 1.15.5
@@ -938,6 +947,48 @@ packages:
'@fastify/busboy@3.1.1':
resolution: {integrity: sha512-5DGmA8FTdB2XbDeEwc/5ZXBl6UbBAyBOOLlPuBnZ/N1SwdH9Ii+cOX3tBROlDgcTXxjOYnLMVoKk9+FXAw0CJw==}
'@golar/darwin-arm64@0.0.13':
resolution: {integrity: sha512-4W9s7NwtH5goTb2VO/U0JraT5qtdbL7GA9p2mGWK/eMmoTyhoWXEn/ACGC3lI7w7YnzgNXupWL4jMFXFCTmLCA==}
cpu: [arm64]
os: [darwin]
'@golar/darwin-x64@0.0.13':
resolution: {integrity: sha512-HHoYeFO0nlQiYJWP7LB2qltaPoGjwlltC9YfZvww9SZRmfr2asBUKGywg57YYMN0BZCzT4kUJhQaCld0SUKI+w==}
cpu: [x64]
os: [darwin]
'@golar/linux-arm64@0.0.13':
resolution: {integrity: sha512-cyLq3PKFTU8wexkhoug2XewiHrLbCp5G6k7X8sFLUNruAAOfQdstc9vz50XUf2FUMUmMbguuuvBth+MhqdEuMg==}
cpu: [arm64]
os: [linux]
'@golar/linux-x64@0.0.13':
resolution: {integrity: sha512-9+KuD9P3pftqaXpDHZz4+XE/tJUQEZoohluvBe8aaLJpwJ6RlAMIyyumy4H23WA4JbCsDX7kshR/38JNEnjHAg==}
cpu: [x64]
os: [linux]
'@golar/plugin@0.0.13':
resolution: {integrity: sha512-QL+djNQZh8hpDnFCEt895zL46sUjD42CrBT1Lwrfypvg2pVZFd6acXHos7cfdWt6f2Yb7a+rEnmshjFuZbGcOQ==}
'@golar/util@0.0.13':
resolution: {integrity: sha512-j4UBvVrOcIRk+1ENQDJjaBJeiSVhWMPDpy+IfTB7Y66vRQgrDZ7LNPsWXooTjnWdaFrNpH9CkJB3ahFkDcfYTw==}
'@golar/volar@0.0.13':
resolution: {integrity: sha512-MoHPLt7WUuYymb+cizAGW0U3wFE8XcvQI3jpfM7fSn9reAFYEXMXFMLgGAOmnjuunRUFbw46FVqcBx5AoTNyhA==}
'@golar/vue@0.0.13':
resolution: {integrity: sha512-X84o6B1eJ6ytUbRMOugljG4VyJwXdqD1xt9S6t0YjalhbVEanW4OXq4VPrCzwqGiaTQJTBuVxPUEKq9Bojy9fw==}
'@golar/win32-arm64@0.0.13':
resolution: {integrity: sha512-aHtHHBOJSfW63oap7KQUpgkIcAOT2iZasoIYb++89iYvo57MeLANpU1sfeFl8y2M9gDlEP5KOwlaLG1FZXwaLQ==}
cpu: [arm64]
os: [win32]
'@golar/win32-x64@0.0.13':
resolution: {integrity: sha512-JXvb0Qxy/lV1PO35cxpBrlGt/wjlAmQjLHrlMn+y8AriNa34GVYXMfqQoDVlaP8F+hqI9a/PrfDePsPBHILWwg==}
cpu: [x64]
os: [win32]
'@headlessui/vue@1.7.23':
resolution: {integrity: sha512-JzdCNqurrtuu0YW6QaDtR2PIYCKPUWq28csDyMvN4zmGccmE7lz40Is6hc3LA4HFeCI7sekZ/PQMTNmn9I/4Wg==}
engines: {node: '>=10'}
@@ -2492,12 +2543,24 @@ packages:
'@volar/language-core@2.4.23':
resolution: {integrity: sha512-hEEd5ET/oSmBC6pi1j6NaNYRWoAiDhINbT8rmwtINugR39loROSlufGdYMF9TaKGfz+ViGs1Idi3mAhnuPcoGQ==}
'@volar/language-core@2.4.27':
resolution: {integrity: sha512-DjmjBWZ4tJKxfNC1F6HyYERNHPYS7L7OPFyCrestykNdUZMFYzI9WTyvwPcaNaHlrEUwESHYsfEw3isInncZxQ==}
'@volar/language-core@2.4.28':
resolution: {integrity: sha512-w4qhIJ8ZSitgLAkVay6AbcnC7gP3glYM3fYwKV3srj8m494E3xtrCv6E+bWviiK/8hs6e6t1ij1s2Endql7vzQ==}
'@volar/source-map@2.4.20':
resolution: {integrity: sha512-mVjmFQH8mC+nUaVwmbxoYUy8cww+abaO8dWzqPUjilsavjxH0jCJ3Mp8HFuHsdewZs2c+SP+EO7hCd8Z92whJg==}
'@volar/source-map@2.4.23':
resolution: {integrity: sha512-Z1Uc8IB57Lm6k7q6KIDu/p+JWtf3xsXJqAX/5r18hYOTpJyBn0KXUR8oTJ4WFYOcDzWC9n3IflGgHowx6U6z9Q==}
'@volar/source-map@2.4.27':
resolution: {integrity: sha512-ynlcBReMgOZj2i6po+qVswtDUeeBRCTgDurjMGShbm8WYZgJ0PA4RmtebBJ0BCYol1qPv3GQF6jK7C9qoVc7lg==}
'@volar/source-map@2.4.28':
resolution: {integrity: sha512-yX2BDBqJkRXfKw8my8VarTyjv48QwxdJtvRgUpNE5erCsgEUdI2DsLbpa+rOQVAJYshY99szEcRDmyHbF10ggQ==}
'@volar/typescript@2.4.20':
resolution: {integrity: sha512-Oc4DczPwQyXcVbd+5RsNEqX6ia0+w3p+klwdZQ6ZKhFjWoBP9PCPQYlKYRi/tDemWphW93P/Vv13vcE9I9D2GQ==}
@@ -2592,6 +2655,9 @@ packages:
typescript:
optional: true
'@vue/language-core@3.2.2':
resolution: {integrity: sha512-5DAuhxsxBN9kbriklh3Q5AMaJhyOCNiQJvCskN9/30XOpdLiqZU9Q+WvjArP17ubdGEyZtBzlIeG5nIjEbNOrQ==}
'@vue/reactivity@3.5.27':
resolution: {integrity: sha512-vvorxn2KXfJ0nBEnj4GYshSgsyMNFnIQah/wczXlsNXt+ijhugmW+PpJ2cNPe4V6jpnBcs0MhCODKllWG+nvoQ==}
@@ -3857,6 +3923,24 @@ packages:
resolution: {integrity: sha512-oB4vkQGqlMl682wL1IlWd02tXCbquGWM4voPEI85QmNKCaw8zGTm1f1rubFgkg3Eli2PtKlFgrnmUqasbQWlkw==}
engines: {node: '>=20'}
golar@0.0.13:
resolution: {integrity: sha512-qXAx6MJiuUVCILcwt237R1LbsnqYsgCi0LEcyvuATfKpEaanUTB7jvBlTLKqUK01SmKFd0iCsdG6d+XWPbewiw==}
hasBin: true
peerDependencies:
'@golar/astro': 0.0.13
'@golar/ember': 0.0.13
'@golar/svelte': 0.0.13
'@golar/vue': 0.0.13
peerDependenciesMeta:
'@golar/astro':
optional: true
'@golar/ember':
optional: true
'@golar/svelte':
optional: true
'@golar/vue':
optional: true
gopd@1.2.0:
resolution: {integrity: sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==}
engines: {node: '>= 0.4'}
@@ -6990,6 +7074,40 @@ snapshots:
'@fastify/busboy@3.1.1':
optional: true
'@golar/darwin-arm64@0.0.13':
optional: true
'@golar/darwin-x64@0.0.13':
optional: true
'@golar/linux-arm64@0.0.13':
optional: true
'@golar/linux-x64@0.0.13':
optional: true
'@golar/plugin@0.0.13': {}
'@golar/util@0.0.13': {}
'@golar/volar@0.0.13':
dependencies:
'@golar/plugin': 0.0.13
'@volar/language-core': 2.4.28
'@golar/vue@0.0.13':
dependencies:
'@golar/util': 0.0.13
'@golar/volar': 0.0.13
'@vue/compiler-dom': 3.5.28
'@vue/language-core': 3.2.2
'@golar/win32-arm64@0.0.13':
optional: true
'@golar/win32-x64@0.0.13':
optional: true
'@headlessui/vue@1.7.23(vue@3.5.27(typescript@5.8.3))':
dependencies:
'@tanstack/vue-virtual': 3.13.12(vue@3.5.27(typescript@5.8.3))
@@ -8765,10 +8883,22 @@ snapshots:
dependencies:
'@volar/source-map': 2.4.23
'@volar/language-core@2.4.27':
dependencies:
'@volar/source-map': 2.4.27
'@volar/language-core@2.4.28':
dependencies:
'@volar/source-map': 2.4.28
'@volar/source-map@2.4.20': {}
'@volar/source-map@2.4.23': {}
'@volar/source-map@2.4.27': {}
'@volar/source-map@2.4.28': {}
'@volar/typescript@2.4.20':
dependencies:
'@volar/language-core': 2.4.20
@@ -8943,6 +9073,16 @@ snapshots:
optionalDependencies:
typescript: 5.8.3
'@vue/language-core@3.2.2':
dependencies:
'@volar/language-core': 2.4.27
'@vue/compiler-dom': 3.5.28
'@vue/shared': 3.5.28
alien-signals: 3.1.0
muggle-string: 0.4.1
path-browserify: 1.0.1
picomatch: 4.0.3
'@vue/reactivity@3.5.27':
dependencies:
'@vue/shared': 3.5.27
@@ -10367,6 +10507,16 @@ snapshots:
slash: 5.1.0
unicorn-magic: 0.3.0
golar@0.0.13(@golar/vue@0.0.13):
optionalDependencies:
'@golar/darwin-arm64': 0.0.13
'@golar/darwin-x64': 0.0.13
'@golar/linux-arm64': 0.0.13
'@golar/linux-x64': 0.0.13
'@golar/vue': 0.0.13
'@golar/win32-arm64': 0.0.13
'@golar/win32-x64': 0.0.13
gopd@1.2.0:
optional: true
+1 -3
View File
@@ -1,4 +1,5 @@
onlyBuiltDependencies:
- "@bufbuild/buf"
- "@parcel/watcher"
- "@prisma/client"
- "@prisma/engines"
@@ -9,7 +10,4 @@ onlyBuiltDependencies:
- sharp
- unrs-resolver
# overrides:
# droplet: link:../../.local/share/pnpm/global/5/node_modules/@drop-oss/droplet
shamefullyHoist: true
@@ -0,0 +1,15 @@
-- DropIndex
DROP INDEX "Game_mName_idx";
-- DropIndex
DROP INDEX "GameTag_name_idx";
-- AlterTable
ALTER TABLE "Game" ALTER COLUMN "mImageCarouselObjectIds" SET DEFAULT ARRAY[]::TEXT[];
UPDATE "Game" SET "mImageCarouselObjectIds" = '{}' WHERE "mImageCarouselObjectIds" IS NULL;
-- 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));
+1 -1
View File
@@ -38,7 +38,7 @@ model Game {
mIconObjectId String // linked to objects in s3
mBannerObjectId String // linked to objects in s3
mCoverObjectId String
mImageCarouselObjectIds String[] // linked to below array
mImageCarouselObjectIds String[] @default([]) // linked to below array
mImageLibraryObjectIds String[] // linked to objects in s3
versions GameVersion[]
@@ -1,16 +0,0 @@
import aclManager from "~/server/internal/acls";
import prisma from "~/server/internal/db/database";
export default defineEventHandler(async (h3) => {
const allowed = await aclManager.allowSystemACL(h3, ["game:read"]);
if (!allowed) throw createError({ statusCode: 403 });
return await prisma.game.findMany({
select: {
id: true,
mName: true,
mShortDescription: true,
mIconObjectId: true,
},
});
});
@@ -0,0 +1,54 @@
import aclManager from "~/server/internal/acls";
import prisma from "~/server/internal/db/database";
import { libraryManager } from "~/server/internal/library";
export default defineEventHandler(async (h3) => {
const allowed = await aclManager.allowSystemACL(h3, ["import:version:read"]);
if (!allowed) throw createError({ statusCode: 403 });
const games = await prisma.game.findMany({
select: {
id: true,
mName: true,
mIconObjectId: true,
versions: {
select: {
versionPath: true,
},
},
unimportedGameVersions: {
select: {
id: true,
versionName: true,
},
},
libraryId: true,
libraryPath: true,
},
});
const unimportedVersions = await Promise.all(
games.map(async (v) => ({
id: v.id,
name: v.mName,
icon: v.mIconObjectId,
versions: await libraryManager.fetchUnimportedGameVersions(
v.libraryId,
v.libraryPath,
{
gameId: v.id,
versions: v.versions
.map((v) => v.versionPath)
.filter((v) => v !== null),
depotVersions: v.unimportedGameVersions,
},
),
})),
);
const onlyUnimported = unimportedVersions.filter(
(v) => v.versions && v.versions.length > 0,
);
return onlyUnimported;
});
@@ -0,0 +1,115 @@
import { type } from "arktype";
import { readDropValidatedBody, throwingArktype } from "~/server/arktype";
import { aclManager } from "~/server/internal/acls";
import { libraryManager } from "~/server/internal/library";
import { taskHandler, wrapTaskContext } from "~/server/internal/tasks";
import type { Platform } from "~/prisma/client/client";
const MassImport = type({
versions: type({
id: "string",
version: type({
type: "'depot' | 'local'",
identifier: "string",
name: "string",
}),
displayName: "string?",
setupMode: "boolean = false",
}).array(),
}).configure(throwingArktype);
export default defineEventHandler(async (h3) => {
const allowed = await aclManager.allowSystemACL(h3, ["import:version:new"]);
if (!allowed) throw createError({ statusCode: 403 });
const body = await readDropValidatedBody(h3, MassImport);
const taskId = await taskHandler.create({
key: "mass-import",
taskGroup: "import:version",
acls: ["system:import:version:read"],
name: `Mass-importing for ${body.versions.length} versions`,
async run({ progress, logger, addAction }) {
for (
let versionIndex = 0;
versionIndex < body.versions.length;
versionIndex++
) {
const version = body.versions[versionIndex];
const preload = await libraryManager.fetchUnimportedVersionInformation(
version.id,
version.version,
);
if (!preload) {
logger.warn(
`failed to fetch preload information for: ${version.version.name} (${version.version.type})`,
);
continue;
}
const chosenPreload = preload.at(0);
if (!chosenPreload) {
logger.warn(
`failed to find preload information for: ${version.version.name} (${version.version.type}), there were no auto-discovered executables`,
);
continue;
}
const launches: Array<{
platform: Platform;
launch: string;
name: string;
}> = [];
const setups: Array<{ platform: Platform; launch: string }> = [];
if (version.setupMode) {
setups.push({
platform: chosenPreload.platform,
launch: chosenPreload.filename,
});
} else {
launches.push({
platform: chosenPreload.platform,
launch: chosenPreload.filename,
name: "Play",
});
}
logger.info(`importing ${version.version.name}`);
const min = versionIndex / body.versions.length;
const max = (versionIndex + 1) / body.versions.length;
await libraryManager.importVersion(
version.id,
version.version,
{
id: version.id,
version: version.version,
launches,
setups,
onlySetup: version.setupMode,
delta: false,
requiredContent: [],
},
wrapTaskContext(
{
logger,
progress,
addAction,
},
{
min: min * 100,
max: max * 100,
prefix: `${version.version.name}`,
},
),
);
logger.info(`finished import for ${version.version.name}`);
progress(max * 100);
}
},
});
return { taskId };
});
@@ -2,7 +2,6 @@ import { type } from "arktype";
import { Platform } from "~/prisma/client/enums";
import { readDropValidatedBody, throwingArktype } from "~/server/arktype";
import aclManager from "~/server/internal/acls";
import prisma from "~/server/internal/db/database";
import libraryManager from "~/server/internal/library";
export const ImportVersion = type({
@@ -42,45 +41,6 @@ export default defineEventHandler(async (h3) => {
const body = await readDropValidatedBody(h3, ImportVersion);
if (body.delta) {
for (const platformObject of [...body.launches, ...body.setups].filter(
(v, i, a) => a.findIndex((k) => k.platform === v.platform) == i,
)) {
const validOverlayVersions = await prisma.gameVersion.count({
where: {
gameId: body.id,
delta: false,
OR: [
{ launches: { some: { platform: platformObject.platform } } },
{
setups: { some: { platform: platformObject.platform } },
},
],
},
});
if (validOverlayVersions == 0)
throw createError({
statusCode: 400,
statusMessage: `Update mode requires a pre-existing version for platform: ${platformObject.platform}`,
});
}
}
if (body.onlySetup) {
if (body.setups.length == 0)
throw createError({
statusCode: 400,
statusMessage: 'Setup required in "setup mode".',
});
} else {
if (body.launches.length == 0)
throw createError({
statusCode: 400,
statusMessage: "Launch executable is required.",
});
}
// startup & delta require more complex checking logic
const taskId = await libraryManager.importVersion(
body.id,
body.version,
+118 -5
View File
@@ -1,15 +1,128 @@
import { ArkErrors, type } from "arktype";
import type { SerializeObject } from "nitropack";
import type { Prisma } from "~/prisma/client/client";
import aclManager from "~/server/internal/acls";
import prisma from "~/server/internal/db/database";
import libraryManager from "~/server/internal/library";
import deepmerge from "deepmerge";
const Query = type({
query: "string?",
skip: "string.numeric.parse?",
limit: "string.numeric.parse?",
sort: "'default' | 'newest' | 'recent' | 'name' = 'default'",
order: "'asc' | 'desc' = 'desc'",
"filters?": type("string").pipe((s) => s.split(",")),
});
type FetchArg = Parameters<typeof libraryManager.fetchGamesWithStatus>[0];
export type AdminLibraryGame = SerializeObject<
Awaited<ReturnType<typeof libraryManager.fetchGamesWithStatus>>[number]
>;
export default defineEventHandler(async (h3) => {
const allowed = await aclManager.allowSystemACL(h3, ["library:read"]);
if (!allowed) throw createError({ statusCode: 403 });
const unimportedGames = await libraryManager.fetchUnimportedGames();
const games = await libraryManager.fetchGamesWithStatus();
const libraries = await libraryManager.fetchLibraries();
const query = Query(getQuery(h3));
if (query instanceof ArkErrors)
throw createError({ statusCode: 400, message: query.summary });
// Fetch other library data here
const skip = query.skip
? ({
skip: query.skip,
} satisfies FetchArg)
: undefined;
return { unimportedGames, games, hasLibraries: libraries.length > 0 };
const limit = Math.min(query.limit ?? 24, 50);
const sort: Prisma.GameOrderByWithRelationInput = {};
switch (query.sort) {
case "default":
case "newest":
sort.mReleased = query.order;
break;
case "recent":
sort.created = query.order;
break;
case "name":
sort.mName = query.order;
break;
}
const rawFilters: Array<Prisma.GameFindManyArgs & Prisma.GameCountArgs> = [];
if (query.filters && query.filters.length > 0) {
const filterSet = new Set(query.filters);
if (filterSet.has("version.none")) {
rawFilters.push({
where: {
versions: {
none: {},
},
},
});
}
if (filterSet.has("metadata.featured")) {
rawFilters.push({
where: {
featured: true,
},
});
}
if (filterSet.has("metadata.noCarousel")) {
rawFilters.push({
where: {
OR: [
{
mImageCarouselObjectIds: {
isEmpty: true,
},
},
],
},
});
}
if (filterSet.has("metadata.emptyDescription")) {
rawFilters.push({
where: {
mDescription: "",
},
});
}
}
if (query.query) {
rawFilters.push({
where: {
mName: {
contains: query.query,
mode: "insensitive",
},
},
});
}
const filters =
rawFilters.length > 0
? rawFilters.reduce((a, b) => deepmerge(a, b))
: undefined;
const results = await libraryManager.fetchGamesWithStatus({
...skip,
take: limit,
orderBy: sort,
...filters,
});
// Safety: the type is defined as a union between the where and count args
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const count = await prisma.game.count({ ...(filters as any) });
return { results, count };
});
@@ -0,0 +1,12 @@
import aclManager from "~/server/internal/acls";
import libraryManager from "~/server/internal/library";
export default defineEventHandler(async (h3) => {
const allowed = await aclManager.allowSystemACL(h3, ["library:read"]);
if (!allowed) throw createError({ statusCode: 403 });
const unimportedGames = await libraryManager.fetchUnimportedGames();
const libraries = await libraryManager.fetchLibraries();
return { unimportedGames, hasLibraries: libraries.length > 0 };
});
+10 -4
View File
@@ -1,6 +1,5 @@
import aclManager from "~/server/internal/acls";
import prisma from "~/server/internal/db/database";
import type { TaskMessage } from "~/server/internal/tasks";
import taskHandler from "~/server/internal/tasks";
export default defineEventHandler(async (h3) => {
@@ -14,7 +13,7 @@ export default defineEventHandler(async (h3) => {
});
const runningTasks = (await taskHandler.runningTasks()).map((e) => e.id);
const historicalTasks = (await prisma.task.findMany({
const historicalTasks = await prisma.task.findMany({
where: {
OR: [
{
@@ -28,8 +27,15 @@ export default defineEventHandler(async (h3) => {
orderBy: {
ended: "desc",
},
take: 10,
})) as Array<TaskMessage>;
select: {
id: true,
name: true,
actions: true,
error: true,
success: true,
},
take: 32,
});
const dailyTasks = await taskHandler.dailyTasks();
const weeklyTasks = await taskHandler.weeklyTasks();
@@ -1,3 +1,4 @@
import { ArkErrors, type } from "arktype";
import type { Platform } from "~/prisma/client/enums";
import { defineClientEventHandler } from "~/server/internal/clients/event-handler";
import prisma from "~/server/internal/db/database";
@@ -21,6 +22,10 @@ type VersionDownloadOption = {
}>;
};
const Query = type({
previous: "string?",
});
export default defineClientEventHandler(async (h3) => {
const id = getRouterParam(h3, "id")!;
if (!id)
@@ -29,6 +34,10 @@ export default defineClientEventHandler(async (h3) => {
statusMessage: "No ID in router params",
});
const query = Query(getQuery(h3));
if (query instanceof ArkErrors)
throw createError({ statusCode: 400, message: query.summary });
const rawVersions = await prisma.gameVersion.findMany({
where: {
gameId: id,
@@ -93,7 +102,10 @@ export default defineClientEventHandler(async (h3) => {
}
}
const size = await gameSizeManager.getVersionSize(v.versionId);
const size = await gameSizeManager.getVersionSize(
v.versionId,
query.previous,
);
return platformOptions
.entries()
@@ -1,15 +1,22 @@
import { ArkErrors, type } from "arktype";
import { defineClientEventHandler } from "~/server/internal/clients/event-handler";
import { createDownloadManifestDetails } from "~/server/internal/library/manifest/index";
export default defineClientEventHandler(async (h3) => {
const query = getQuery(h3);
const version = query.version?.toString();
if (!version)
throw createError({
statusCode: 400,
statusMessage: "Missing version ID in query",
const Query = type({
version: "string",
previous: "string?",
refresh: "string?",
});
const result = await createDownloadManifestDetails(version);
export default defineClientEventHandler(async (h3) => {
const query = Query(getQuery(h3));
if (query instanceof ArkErrors)
throw createError({ statusCode: 400, message: query.summary });
const result = await createDownloadManifestDetails(
query.version,
query.previous,
query.refresh == "true",
);
return result;
});
+16 -6
View File
@@ -21,23 +21,33 @@ class GameSizeManager {
private gameBreakdownCache =
cacheHandler.createCache<GameSizeBreakdown>("gameBreakdown");
private gameVersionSizeCacheKey(versionId: string, previousId?: string) {
return `${versionId}${previousId ? `-from-${previousId}` : ""}`;
}
/***
* Gets the size of the game to the user:
* - installSize: size on disk after install
* - downloadSize: how many bytes are downloaded (but not necessarily stored)
*/
async getVersionSize(versionId: string): Promise<GameVersionSize | null> {
if (await this.gameVersionsSizesCache.has(versionId))
return await this.gameVersionsSizesCache.get(versionId);
async getVersionSize(
versionId: string,
previousId?: string,
): Promise<GameVersionSize | null> {
const key = this.gameVersionSizeCacheKey(versionId, previousId);
if (await this.gameVersionsSizesCache.has(key))
return await this.gameVersionsSizesCache.get(key);
try {
const { downloadSize, installSize } =
await createDownloadManifestDetails(versionId);
const { downloadSize, installSize } = await createDownloadManifestDetails(
versionId,
previousId,
);
const result = {
downloadSize,
installSize,
versionId,
} satisfies GameVersionSize;
await this.gameVersionsSizesCache.set(versionId, result);
await this.gameVersionsSizesCache.set(key, result);
return result;
} catch {
return null;
+117 -33
View File
@@ -8,6 +8,7 @@
import path from "path";
import prisma from "../db/database";
import { fuzzy } from "fast-fuzzy";
import type { TaskRunContext } from "../tasks";
import taskHandler from "../tasks";
import notificationSystem from "../notifications";
import { GameNotFoundError, type LibraryProvider } from "./provider";
@@ -20,6 +21,7 @@ import type { ImportVersion } from "~/server/api/v1/admin/import/version/index.p
import { GameType, type Platform } from "~/prisma/client/enums";
import { castManifest } from "./manifest/utils";
import { Shescape } from "shescape";
import type { Prisma } from "~/prisma/client/client";
export function createGameImportTaskId(libraryId: string, libraryPath: string) {
return createHash("md5")
@@ -125,9 +127,16 @@ class LibraryManager {
async fetchUnimportedGameVersions(
libraryId: string,
libraryPath: string,
noFetchParams?: {
gameId: string;
versions: string[];
depotVersions: { id: string; versionName: string }[];
},
): Promise<UnimportedVersionInformation[] | undefined> {
const provider = this.libraries.get(libraryId);
if (!provider) return undefined;
let params = noFetchParams;
if (!params) {
const game = await prisma.game.findUnique({
where: {
libraryKey: {
@@ -137,30 +146,14 @@ class LibraryManager {
},
select: {
id: true,
versions: true,
versions: {
select: {
versionPath: true,
},
},
},
});
if (!game) return undefined;
try {
const versions = await provider.listVersions(
libraryPath,
game.versions.map((v) => v.versionPath).filter((v) => v !== null),
);
const unimportedVersions = versions
.filter(
(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,
@@ -170,7 +163,38 @@ class LibraryManager {
id: true,
},
});
const mappedDepotVersions = depotVersions.map(
params = {
gameId: game.id,
versions: game.versions
.map((v) => v.versionPath)
.filter((v) => v !== null),
depotVersions: depotVersions,
};
}
try {
const versions = await provider.listVersions(
libraryPath,
params.versions,
);
const unimportedVersions = versions
.filter(
(e) =>
params.versions.findIndex((v) => v == e) == -1 &&
!taskHandler.hasTaskKey(
createVersionImportTaskKey(params.gameId, e),
),
)
.map(
(v) =>
({
type: "local",
name: v,
identifier: v,
}) satisfies UnimportedVersionInformation,
);
const mappedDepotVersions = params.depotVersions.map(
(v) =>
({
type: "depot",
@@ -188,29 +212,37 @@ class LibraryManager {
}
}
async fetchGamesWithStatus() {
async fetchGamesWithStatus(
where: Partial<Omit<Prisma.GameFindManyArgs, "include">>,
) {
const games = await prisma.game.findMany({
...where,
include: {
library: true,
versions: true,
},
orderBy: {
mName: "asc",
unimportedGameVersions: true,
},
});
return await Promise.all(
games.map(async (e) => {
const versions = await this.fetchUnimportedGameVersions(
const unimportedVersions = await this.fetchUnimportedGameVersions(
e.libraryId ?? "",
e.libraryPath,
{
gameId: e.id,
versions: e.versions
.map((v) => v.versionPath)
.filter((v) => v !== null),
depotVersions: e.unimportedGameVersions,
},
);
return {
game: e,
status: versions
status: unimportedVersions
? {
noVersions: e.versions.length == 0,
unimportedVersions: versions,
unimportedVersions: unimportedVersions,
}
: ("offline" as const),
};
@@ -375,9 +407,51 @@ class LibraryManager {
gameId: string,
version: UnimportedVersionInformation,
metadata: typeof ImportVersion.infer,
parentTask?: TaskRunContext,
) {
const taskKey = createVersionImportTaskKey(gameId, version.identifier);
if (metadata.delta) {
for (const platformObject of [
...metadata.launches,
...metadata.setups,
].filter(
(v, i, a) => a.findIndex((k) => k.platform === v.platform) == i,
)) {
const validOverlayVersions = await prisma.gameVersion.count({
where: {
gameId: metadata.id,
delta: false,
OR: [
{ launches: { some: { platform: platformObject.platform } } },
{
setups: { some: { platform: platformObject.platform } },
},
],
},
});
if (validOverlayVersions == 0)
throw createError({
statusCode: 400,
message: `Update mode requires a pre-existing version for platform: ${platformObject.platform}`,
});
}
}
if (metadata.onlySetup) {
if (metadata.setups.length == 0)
throw createError({
statusCode: 400,
message: 'Setup required in "setup mode".',
});
} else {
if (metadata.launches.length == 0)
throw createError({
statusCode: 400,
message: "Launch executable is required.",
});
}
const game = await prisma.game.findUnique({
where: { id: gameId },
select: { mName: true, libraryId: true, libraryPath: true, type: true },
@@ -400,9 +474,10 @@ class LibraryManager {
})
: undefined;
return await taskHandler.create({
return await taskHandler.create(
{
key: taskKey,
taskGroup: "import:game",
taskGroup: "import:version",
name: `Importing version ${version.name} for ${game.mName}`,
acls: ["system:import:version:read"],
async run({ progress, logger }) {
@@ -438,9 +513,16 @@ class LibraryManager {
throw "Could not find or create manifest for this version.";
}
const currentIndex = await prisma.gameVersion.count({
const largestIndex = await prisma.gameVersion.findFirst({
where: { gameId: gameId },
orderBy: {
versionIndex: "desc",
},
select: {
versionIndex: true,
},
});
const currentIndex = largestIndex ? largestIndex.versionIndex + 1 : 0;
// Then, create the database object
const newVersion = await prisma.gameVersion.create({
@@ -517,7 +599,9 @@ class LibraryManager {
}
progress(100);
},
});
},
parentTask,
);
}
async peekFile(
@@ -30,10 +30,12 @@ const manifestCache =
*/
export async function createDownloadManifestDetails(
versionId: string,
previous?: string,
refresh = false,
): Promise<DownloadManifestDetails> {
if ((await manifestCache.has(versionId)) && !refresh)
return (await manifestCache.get(versionId))!;
const manifestKey = `${versionId}${previous ? `-from-${previous}` : ""}`;
if ((await manifestCache.has(manifestKey)) && !refresh)
return (await manifestCache.get(manifestKey))!;
const mainVersion = await prisma.gameVersion.findUnique({
where: { versionId },
select: {
@@ -94,6 +96,10 @@ export async function createDownloadManifestDetails(
let installSize = 0;
let downloadSize = 0;
const existingChunks = previous
? await createDownloadManifestDetails(previous)
: undefined;
// Now that we have our file list, filter the manifests
const manifests = new Map<string, DropletManifest>();
for (const version of versionOrder) {
@@ -105,9 +111,15 @@ export async function createDownloadManifestDetails(
const fileNames = Object.fromEntries(files);
const manifest = castManifest(version.dropletManifest);
const filteredChunks = Object.fromEntries(
Object.entries(manifest.chunks).filter(([, chunkData]) => {
Object.entries(manifest.chunks).filter(([_, chunkData]) => {
//if(existingChunks && existingChunks.manifests[version.versionId]?.chunks?.[chunkId]) return false;
let flag = false;
chunkData.files.forEach((fileEntry) => {
if (
existingChunks &&
existingChunks.fileList[fileEntry.filename] == version.versionId
)
return;
if (fileNames[fileEntry.filename]) {
flag = true;
installSize += fileEntry.length;
@@ -134,7 +146,7 @@ export async function createDownloadManifestDetails(
installSize,
downloadSize,
};
await manifestCache.set(versionId, result);
await manifestCache.set(manifestKey, result);
return result;
}
+6 -3
View File
@@ -107,9 +107,12 @@ export class Service<T> {
if (this.spun) this.launch();
});
serviceProcess.stdout?.on("data", (data) =>
this.logger.info(data.toString().trim()),
);
serviceProcess.stdout?.on("data", (data) => {
const lines = data.toString().trim().split("\n");
for (const line of lines) {
this.logger.info(line);
}
});
serviceProcess.stderr?.on("data", (data) =>
this.logger.error(data.toString().trim()),
+3
View File
@@ -14,6 +14,9 @@ export const taskGroups = {
"import:game": {
concurrency: true,
},
"import:version": {
concurrency: true,
},
debug: {
concurrency: true,
},
+22 -14
View File
@@ -8,7 +8,7 @@ import checkUpdate from "./registry/update";
import cleanupObjects from "./registry/objects";
import { taskGroups, type TaskGroup } from "./group";
import prisma from "../db/database";
import { type } from "arktype";
import { ArkErrors, type } from "arktype";
import pino from "pino";
import { logger } from "~/server/internal/logging";
import { Writable } from "node:stream";
@@ -76,7 +76,7 @@ class TaskHandler {
this.taskCreators.set(task.taskGroup, task.build);
}
async create(iTask: Omit<Task, "id">) {
async create(iTask: Omit<Task, "id">, parentTask?: TaskRunContext) {
const task: Task = { ...iTask, id: crypto.randomUUID() };
if (this.hasTaskID(task.id))
throw new Error("Task with ID already exists.");
@@ -105,6 +105,7 @@ class TaskHandler {
const updateAllClients = (reset = false) =>
new Promise((r) => {
//if (parentTask) return; // NO-OP if we're a child task
if (updateCollectTimeout) {
updateCollectResolves.push(r);
return;
@@ -148,7 +149,10 @@ class TaskHandler {
write(chunk, encoding, callback) {
try {
// chunk is a stringified JSON log line
const logObj = JSON.parse(chunk.toString());
const logObj = TaskLog(JSON.parse(chunk.toString()));
if (logObj instanceof ArkErrors) {
throw logObj;
}
const taskEntry = taskPool.get(task.id);
if (taskEntry) {
taskEntry.log.push(JSON.stringify(logObj));
@@ -156,17 +160,16 @@ class TaskHandler {
}
} catch (e) {
// fallback: ignore or log error
logger.error("Failed to parse log chunk", {
error: e,
chunk: chunk,
});
logger.error(`Failed to parse log chunk: ${e}, ${chunk}`);
}
callback();
},
});
// Use pino with the custom stream
const taskLogger = pino(
const taskLogger =
parentTask?.logger ??
pino(
{
// You can configure timestamp, level, etc. here
timestamp: pino.stdTimeFunctions.isoTime,
@@ -182,7 +185,9 @@ class TaskHandler {
logStream,
);
const progress = (progress: number) => {
const progress =
parentTask?.progress ??
((progress: number) => {
if (progress < 0 || progress > 100) {
logger.error("Progress must be between 0 and 100", { progress });
return;
@@ -192,7 +197,7 @@ class TaskHandler {
taskEntry.progress = progress;
// log(`Progress: ${progress}%`);
updateAllClients();
};
});
this.taskPool.set(task.id, {
name: task.name,
@@ -233,6 +238,7 @@ class TaskHandler {
taskEntry.endTime = new Date().toISOString();
await updateAllClients();
if (!parentTask) {
for (const clientId of taskEntry.clients.keys()) {
if (!this.clientRegistry.get(clientId)) continue;
this.disconnect(clientId, task.id);
@@ -257,11 +263,12 @@ class TaskHandler {
...(taskEntry.error ? { error: taskEntry.error } : undefined),
},
});
}
this.taskPool.delete(task.id);
};
taskFunc();
const fnPromise = taskFunc();
if (parentTask) await fnPromise;
return task.id;
}
@@ -511,9 +518,10 @@ interface DropTask {
}
export const TaskLog = type({
timestamp: "string",
message: "string",
time: "string",
msg: "string",
level: "string",
prefix: "string?",
});
// /**
Submodule server/torrential updated: 50e54b6c60...f469744ebf
+2 -6
View File
@@ -14,7 +14,7 @@ const labelNumberMap = {
export function parseTaskLog(
logStr?: string | undefined,
): typeof TaskLog.infer {
if (!logStr) return { message: "", timestamp: "", level: "" };
if (!logStr) return { msg: "", time: "", level: "" };
const log = JSON.parse(logStr);
if (typeof log.level === "number") {
@@ -23,9 +23,5 @@ export function parseTaskLog(
] as string;
}
return {
message: log.msg,
timestamp: log.time,
level: log.level,
};
return log;
}