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
All checks were successful
Production Build & Deploy / build-and-deploy (push) Successful in 35s
This commit is contained in:
41
src/pages/api/admin/settings/update.ts
Normal file
41
src/pages/api/admin/settings/update.ts
Normal 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 });
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user