feat(admin): add global site settings API, tests and dashboard UI
All checks were successful
Production Build & Deploy / build-and-deploy (push) Successful in 35s

This commit is contained in:
Daniel S
2026-08-09 21:26:15 +02:00
parent a35efb2726
commit 03ceb3de7f
4 changed files with 153 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
import type { APIRoute } from 'astro';
import fs from 'node:fs/promises';
import path from 'node:path';
export const prerender = false;
const DATA_DIR = process.env.DATA_DIR || path.join(process.cwd(), 'app', 'data');
export const POST: APIRoute = async ({ request }) => {
try {
const { site_info, navigation } = await request.json();
if (!site_info || typeof site_info !== 'object') {
return new Response(JSON.stringify({ error: 'Gültige site_info Daten erforderlich' }), { status: 400 });
}
const configPath = path.join(DATA_DIR, 'site.config.json');
let config: any = {};
try {
const raw = await fs.readFile(configPath, 'utf-8');
config = JSON.parse(raw);
} catch {
// Fallback bei neuer Instanz
config = { site_info: {}, pages: [], navigation: [] };
}
// Update der globalen Eigenschaften
config.site_info = { ...config.site_info, ...site_info };
if (Array.isArray(navigation)) {
config.navigation = navigation;
}
await fs.mkdir(DATA_DIR, { recursive: true });
await fs.writeFile(configPath, JSON.stringify(config, null, 2), 'utf-8');
return new Response(JSON.stringify({ success: true, site_info: config.site_info }), { status: 200 });
} catch (error) {
return new Response(JSON.stringify({ error: 'Fehler beim Speichern der Einstellungen' }), { status: 500 });
}
};