revert fb8e77bb68
Local Build and Deploy / deploy (push) Successful in 1m11s

revert style: clean up code with prettier and eslint
This commit is contained in:
remco committed 2026-07-12 21:02:03 +02:00
1 parent 27de078f54
commit e85e4d74ea
378 files changed
+20710 -22428

No files matched your search

+33 -33
View File
@@ -1,71 +1,71 @@
import { withAdmin } from "@/lib/api-handler";
import { apiError } from "@/lib/api-response";
import { PERMS } from "@/lib/permissions";
import { logAudit } from "@/lib/services/audit";
import { cloneSingleFurni, fetchSourceFurnidata } from "@/lib/services/clone-import";
import { getSource } from "@/lib/services/clone-sources";
import { runSseBatch } from "@/lib/services/import/core/sse-batch";
import { withAdmin } from '@/lib/api-handler'
import { apiError } from '@/lib/api-response'
import { PERMS } from '@/lib/permissions'
import { logAudit } from '@/lib/services/audit'
import { cloneSingleFurni, fetchSourceFurnidata } from '@/lib/services/clone-import'
import { getSource } from '@/lib/services/clone-sources'
import { runSseBatch } from '@/lib/services/import/core/sse-batch'
interface BatchItem {
classname: string;
classname: string
}
export const POST = withAdmin({ permission: PERMS.ASSETS_IMPORT }, async (request, ctx) => {
const body = await request.json();
const sourceId: string = body.sourceId || "";
const rawClassnames: string[] = body.classnames || [];
const body = await request.json()
const sourceId: string = body.sourceId || ''
const rawClassnames: string[] = body.classnames || []
if (!sourceId) return apiError("Missing sourceId", 400);
if (rawClassnames.length === 0) return apiError("No classnames to clone", 400);
if (!sourceId) return apiError('Missing sourceId', 400)
if (rawClassnames.length === 0) return apiError('No classnames to clone', 400)
const source = await getSource(sourceId);
if (!source) return apiError("Source not found", 404);
const source = await getSource(sourceId)
if (!source) return apiError('Source not found', 404)
// Fetch furnidata once so we can resolve entries by classname.
let allEntries: Awaited<ReturnType<typeof fetchSourceFurnidata>>;
let allEntries: Awaited<ReturnType<typeof fetchSourceFurnidata>>
try {
allEntries = await fetchSourceFurnidata(source.furnidataUrl);
allEntries = await fetchSourceFurnidata(source.furnidataUrl)
} catch (err) {
return apiError(`Failed to fetch furnidata: ${(err as Error).message}`, 502);
return apiError(`Failed to fetch furnidata: ${(err as Error).message}`, 502)
}
const entryMap = new Map(allEntries.map((e) => [e.classname, e]));
const entryMap = new Map(allEntries.map((e) => [e.classname, e]))
// Deduplicate classnames preserving order.
const seen = new Set<string>();
const items: BatchItem[] = [];
const seen = new Set<string>()
const items: BatchItem[] = []
for (const cn of rawClassnames) {
if (!seen.has(cn)) {
seen.add(cn);
items.push({ classname: cn });
seen.add(cn)
items.push({ classname: cn })
}
}
if (items.length > 500) return apiError("Too many classnames (max 500)", 400);
if (items.length > 500) return apiError('Too many classnames (max 500)', 400)
return runSseBatch<BatchItem>({
items,
concurrency: body.concurrency || 2,
labelOf: (it) => it.classname,
worker: async (it, _index, report) => {
const entry = entryMap.get(it.classname);
const entry = entryMap.get(it.classname)
if (!entry) {
return { ok: false, error: "classname not found in source furnidata" };
return { ok: false, error: 'classname not found in source furnidata' }
}
const result = await cloneSingleFurni({ source, entry, onProgress: report });
const result = await cloneSingleFurni({ source, entry, onProgress: report })
if (result.ok) {
logAudit({
userId: ctx.session.user.id,
action: "clone_furni",
target: "FurniAsset",
action: 'clone_furni',
target: 'FurniAsset',
targetId: 0,
after: { classname: it.classname, sourceId, sourceName: source.name },
});
})
}
return { ok: result.ok, warnings: result.warnings, error: result.error };
return { ok: result.ok, warnings: result.warnings, error: result.error }
},
});
});
})
})