diff --git a/server/internal/tasks/index.ts b/server/internal/tasks/index.ts index e87d0a4..c002c8b 100644 --- a/server/internal/tasks/index.ts +++ b/server/internal/tasks/index.ts @@ -51,6 +51,7 @@ class TaskHandler { "cleanup:invitations", "cleanup:sessions", "check:update", + "ludusavi:import" ]; private weeklyScheduledTasks: TaskGroup[] = ["cleanup:objects"]; diff --git a/server/tasks/ludusavi.ts b/server/tasks/ludusavi.ts deleted file mode 100644 index 343edfa..0000000 --- a/server/tasks/ludusavi.ts +++ /dev/null @@ -1,133 +0,0 @@ -import yaml from "js-yaml"; -import prisma from "../internal/db/database"; -import { Platform } from "~/prisma/client"; -import type { LudusaviPlatformEntryCreateOrConnectWithoutLudusaviEntryInput } from "~/prisma/client/models"; - -type ConnectOrCreateShorthand = - LudusaviPlatformEntryCreateOrConnectWithoutLudusaviEntryInput; - -type LudusaviModel = { - [key: string]: { - files?: { - [key: string]: { - tags?: Array; - when?: Array<{ os?: string }>; - }; - }; - registry?: { [key: string]: { tags?: Array } }; - steam?: { id: number }; - }; -}; - -export default defineTask({ - async run(_event) { - const manifest = yaml.load( - await $fetch( - "https://raw.githubusercontent.com/mtkennerly/ludusavi-manifest/refs/heads/master/data/manifest.yaml", - ), - ) as LudusaviModel; - - for (const [name, data] of Object.entries(manifest)) { - if (!data.files && !data.registry) continue; - console.log(name); - - const iterableFiles = data.files ? Object.entries(data.files) : undefined; - - function findFilesForOperatingSystem(os: string) { - return iterableFiles?.filter((e) => - e[1].when?.find((v) => v.os === os), - ); - } - - const connectOrCreate: ConnectOrCreateShorthand[] = []; - - const windowsData = { - registry: data.registry, - files: findFilesForOperatingSystem("windows"), - }; - - if (windowsData.registry || windowsData.files) { - const create: ConnectOrCreateShorthand = { - where: { - ludusaviEntryName_platform: { - ludusaviEntryName: name, - platform: Platform.Windows, - }, - }, - create: { - platform: Platform.Windows, - files: windowsData.files?.map((e) => e[0]) ?? [], - registry: Object.entries(windowsData.registry ?? {}).map( - (e) => e[0], - ), - }, - }; - - connectOrCreate.push(create); - } - - const linuxData = { - files: findFilesForOperatingSystem("linux"), - }; - - if (linuxData.files) { - const create: ConnectOrCreateShorthand = { - where: { - ludusaviEntryName_platform: { - ludusaviEntryName: name, - platform: Platform.Linux, - }, - }, - create: { - platform: Platform.Linux, - files: linuxData.files?.map((e) => e[0]) ?? [], - registry: [], - }, - }; - - connectOrCreate.push(create); - } - - const macData = { - files: findFilesForOperatingSystem("mac"), - }; - - if (macData.files) { - const create: ConnectOrCreateShorthand = { - where: { - ludusaviEntryName_platform: { - ludusaviEntryName: name, - platform: Platform.macOS, - }, - }, - create: { - platform: Platform.macOS, - files: macData.files?.map((e) => e[0]) ?? [], - registry: [], - }, - }; - - connectOrCreate.push(create); - } - - const steamId = data.steam?.id.toString() ?? null; - - await prisma.ludusaviEntry.upsert({ - where: { - name, - }, - create: { - name, - steamId, - entries: { connectOrCreate }, - }, - update: { - steamId, - entries: { connectOrCreate }, - }, - }); - } - - return { result: true }; - }, -});