Rearchitecture for v0.4.0 (#197)

* feat: database redist support

* feat: rearchitecture of database schemas, migration reset, and #180

* feat: import redists

* fix: giantbomb logging bug

* feat: partial user platform support + statusMessage -> message

* feat: add user platform filters to store view

* fix: sanitize svg uploads

... copilot suggested this

I feel dirty.

* feat: beginnings of platform & redist management

* feat: add server side redist patching

* fix: update drop-base commit

* feat: import of custom platforms & file extensions

* fix: redelete platform

* fix: remove platform

* feat: uninstall commands, new R UI

* checkpoint: before migrating to nuxt v4

* update to nuxt 4

* fix: fixes for Nuxt v4 update

* fix: remaining type issues

* feat: initial feedback to import other kinds of versions

* working commit

* fix: lint

* feat: redist import
This commit is contained in:
DecDuck
2025-11-10 10:36:13 +11:00
committed by GitHub
parent dfa30c8a65
commit 251ddb8ff8
465 changed files with 8029 additions and 7509 deletions

View File

@ -1,22 +1,32 @@
export const taskGroups = {
"cleanup:invitations": {
concurrency: false,
},
"cleanup:objects": {
concurrency: false,
},
"cleanup:sessions": {
concurrency: false,
},
"check:update": {
concurrency: false,
},
"import:game": {
concurrency: true,
},
debug: {
concurrency: true,
},
} as const;
export const TASK_GROUPS = [
"cleanup:invitations",
"cleanup:objects",
"cleanup:sessions",
"check:update",
"import:game",
"import:version",
] as const;
export type TaskGroup = keyof typeof taskGroups;
export type TaskGroup = (typeof TASK_GROUPS)[number];
export const TASK_GROUP_CONFIG: { [key in TaskGroup]: { concurrency: boolean } } =
{
"cleanup:invitations": {
concurrency: false
},
"cleanup:objects": {
concurrency: false
},
"cleanup:sessions": {
concurrency: false
},
"check:update": {
concurrency: false
},
"import:game": {
concurrency: true
},
"import:version": {
concurrency: true
}
};

View File

@ -1,5 +1,5 @@
import droplet from "@drop-oss/droplet";
import type { MinimumRequestObject } from "~/server/h3";
import type { MinimumRequestObject } from "~~/server/h3";
import type { GlobalACL } from "../acls";
import aclManager from "../acls";
@ -7,12 +7,13 @@ import cleanupInvites from "./registry/invitations";
import cleanupSessions from "./registry/sessions";
import checkUpdate from "./registry/update";
import cleanupObjects from "./registry/objects";
import { taskGroups, type TaskGroup } from "./group";
import { TASK_GROUP_CONFIG, type TaskGroup } from "./group";
import prisma from "../db/database";
import { type } from "arktype";
import pino from "pino";
import { logger } from "~/server/internal/logging";
import { logger } from "~~/server/internal/logging";
import { Writable } from "node:stream";
import type { TaskRunContext } from "./utils";
// a task that has been run
type FinishedTask = {
@ -53,7 +54,6 @@ class TaskHandler {
"cleanup:invitations",
"cleanup:sessions",
"check:update",
"debug",
];
private weeklyScheduledTasks: TaskGroup[] = ["cleanup:objects"];
@ -82,7 +82,7 @@ class TaskHandler {
let logOffset: number = 0;
// if taskgroup disallows concurrency
if (!taskGroups[task.taskGroup].concurrency) {
if (!TASK_GROUP_CONFIG[task.taskGroup].concurrency) {
for (const existingTask of this.taskPool.values()) {
// if a task is already running, we don't want to start another
if (existingTask.taskGroup === task.taskGroup) {
@ -149,7 +149,7 @@ class TaskHandler {
}
} catch (e) {
// fallback: ignore or log error
logger.error("Failed to parse log chunk", {
logger.error("Failed to parse log chunk %s", {
error: e,
chunk: chunk,
});
@ -177,7 +177,7 @@ class TaskHandler {
const progress = (progress: number) => {
if (progress < 0 || progress > 100) {
logger.error("Progress must be between 0 and 100", { progress });
logger.error("Progress must be between 0 and 100, actually %d", progress);
return;
}
const taskEntry = this.taskPool.get(task.id);
@ -412,36 +412,6 @@ class TaskHandler {
}
}
export type TaskRunContext = {
progress: (progress: number) => void;
logger: typeof logger;
};
export function wrapTaskContext(
context: TaskRunContext,
options: { min: number; max: number; prefix: string },
): TaskRunContext {
const child = context.logger.child({
prefix: options.prefix,
});
return {
progress(progress) {
if (progress > 100 || progress < 0) {
logger.warn("[wrapTaskContext] progress must be between 0 and 100");
}
// I was too tired to figure this out
// https://stackoverflow.com/a/929107
const oldRange = 100;
const newRange = options.max - options.min;
const adjustedProgress = (progress * newRange) / oldRange + options.min;
return context.progress(adjustedProgress);
},
logger: child,
};
}
export interface Task {
id: string;
taskGroup: TaskGroup;
@ -484,31 +454,6 @@ export const TaskLog = type({
level: "string",
});
// /**
// * Create a log message with a timestamp in the format YYYY-MM-DD HH:mm:ss.SSS UTC
// * @param message
// * @returns
// */
// function msgWithTimestamp(message: string): string {
// const now = new Date();
// const pad = (n: number, width = 2) => n.toString().padStart(width, "0");
// const year = now.getUTCFullYear();
// const month = pad(now.getUTCMonth() + 1);
// const day = pad(now.getUTCDate());
// const hours = pad(now.getUTCHours());
// const minutes = pad(now.getUTCMinutes());
// const seconds = pad(now.getUTCSeconds());
// const milliseconds = pad(now.getUTCMilliseconds(), 3);
// const log: typeof TaskLog.infer = {
// timestamp: `${year}-${month}-${day} ${hours}:${minutes}:${seconds}.${milliseconds} UTC`,
// message,
// };
// return JSON.stringify(log);
// }
export function defineDropTask(buildTask: BuildTask): DropTask {
return {

View File

@ -1,5 +1,6 @@
import { defineDropTask } from "..";
// import { defineDropTask } from "..";
/*
export default defineDropTask({
buildId: () => `debug:${new Date().toISOString()}`,
name: "Debug Task",
@ -16,3 +17,4 @@ export default defineDropTask({
}
},
});
*/

View File

@ -1,4 +1,4 @@
import prisma from "~/server/internal/db/database";
import prisma from "~~/server/internal/db/database";
import { defineDropTask } from "..";
export default defineDropTask({

View File

@ -1,5 +1,5 @@
import prisma from "~/server/internal/db/database";
import objectHandler from "~/server/internal/objects";
import prisma from "~~/server/internal/db/database";
import objectHandler from "~~/server/internal/objects";
import { defineDropTask } from "..";
type FieldReferenceMap = {

View File

@ -1,4 +1,4 @@
import sessionHandler from "~/server/internal/session";
import sessionHandler from "~~/server/internal/session";
import { defineDropTask } from "..";
export default defineDropTask({

View File

@ -49,7 +49,7 @@ export default defineDropTask({
// if response failed somehow
if (!response.ok) {
logger.info("Failed to check for update ", {
logger.info("Failed to check for update: %s", {
status: response.status,
body: response.body,
});

View File

@ -0,0 +1,58 @@
import { logger } from "../logging";
export type TaskRunContext = {
progress: (progress: number) => void;
logger: typeof logger;
};
export function wrapTaskContext(
context: TaskRunContext,
options: { min: number; max: number; prefix: string },
): TaskRunContext {
const child = context.logger.child({
prefix: options.prefix,
});
return {
progress(progress) {
if (progress > 100 || progress < 0) {
logger.warn("[wrapTaskContext] progress must be between 0 and 100");
}
// I was too tired to figure this out
// https://stackoverflow.com/a/929107
const oldRange = 100;
const newRange = options.max - options.min;
const adjustedProgress = (progress * newRange) / oldRange + options.min;
return context.progress(adjustedProgress);
},
logger: child,
};
}
// /**
// * Create a log message with a timestamp in the format YYYY-MM-DD HH:mm:ss.SSS UTC
// * @param message
// * @returns
// */
// function msgWithTimestamp(message: string): string {
// const now = new Date();
// const pad = (n: number, width = 2) => n.toString().padStart(width, "0");
// const year = now.getUTCFullYear();
// const month = pad(now.getUTCMonth() + 1);
// const day = pad(now.getUTCDate());
// const hours = pad(now.getUTCHours());
// const minutes = pad(now.getUTCMinutes());
// const seconds = pad(now.getUTCSeconds());
// const milliseconds = pad(now.getUTCMilliseconds(), 3);
// const log: typeof TaskLog.infer = {
// timestamp: `${year}-${month}-${day} ${hours}:${minutes}:${seconds}.${milliseconds} UTC`,
// message,
// };
// return JSON.stringify(log);
// }