src/lib/server/paths.ts: zentrale Auflösung der env-vars; vorher 6× IMAGE_DIR und 2× DATABASE_PATH dupliziert mit identischen Defaults. Migrierte Sites: - src/lib/server/db/index.ts (DATABASE_PATH + IMAGE_DIR) - src/routes/api/admin/backup/+server.ts - src/routes/api/domains/+server.ts - src/routes/api/domains/[id]/+server.ts - src/routes/api/recipes/import/+server.ts - src/routes/api/recipes/[id]/image/+server.ts - src/routes/images/[filename]/+server.ts ARCHITECTURE.md: - 49 Flachwitze -> 150 (waren tatsaechlich 150) - 'search/' Route entfernt — wurde nie als eigene Route gebaut, Suche laeuft direkt auf der Homepage via API-Calls Findings aus zweiter Review-Runde (siehe OPEN-ISSUES-NEXT.md)
21 lines
764 B
TypeScript
21 lines
764 B
TypeScript
import type { RequestHandler } from './$types';
|
|
import { json } from '@sveltejs/kit';
|
|
import { z } from 'zod';
|
|
import { getDb } from '$lib/server/db';
|
|
import { validateBody } from '$lib/server/api-helpers';
|
|
import { importRecipe } from '$lib/server/recipes/importer';
|
|
import { mapImporterError } from '$lib/server/errors';
|
|
import { IMAGE_DIR } from '$lib/server/paths';
|
|
|
|
const ImportSchema = z.object({ url: z.string().url() });
|
|
|
|
export const POST: RequestHandler = async ({ request }) => {
|
|
const data = validateBody(await request.json().catch(() => null), ImportSchema);
|
|
try {
|
|
const result = await importRecipe(getDb(), IMAGE_DIR, data.url);
|
|
return json({ id: result.id, duplicate: result.duplicate });
|
|
} catch (e) {
|
|
mapImporterError(e);
|
|
}
|
|
};
|