feat(editor): add section settings property editor API and sidebar modal

This commit is contained in:
Daniel S
2026-08-09 21:24:16 +02:00
parent 58fc8e51cd
commit a35efb2726
4 changed files with 185 additions and 2 deletions

View File

@@ -0,0 +1,49 @@
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 { page_id, section_id, settings } = await request.json();
if (!page_id || !section_id || !settings) {
return new Response(JSON.stringify({ error: 'page_id, section_id und settings erforderlich' }), { status: 400 });
}
const draftPath = path.join(DATA_DIR, 'site.config.draft.json');
const livePath = path.join(DATA_DIR, 'site.config.json');
let configRaw: string;
try {
configRaw = await fs.readFile(draftPath, 'utf-8');
} catch {
configRaw = await fs.readFile(livePath, 'utf-8');
}
const config = JSON.parse(configRaw);
const targetPage = config.pages?.find((p: any) => p.id === page_id);
if (!targetPage) {
return new Response(JSON.stringify({ error: 'Seite nicht gefunden' }), { status: 404 });
}
// Sektion finden und Einstellungen aktualisieren
const targetSection = targetPage.sections?.find((sec: any) => sec.id === section_id);
if (!targetSection) {
return new Response(JSON.stringify({ error: 'Sektion nicht gefunden' }), { status: 404 });
}
targetSection.settings = { ...targetSection.settings, ...settings };
await fs.mkdir(DATA_DIR, { recursive: true });
await fs.writeFile(draftPath, JSON.stringify(config, null, 2), 'utf-8');
return new Response(JSON.stringify({ success: true, settings: targetSection.settings }), { status: 200 });
} catch (error) {
return new Response(JSON.stringify({ error: 'Fehler beim Aktualisieren der Sektions-Einstellungen' }), { status: 500 });
}
};