Support Gitea configuration and safe Catalog Studio furniture completion
This commit is contained in:
1 parent
26f071117b
commit
9f791ba284
22 files changed
+1120
-166
No files matched your search
@@ -1,15 +1,19 @@
|
||||
import { promises as fs } from "node:fs";
|
||||
import path from "node:path";
|
||||
import {
|
||||
catalogStateRoot,
|
||||
readManagedCatalogConfig,
|
||||
} from "./catalog-git-config";
|
||||
import { CatalogExportQueue } from "./catalog-git-core";
|
||||
|
||||
export function catalogExportEnabled() {
|
||||
return Boolean(process.env.CATALOG_GIT_CHECKOUT?.trim());
|
||||
const config = readManagedCatalogConfig();
|
||||
return config
|
||||
? config.enabled
|
||||
: 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"),
|
||||
);
|
||||
return new CatalogExportQueue(catalogStateRoot());
|
||||
}
|
||||
export function isCatalogMutation(method: string, pathname: string) {
|
||||
return (
|
||||
@@ -45,10 +49,30 @@ export async function withCatalogExport<T>(
|
||||
operation: () => Promise<T>,
|
||||
): Promise<T> {
|
||||
if (!catalogExportEnabled()) return operation();
|
||||
const finish = await catalogExportQueue().begin();
|
||||
const finish = await beginCatalogExport();
|
||||
try {
|
||||
return await operation();
|
||||
} finally {
|
||||
await finish();
|
||||
}
|
||||
}
|
||||
|
||||
export async function scheduleCatalogExport() {
|
||||
if (!readManagedCatalogConfig()?.enabled) return;
|
||||
try {
|
||||
const { after } = await import("next/server");
|
||||
after(async () => {
|
||||
const { runCatalogExport } = await import("./catalog-git-export");
|
||||
await runCatalogExport();
|
||||
});
|
||||
} catch {
|
||||
/* Standalone worker contexts use their scheduled retry. */
|
||||
}
|
||||
}
|
||||
export async function beginCatalogExport() {
|
||||
const finish = await catalogExportQueue().begin();
|
||||
return async () => {
|
||||
await finish();
|
||||
await scheduleCatalogExport();
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user