feat: add server side redist patching

This commit is contained in:
DecDuck
2025-08-28 11:14:38 +10:00
parent ca7a89bbcf
commit cf3a458bdf
9 changed files with 218 additions and 71 deletions

View File

@ -0,0 +1,14 @@
<template>
<div>{{ model }}</div>
</template>
<script setup lang="ts">
import type { SerializeObject } from "nitropack";
import type { RedistModel, UserPlatformModel } from "~/prisma/client/models";
type ModelType = SerializeObject<
RedistModel & { platform?: UserPlatformModel }
>;
const model = defineModel<ModelType>({ required: true });
</script>

View File

@ -7,66 +7,6 @@
> >
<!--start--> <!--start-->
<div> <div>
<Listbox v-if="false" v-model="currentMode" as="div">
<div class="relative mt-2">
<ListboxButton
class="min-w-[10vw] w-full cursor-default inline-flex items-center gap-x-2 rounded-md bg-zinc-900 py-1.5 pr-2 pl-3 text-left text-zinc-200 outline-1 -outline-offset-1 outline-zinc-700 focus:outline-2 focus:-outline-offset-2 focus:outline-blue-600 sm:text-sm/6"
>
<span class="col-start-1 row-start-1 truncate">{{
currentMode
}}</span>
<PencilIcon class="ml-auto size-5" />
<ChevronUpDownIcon
class="text-gray-500 size-5"
aria-hidden="true"
/>
</ListboxButton>
<transition
leave-active-class="transition ease-in duration-100"
leave-from-class="opacity-100"
leave-to-class="opacity-0"
>
<ListboxOptions
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-hidden sm:text-sm"
>
<ListboxOption
v-for="[value] in Object.entries(components)"
v-slot="{ active, selected }"
:key="value"
as="template"
:value="value"
>
<li
:class="[
active
? 'bg-blue-600 text-white outline-hidden'
: 'text-zinc-100',
'relative cursor-default py-2 pr-9 pl-3 select-none',
]"
>
<span
:class="[
selected ? 'font-semibold' : 'font-normal',
'block truncate',
]"
>{{ value }}</span
>
<span
v-if="selected"
class="text-white absolute inset-y-0 right-0 flex items-center pr-4"
>
<PencilIcon class="size-5" aria-hidden="true" />
</span>
</li>
</ListboxOption>
</ListboxOptions>
</transition>
</div>
</Listbox>
<div class="pt-4 inline-flex gap-x-2"> <div class="pt-4 inline-flex gap-x-2">
<div <div
@ -112,18 +52,10 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import {
Listbox,
ListboxButton,
ListboxOption,
ListboxOptions,
} from "@headlessui/vue";
import { ChevronUpDownIcon } from "@heroicons/vue/16/solid";
import { GameEditorMetadata, GameEditorVersion } from "#components"; import { GameEditorMetadata, GameEditorVersion } from "#components";
import { import {
ArrowTopRightOnSquareIcon, ArrowTopRightOnSquareIcon,
DocumentIcon, DocumentIcon,
PencilIcon,
ServerStackIcon, ServerStackIcon,
} from "@heroicons/vue/24/outline"; } from "@heroicons/vue/24/outline";
import type { Component } from "vue"; import type { Component } from "vue";
@ -158,7 +90,6 @@ const components: {
const currentMode = ref<GameEditorMode>(GameEditorMode.Metadata); const currentMode = ref<GameEditorMode>(GameEditorMode.Metadata);
useHead({ useHead({
// To do a title with the game name in it, we need some sort of watch
title: `${currentMode.value} - ${game.value.mName}`, title: `${currentMode.value} - ${game.value.mName}`,
}); });

View File

@ -210,7 +210,7 @@
</dl> </dl>
<dl <dl
v-if="entry.platform" v-if="entry.platform"
class="mt-2 flex items-center text-zinc-200 font-semibold text-sm gap-x-1 p-2 bg-zinc-900 rounded-xl" class="mt-2 flex items-center text-zinc-200 font-semibold text-sm gap-x-1 p-2 bg-zinc-800 rounded-xl"
> >
<IconsPlatform <IconsPlatform
:platform="entry.platform.id" :platform="entry.platform.id"

View File

@ -0,0 +1,85 @@
<template>
<div
class="pt-8 lg:pt-0 lg:pl-20 fixed inset-0 flex flex-col overflow-auto bg-zinc-900"
>
<div
class="bg-zinc-950 w-full flex flex-col sm:flex-row items-center gap-2 justify-between pr-2"
>
<!--start-->
<div>
<div class="pt-4 inline-flex gap-x-2">
<div
v-for="[value, { icon }] in Object.entries(components)"
:key="value"
>
<button
:class="[
'inline-flex items-center gap-x-1 py-2 px-3 rounded-t-md font-semibold text-sm',
value == currentMode
? 'bg-zinc-900 text-zinc-100'
: 'bg-transparent text-zinc-500',
]"
@click="() => (currentMode = value as RedistEditorMode)"
>
<component :is="icon" class="size-4" />
{{ value }}
</button>
</div>
</div>
</div>
<div>
<!-- open in store button -->
</div>
</div>
<component
:is="components[currentMode].editor"
v-model="redist"
:unimported-versions="unimportedVersions"
/>
</div>
</template>
<script setup lang="ts">
import { GameEditorVersion, RedistEditorMetadata } from "#components";
import { DocumentIcon, ServerStackIcon } from "@heroicons/vue/24/outline";
import type { Component } from "vue";
const route = useRoute();
const redistId = route.params.id.toString();
const { redist: rawRedist, unimportedVersions } = await $dropFetch(
`/api/v1/admin/redist/:id`,
{ params: { id: redistId } },
);
const redist = ref(rawRedist);
definePageMeta({
layout: "admin",
});
enum RedistEditorMode {
Metadata = "Metadata",
Versions = "Versions",
}
const components: {
[key in RedistEditorMode]: { editor: Component; icon: Component };
} = {
[RedistEditorMode.Metadata]: { editor: RedistEditorMetadata, icon: DocumentIcon },
[RedistEditorMode.Versions]: {
editor: GameEditorVersion,
icon: ServerStackIcon,
},
};
const currentMode = ref<RedistEditorMode>(RedistEditorMode.Metadata);
useHead({
title: `${currentMode.value} - ${redist.value.mName}`,
});
watch(currentMode, (v) => {
useHead({
title: `${v} - ${redist.value.mName}`,
});
});
</script>

View File

@ -0,0 +1,32 @@
/*
Warnings:
- Added the required column `mReleased` to the `Mod` table without a default value. This is not possible if the table is not empty.
*/
-- DropIndex
DROP INDEX "public"."GameTag_name_idx";
-- AlterTable
ALTER TABLE "public"."Mod" ADD COLUMN "mReleased" TIMESTAMP(3) NOT NULL;
-- CreateTable
CREATE TABLE "public"."GameDLCMetadata" (
"id" TEXT NOT NULL,
"mName" TEXT NOT NULL,
"mShortDescription" TEXT NOT NULL,
"mDescription" TEXT NOT NULL,
"mIconObjectId" TEXT NOT NULL,
"mBannerObjectId" TEXT NOT NULL,
"mCoverObjectId" TEXT NOT NULL,
"mImageCarouselObjectIds" TEXT[],
"mImageLibraryObjectIds" TEXT[],
CONSTRAINT "GameDLCMetadata_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE INDEX "GameTag_name_idx" ON "public"."GameTag" USING GIST ("name" gist_trgm_ops(siglen=32));
-- AddForeignKey
ALTER TABLE "public"."GameDLCMetadata" ADD CONSTRAINT "GameDLCMetadata_id_fkey" FOREIGN KEY ("id") REFERENCES "public"."DLC"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

View File

@ -74,6 +74,8 @@ model LaunchOption {
launchCommand String launchCommand String
launchArgs String @default("") launchArgs String @default("")
} }
model DLCVersion { model DLCVersion {

View File

@ -63,6 +63,22 @@ model DLC {
libraryPath String libraryPath String
versions Version[] versions Version[]
metadata GameDLCMetadata?
}
model GameDLCMetadata {
id String @id
dlc DLC @relation(fields: [id], references: [id])
mName String
mShortDescription String
mDescription String
mIconObjectId String // linked to objects in s3
mBannerObjectId String // linked to objects in s3
mCoverObjectId String
mImageCarouselObjectIds String[] // linked to below array
mImageLibraryObjectIds String[] // linked to objects in s3
} }
model Redist { model Redist {
@ -77,7 +93,7 @@ model Redist {
library Library @relation(fields: [libraryId], references: [id], onDelete: Cascade, onUpdate: Cascade) library Library @relation(fields: [libraryId], references: [id], onDelete: Cascade, onUpdate: Cascade)
libraryPath String libraryPath String
versions Version[] versions Version[]
platform UserPlatform? platform UserPlatform?
@@unique([libraryId, libraryPath], name: "libraryKey") @@unique([libraryId, libraryPath], name: "libraryKey")
@ -97,6 +113,8 @@ model Mod {
mShortDescription String mShortDescription String
mDescription String mDescription String
mReleased DateTime
mIconObjectId String // linked to objects in s3 mIconObjectId String // linked to objects in s3
mBannerObjectId String // linked to objects in s3 mBannerObjectId String // linked to objects in s3
mCoverObjectId String mCoverObjectId String

View File

@ -0,0 +1,38 @@
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, ["redist:read"]);
if (!allowed) throw createError({ statusCode: 403 });
const id = getRouterParam(h3, "id")!;
const redist = await prisma.redist.findUnique({
where: {
id,
},
include: {
platform: true,
versions: true,
},
});
if (!redist)
throw createError({
statusCode: 404,
message: "Redistributable not found.",
});
const unimportedVersions = await libraryManager.fetchUnimportedGameVersions(
redist.libraryId,
redist.libraryPath,
);
if (!unimportedVersions)
throw createError({
statusCode: 500,
message: "Failed to fetch unimported versions for redistributable.",
});
return { redist, unimportedVersions };
});

View File

@ -0,0 +1,27 @@
import aclManager from "~/server/internal/acls";
import prisma from "~/server/internal/db/database";
export default defineEventHandler(async (h3) => {
const allowed = await aclManager.allowSystemACL(h3, ["redist:update"]);
if (!allowed) throw createError({ statusCode: 403 });
const body = await readBody(h3);
const id = body.id;
if (!id || typeof id !== "string")
throw createError({ statusCode: 400, message: "ID required in body." });
const updateParams = body;
delete updateParams["id"];
try {
return await prisma.redist.update({
where: {
id,
},
data: updateParams,
});
} catch (e) {
throw createError({ statusCode: 400, message: (e as string)?.toString() });
}
});