feat: export Catalog Studio assets and SQL to catalog repository

This commit is contained in:
Simo committed 2026-09-05 11:49:00 +02:00
1 parent bfbf244141
commit 9ec9ab31ad
21 files changed
+1811 -514

No files matched your search

+54
View File
@@ -0,0 +1,54 @@
import { promises as fs } from "node:fs";
import path from "node:path";
import { CatalogExportQueue } from "./catalog-git-core";
export function catalogExportEnabled() {
return Boolean(process.env.CATALOG_GIT_CHECKOUT?.trim());
}
export function catalogExportQueue() {
return new CatalogExportQueue(
process.env.CATALOG_GIT_STATE_DIR ||
path.join(process.cwd(), "storage", "catalog-git"),
);
}
export function isCatalogMutation(method: string, pathname: string) {
return (
["POST", "PUT", "PATCH", "DELETE"].includes(method) &&
(pathname.startsWith("/api/admin/import/") ||
pathname.startsWith("/api/admin/catalog/") ||
pathname.startsWith("/api/admin/furni/") ||
pathname.startsWith("/api/admin/furniture/"))
);
}
export async function catalogExportStatus() {
const q = catalogExportQueue();
if (!catalogExportEnabled()) return { enabled: false, pending: 0, active: 0 };
const entries = await q.entries();
let last: { commit?: string; finishedAt?: string; error?: string } = {};
try {
last = JSON.parse(
await fs.readFile(path.join(q.root, "status.json"), "utf8"),
);
} catch (error) {
if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error;
}
return {
enabled: true,
pending: entries.filter((f) => f.endsWith(".pending")).length,
active: entries.filter((f) => f.endsWith(".active")).length,
running: entries.includes("worker.lock"),
...last,
};
}
export async function withCatalogExport<T>(
operation: () => Promise<T>,
): Promise<T> {
if (!catalogExportEnabled()) return operation();
const finish = await catalogExportQueue().begin();
try {
return await operation();
} finally {
await finish();
}
}