Files
immich-folio/app/api/admin/gallery/route.ts
ralksta b4fa37d680 fix: admin panel light/dark theme support, improved contrast, and backup confirmation
a) Admin panel now respects the site's light/dark theme toggle via CSS
   custom properties that respond to [data-theme='light'] on <html>.
   All hardcoded dark colors replaced with semantic CSS variables.

b) Improved contrast in dark mode: secondary text changed from #666/#555
   to #a0a0a0, muted text from #555 to #707070. All text is now clearly
   readable against dark backgrounds.

c) Backup system was already implemented in yaml-service.ts (creates
   timestamped backups in content/.backups/ before each save, keeps last
   10 versions). Now the UI shows a confirmation message that a backup
   was created after each successful save.
2026-05-29 17:20:56 +02:00

49 lines
1.8 KiB
TypeScript

import { NextResponse } from 'next/server';
import { isAdminAuthenticated, isAdminEnabled } from '@/lib/admin/auth';
import { readGalleryYaml, writeGalleryYaml } from '@/lib/admin/yaml-service';
import { invalidateConfigCache } from '@/lib/config';
import type { GalleryYaml } from '@/lib/config/schema';
/** GET: Read current gallery.yaml config. */
export async function GET() {
if (!isAdminEnabled()) {
return NextResponse.json({ error: 'Admin not enabled' }, { status: 403 });
}
if (!(await isAdminAuthenticated())) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
}
const gallery = await readGalleryYaml();
return NextResponse.json({ gallery: gallery || { hero: [], albums: [], subpages: [] } });
}
/** PUT: Write gallery.yaml config. */
export async function PUT(request: Request) {
if (!isAdminEnabled()) {
return NextResponse.json({ error: 'Admin not enabled' }, { status: 403 });
}
if (!(await isAdminAuthenticated())) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
}
const body = await request.json().catch(() => null);
if (!body?.gallery) {
return NextResponse.json({ error: 'Missing gallery data' }, { status: 400 });
}
// Validate basic structure
const gallery = body.gallery as GalleryYaml;
if (!Array.isArray(gallery.hero) && typeof gallery.hero !== 'string' && gallery.hero != null) {
return NextResponse.json({ error: 'Invalid hero format' }, { status: 400 });
}
try {
await writeGalleryYaml(gallery);
invalidateConfigCache();
return NextResponse.json({ success: true, message: 'Saved successfully. Backup of previous version created.' });
} catch (err) {
console.error('[Admin] Failed to write gallery.yaml:', err);
return NextResponse.json({ error: 'Failed to save gallery config' }, { status: 500 });
}
}