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

+49 -49
View File
@@ -1,94 +1,94 @@
import { withAdmin } from "@/lib/api-handler";
import { apiError, apiOk } from "@/lib/api-response";
import { PERMS } from "@/lib/permissions";
import { logAudit } from "@/lib/services/audit";
import { getClonableClassnames, getCloneList, getCloneStats } from "@/lib/services/clone-import";
import { deleteSource, getSource, listSources, upsertSource } from "@/lib/services/clone-sources";
import { withAdmin } from '@/lib/api-handler'
import { apiError, apiOk } from '@/lib/api-response'
import { PERMS } from '@/lib/permissions'
import { logAudit } from '@/lib/services/audit'
import { getClonableClassnames, getCloneList, getCloneStats } from '@/lib/services/clone-import'
import { deleteSource, getSource, listSources, upsertSource } from '@/lib/services/clone-sources'
// GET ?action=sources → list presets
// GET ?source=<id>&search=&page=&perPage= → { items, meta, stats }
export const GET = withAdmin({ permission: PERMS.ASSETS_IMPORT }, async (request) => {
const sp = request.nextUrl.searchParams;
const sp = request.nextUrl.searchParams
if (sp.get("action") === "sources") {
return apiOk({ sources: await listSources() });
if (sp.get('action') === 'sources') {
return apiOk({ sources: await listSources() })
}
const sourceId = sp.get("source");
if (!sourceId) return apiError("Missing source or action", 400);
const sourceId = sp.get('source')
if (!sourceId) return apiError('Missing source or action', 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)
// GET ?source=<id>&action=clonable → all not-yet-present classnames (for "clone all")
if (sp.get("action") === "clonable") {
return apiOk({ classnames: await getClonableClassnames(source) });
if (sp.get('action') === 'clonable') {
return apiOk({ classnames: await getClonableClassnames(source) })
}
const search = sp.get("search") || "";
const page = Math.max(Number.parseInt(sp.get("page") || "1", 10) || 1, 1);
const perPage = Math.min(Math.max(Number.parseInt(sp.get("perPage") || "50", 10) || 50, 1), 200);
const filterParam = sp.get("filter");
const filter = filterParam === "missing" || filterParam === "present" ? filterParam : "all";
const search = sp.get('search') || ''
const page = Math.max(Number.parseInt(sp.get('page') || '1', 10) || 1, 1)
const perPage = Math.min(Math.max(Number.parseInt(sp.get('perPage') || '50', 10) || 50, 1), 200)
const filterParam = sp.get('filter')
const filter = filterParam === 'missing' || filterParam === 'present' ? filterParam : 'all'
const [listResult, stats] = await Promise.all([
getCloneList({ source, search, page, perPage, filter }),
getCloneStats(source),
]);
])
return apiOk({ items: listResult.items, meta: listResult.meta, stats });
});
return apiOk({ items: listResult.items, meta: listResult.meta, stats })
})
// POST — upsert a source preset
export const POST = withAdmin({ permission: PERMS.ASSETS_IMPORT }, async (request, ctx) => {
const body = await request.json();
const { name, furnidataUrl, nitroBaseUrl, iconBaseUrl, id } = body as Record<string, string>;
const body = await request.json()
const { name, furnidataUrl, nitroBaseUrl, iconBaseUrl, id } = body as Record<string, string>
const isHttps = (u: string) => {
try {
return new URL(u).protocol === "https:";
return new URL(u).protocol === 'https:'
} catch {
return false;
return false
}
};
}
if (!name?.trim()) return apiError("name is required", 400);
if (!furnidataUrl?.trim()) return apiError("furnidataUrl is required", 400);
if (!nitroBaseUrl?.trim()) return apiError("nitroBaseUrl is required", 400);
if (!iconBaseUrl?.trim()) return apiError("iconBaseUrl is required", 400);
if (!name?.trim()) return apiError('name is required', 400)
if (!furnidataUrl?.trim()) return apiError('furnidataUrl is required', 400)
if (!nitroBaseUrl?.trim()) return apiError('nitroBaseUrl is required', 400)
if (!iconBaseUrl?.trim()) return apiError('iconBaseUrl is required', 400)
if (!isHttps(furnidataUrl) || !isHttps(nitroBaseUrl) || !isHttps(iconBaseUrl))
return apiError("Source URLs must be valid https:// URLs", 400);
return apiError('Source URLs must be valid https:// URLs', 400)
const entry = await upsertSource({ id, name, furnidataUrl, nitroBaseUrl, iconBaseUrl });
const entry = await upsertSource({ id, name, furnidataUrl, nitroBaseUrl, iconBaseUrl })
logAudit({
userId: ctx.session.user.id,
action: id ? "clone_source_update" : "clone_source_create",
target: "CloneSource",
action: id ? 'clone_source_update' : 'clone_source_create',
target: 'CloneSource',
targetId: 0,
after: { id: entry.id, name: entry.name },
});
})
return apiOk({ source: entry });
});
return apiOk({ source: entry })
})
// DELETE ?id=<id>
export const DELETE = withAdmin({ permission: PERMS.ASSETS_IMPORT }, async (request, ctx) => {
const id = request.nextUrl.searchParams.get("id");
if (!id) return apiError("Missing id", 400);
const id = request.nextUrl.searchParams.get('id')
if (!id) return apiError('Missing id', 400)
const source = await getSource(id);
if (!source) return apiError("Source not found", 404);
const source = await getSource(id)
if (!source) return apiError('Source not found', 404)
await deleteSource(id);
await deleteSource(id)
logAudit({
userId: ctx.session.user.id,
action: "clone_source_delete",
target: "CloneSource",
action: 'clone_source_delete',
target: 'CloneSource',
targetId: 0,
after: { id, name: source.name },
});
})
return apiOk({ id });
});
return apiOk({ id })
})