Migrate game metadata import to task system #90 (#103)

* feat: move game import to new task system

* fix: sizing issue with new task UI

* fix: lint

* feat: add pcgamingwiki task
This commit is contained in:
DecDuck
2025-06-08 11:37:24 +10:00
committed by GitHub
parent 9f8890020f
commit de438b93d5
9 changed files with 307 additions and 187 deletions

View File

@@ -5,6 +5,7 @@ This is used as a utility in metadata handling, so we only fetch the objects if
import type { Readable } from "stream";
import { randomUUID } from "node:crypto";
import objectHandler from ".";
import type { TaskRunContext } from "../tasks";
export type TransactionDataType = string | Readable | Buffer;
type TransactionTable = Map<string, TransactionDataType>; // ID to data
@@ -20,6 +21,7 @@ export class ObjectTransactionalHandler {
new(
metadata: { [key: string]: string },
permissions: Array<string>,
context?: TaskRunContext,
): [Register, Pull, Dump] {
const transactionId = randomUUID();
@@ -35,7 +37,16 @@ export class ObjectTransactionalHandler {
const pull = async () => {
const transaction = this.record.get(transactionId);
if (!transaction) return;
let progress = 0;
const increment = (1 / transaction.size) * 100;
for (const [id, data] of transaction) {
if (typeof data === "string") {
context?.log(`Importing object from "${data}"`);
} else {
context?.log(`Importing raw object...`);
}
await objectHandler.createFromSource(
id,
() => {
@@ -47,6 +58,8 @@ export class ObjectTransactionalHandler {
metadata,
permissions,
);
progress += increment;
context?.progress(progress);
}
};