refactor(server): IMAGE_DIR/DATABASE_PATH zentralisieren + Doku-Drift fixen
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)
This commit is contained in:
@@ -1,12 +1,10 @@
|
||||
import type { RequestHandler } from './$types';
|
||||
import { createBackupStream, backupFilename } from '$lib/server/backup/export';
|
||||
import { DATABASE_PATH, IMAGE_DIR } from '$lib/server/paths';
|
||||
import { Readable } from 'node:stream';
|
||||
|
||||
const DB_PATH = process.env.DATABASE_PATH ?? './data/kochwas.db';
|
||||
const IMAGE_DIR = process.env.IMAGE_DIR ?? './data/images';
|
||||
|
||||
export const GET: RequestHandler = async () => {
|
||||
const archive = createBackupStream({ dbPath: DB_PATH, imagesDir: IMAGE_DIR });
|
||||
const archive = createBackupStream({ dbPath: DATABASE_PATH, imagesDir: IMAGE_DIR });
|
||||
const filename = backupFilename();
|
||||
return new Response(Readable.toWeb(archive) as ReadableStream, {
|
||||
status: 200,
|
||||
|
||||
@@ -5,6 +5,7 @@ import { getDb } from '$lib/server/db';
|
||||
import { validateBody } from '$lib/server/api-helpers';
|
||||
import { addDomain, listDomains, setDomainFavicon } from '$lib/server/domains/repository';
|
||||
import { ensureFavicons, fetchAndStoreFavicon } from '$lib/server/domains/favicons';
|
||||
import { IMAGE_DIR } from '$lib/server/paths';
|
||||
|
||||
const CreateSchema = z.object({
|
||||
domain: z.string().min(3).max(253),
|
||||
@@ -12,8 +13,6 @@ const CreateSchema = z.object({
|
||||
added_by_profile_id: z.number().int().positive().nullable().optional()
|
||||
});
|
||||
|
||||
const IMAGE_DIR = process.env.IMAGE_DIR ?? './data/images';
|
||||
|
||||
export const GET: RequestHandler = async () => {
|
||||
const db = getDb();
|
||||
// Favicons lazy nachziehen — beim zweiten Aufruf gibt es nichts mehr zu tun.
|
||||
|
||||
@@ -9,8 +9,7 @@ import {
|
||||
setDomainFavicon
|
||||
} from '$lib/server/domains/repository';
|
||||
import { fetchAndStoreFavicon } from '$lib/server/domains/favicons';
|
||||
|
||||
const IMAGE_DIR = process.env.IMAGE_DIR ?? './data/images';
|
||||
import { IMAGE_DIR } from '$lib/server/paths';
|
||||
|
||||
const UpdateSchema = z.object({
|
||||
domain: z.string().min(3).max(253).optional(),
|
||||
|
||||
@@ -7,8 +7,8 @@ import { join } from 'node:path';
|
||||
import { getDb } from '$lib/server/db';
|
||||
import { parsePositiveIntParam } from '$lib/server/api-helpers';
|
||||
import { getRecipeById, updateImagePath } from '$lib/server/recipes/repository';
|
||||
import { IMAGE_DIR } from '$lib/server/paths';
|
||||
|
||||
const IMAGE_DIR = process.env.IMAGE_DIR ?? './data/images';
|
||||
const MAX_BYTES = 10 * 1024 * 1024;
|
||||
|
||||
const EXT_BY_MIME: Record<string, string> = {
|
||||
|
||||
@@ -5,11 +5,10 @@ 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() });
|
||||
|
||||
const IMAGE_DIR = process.env.IMAGE_DIR ?? './data/images';
|
||||
|
||||
export const POST: RequestHandler = async ({ request }) => {
|
||||
const data = validateBody(await request.json().catch(() => null), ImportSchema);
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user