Files
EpicNext-Cms/src/lib/services/furni-sync-item.ts
T
Simo 13bd3695cb
CI / check (push) Successful in 2m5s
CI / deploy (push) Successful in 1m8s
CI / publish-container (push) Successful in 1m4s
feat(studio): recover matching Nitro sources and persist import phases
2026-09-11 10:22:06 +02:00

44 lines
1.3 KiB
TypeScript

import { eq } from "drizzle-orm";
import { db, ItemsBase } from "@/lib/db";
import type { ImportJobItem } from "@/lib/furni/import-job";
import { cloneSingleFurni } from "./clone-import";
import { getSource } from "./clone-sources";
import { importSingleFurni } from "./furni-import";
/** Called only inside the shared import lease and catalog export lock. */
export async function runSyncJobItem(
item: ImportJobItem,
onProgress?: (status: string) => void | Promise<void>,
) {
const [existing] = await db
.select({ id: ItemsBase.id })
.from(ItemsBase)
.where(eq(ItemsBase.itemName, item.classname))
.limit(1);
if (existing)
return {
ok: true,
itemId: existing.id,
warnings: ["Already present; synchronization skipped this item."],
};
if (item.cloneSourceId) {
const source = await getSource(item.cloneSourceId);
if (!source || !item.cloneEntry)
throw Error("Synchronization source no longer available");
const result = await cloneSingleFurni({
source,
entry: item.cloneEntry,
onProgress,
});
const [created] = result.ok
? await db
.select({ id: ItemsBase.id })
.from(ItemsBase)
.where(eq(ItemsBase.itemName, item.classname))
.limit(1)
: [];
return { ...result, itemId: created?.id };
}
return importSingleFurni({ ...item, repairExisting: false, onProgress });
}