feat(housekeeping): integrate studio operations
CI / check (pull_request) Successful in 38s
CI / release (pull_request) Skipped
CI / deploy (pull_request) Skipped

This commit is contained in:
Simo committed 2026-08-30 15:29:58 +02:00
1 parent 020c06f172
commit 2e95a106e0
36 files changed
+2296 -60

No files matched your search

+22 -7
View File
@@ -17,7 +17,9 @@ export async function writeBadgeToExternalTexts(
code: string,
name: string,
description: string,
signal?: AbortSignal,
): Promise<ImportBadgeResult> {
signal?.throwIfAborted();
const gamedataRoot = await getGamedataRoot();
if (!gamedataRoot) {
return {
@@ -35,6 +37,7 @@ export async function writeBadgeToExternalTexts(
const raw = await fs.readFile(extPath, "utf-8");
texts = JSON.parse(raw) as Record<string, string>;
} catch (err) {
if (signal?.aborted) throw err;
// File not present yet (fresh deployment) — start with an empty object.
if ((err as NodeJS.ErrnoException).code !== "ENOENT") {
console.warn(
@@ -49,6 +52,7 @@ export async function writeBadgeToExternalTexts(
}
texts = {};
}
signal?.throwIfAborted();
if (texts[nameKey] !== undefined) {
return {
@@ -63,9 +67,11 @@ export async function writeBadgeToExternalTexts(
try {
await fs.mkdir(path.dirname(extPath), { recursive: true });
signal?.throwIfAborted();
await fs.writeFile(extPath, JSON.stringify(texts, null, 4), "utf-8");
return { ok: true };
} catch (err) {
if (signal?.aborted) throw err;
console.warn(
"[import-badges] Failed to update ExternalTexts.json:",
(err as Error).message,
@@ -83,7 +89,9 @@ export async function upsertWebsiteBadge(
code: string,
name: string,
description: string,
signal?: AbortSignal,
): Promise<void> {
signal?.throwIfAborted();
const now = new Date();
await db
.insert(WebsiteBadges)
@@ -107,21 +115,28 @@ export async function upsertWebsiteBadge(
* Single import path: ExternalTexts.json + WebsiteBadges.
* Callers should gate with ASSETS_IMPORT.
*/
export async function importBadgeSynced(input: {
code: string;
name: string;
description: string;
}): Promise<ImportBadgeResult> {
export async function importBadgeSynced(
input: {
code: string;
name: string;
description: string;
},
signal?: AbortSignal,
): Promise<ImportBadgeResult> {
signal?.throwIfAborted();
const texts = await writeBadgeToExternalTexts(
input.code,
input.name,
input.description,
signal,
);
if (!texts.ok) return texts;
try {
await upsertWebsiteBadge(input.code, input.name, input.description);
} catch {
signal?.throwIfAborted();
await upsertWebsiteBadge(input.code, input.name, input.description, signal);
} catch (error) {
if (signal?.aborted) throw error;
return { ok: false, error: "Failed to import badge", status: 500 };
}