2026-05-31 21:17:52 +02:00
|
|
|
import { NextResponse } from 'next/server';
|
|
|
|
|
import { isAdminAuthenticated, isAdminEnabled } from '@/lib/admin/auth';
|
|
|
|
|
import { immich } from '@/lib/immich';
|
|
|
|
|
import { cache } from '@/lib/cache';
|
|
|
|
|
import { listBackups, readGalleryYaml, readSettingsYaml } from '@/lib/admin/yaml-service';
|
|
|
|
|
|
|
|
|
|
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 });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 1. Immich Connection Status
|
|
|
|
|
let immichOk = false;
|
|
|
|
|
try {
|
|
|
|
|
immichOk = await immich.ping();
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.error('[Admin API] Immich ping failed:', err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 2. Config Health Check
|
|
|
|
|
let galleryValid = false;
|
chore(release): v0.10.0 (#400)
Photo Essay mode, client proofing, studio-modern preset, admin panel overhaul, watermark, cookieless analytics, subpage toggle, SEO title templates. Analytics API now admin-only, Trivy scan on publish. Album order mirrors the Immich timeline; map theme, admin status panel, lightbox counter and Docker health check fixed.
See CHANGELOG.md for the full list and the health-check upgrade note.
2026-08-10 09:56:20 +02:00
|
|
|
// settings.yaml is optional — getConfig() falls back to defaults when it is
|
|
|
|
|
// absent, so a missing file is a valid installation, not a fault. Only a file
|
|
|
|
|
// that exists and cannot be parsed counts as degraded: readSettingsYaml()
|
|
|
|
|
// returns null for ENOENT and rethrows everything else.
|
|
|
|
|
let settingsValid = true;
|
|
|
|
|
|
2026-05-31 21:17:52 +02:00
|
|
|
try {
|
|
|
|
|
const gallery = await readGalleryYaml();
|
|
|
|
|
galleryValid = !!gallery;
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.error('[Admin API] Gallery YAML parse failed:', err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
chore(release): v0.10.0 (#400)
Photo Essay mode, client proofing, studio-modern preset, admin panel overhaul, watermark, cookieless analytics, subpage toggle, SEO title templates. Analytics API now admin-only, Trivy scan on publish. Album order mirrors the Immich timeline; map theme, admin status panel, lightbox counter and Docker health check fixed.
See CHANGELOG.md for the full list and the health-check upgrade note.
2026-08-10 09:56:20 +02:00
|
|
|
await readSettingsYaml();
|
2026-05-31 21:17:52 +02:00
|
|
|
} catch (err) {
|
|
|
|
|
console.error('[Admin API] Settings YAML parse failed:', err);
|
chore(release): v0.10.0 (#400)
Photo Essay mode, client proofing, studio-modern preset, admin panel overhaul, watermark, cookieless analytics, subpage toggle, SEO title templates. Analytics API now admin-only, Trivy scan on publish. Album order mirrors the Immich timeline; map theme, admin status panel, lightbox counter and Docker health check fixed.
See CHANGELOG.md for the full list and the health-check upgrade note.
2026-08-10 09:56:20 +02:00
|
|
|
settingsValid = false;
|
2026-05-31 21:17:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 3. Backup Info
|
|
|
|
|
const galleryBackups = await listBackups('gallery.yaml');
|
|
|
|
|
const settingsBackups = await listBackups('settings.yaml');
|
|
|
|
|
const backupCount = galleryBackups.length + settingsBackups.length;
|
chore(release): v0.10.0 (#400)
Photo Essay mode, client proofing, studio-modern preset, admin panel overhaul, watermark, cookieless analytics, subpage toggle, SEO title templates. Analytics API now admin-only, Trivy scan on publish. Album order mirrors the Immich timeline; map theme, admin status panel, lightbox counter and Docker health check fixed.
See CHANGELOG.md for the full list and the health-check upgrade note.
2026-08-10 09:56:20 +02:00
|
|
|
|
2026-05-31 21:17:52 +02:00
|
|
|
// Find timestamp of the latest backup
|
|
|
|
|
let lastBackup: string | null = null;
|
|
|
|
|
const allBackups = [...galleryBackups, ...settingsBackups].sort().reverse();
|
|
|
|
|
if (allBackups.length > 0) {
|
|
|
|
|
// Filename format: filename.yaml.2026-05-31T17-30-00-000Z.bak
|
|
|
|
|
const match = allBackups[0].match(/\d{4}-\d{2}-\d{2}T\d{2}-\d{2}-\d{2}/);
|
|
|
|
|
if (match) {
|
|
|
|
|
lastBackup = match[0].replace(/-/g, ':').replace(/(\d{4}):(\d{2}):(\d{2})T/, '$1-$2-$3T');
|
|
|
|
|
} else {
|
|
|
|
|
lastBackup = allBackups[0]; // fallback
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NextResponse.json({
|
|
|
|
|
immich: {
|
|
|
|
|
status: immichOk ? 'connected' : 'disconnected',
|
|
|
|
|
},
|
|
|
|
|
config: {
|
chore(release): v0.10.0 (#400)
Photo Essay mode, client proofing, studio-modern preset, admin panel overhaul, watermark, cookieless analytics, subpage toggle, SEO title templates. Analytics API now admin-only, Trivy scan on publish. Album order mirrors the Immich timeline; map theme, admin status panel, lightbox counter and Docker health check fixed.
See CHANGELOG.md for the full list and the health-check upgrade note.
2026-08-10 09:56:20 +02:00
|
|
|
status: galleryValid && settingsValid ? 'valid' : 'invalid',
|
2026-05-31 21:17:52 +02:00
|
|
|
gallery: galleryValid ? 'valid' : 'invalid',
|
|
|
|
|
settings: settingsValid ? 'valid' : 'invalid',
|
|
|
|
|
},
|
|
|
|
|
cache: {
|
|
|
|
|
size: cache.size,
|
|
|
|
|
},
|
|
|
|
|
backups: {
|
|
|
|
|
count: backupCount,
|
|
|
|
|
lastBackup,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|