fix: revalidate all pages on admin save so hero/config changes appear immediately

Add revalidatePath('/', 'layout') calls to gallery save, settings save,
and reload routes. This tells Next.js to purge any cached page responses
so the next browser refresh picks up the new hero images and config.
This commit is contained in:
ralksta
2026-05-29 18:10:48 +02:00
parent 066e6f5af6
commit 6f4cb467fd
3 changed files with 7 additions and 0 deletions

View File

@@ -1,4 +1,5 @@
import { NextResponse } from 'next/server';
import { revalidatePath } from 'next/cache';
import { isAdminAuthenticated, isAdminEnabled } from '@/lib/admin/auth';
import { readGalleryYaml, writeGalleryYaml } from '@/lib/admin/yaml-service';
import { invalidateConfigCache } from '@/lib/config';
@@ -42,6 +43,8 @@ export async function PUT(request: Request) {
await writeGalleryYaml(gallery);
invalidateConfigCache();
immich.invalidateAll();
// Revalidate all pages so the homepage picks up new hero images immediately
revalidatePath('/', 'layout');
return NextResponse.json({ success: true, message: 'Saved successfully. Backup of previous version created.' });
} catch (err) {
console.error('[Admin] Failed to write gallery.yaml:', err);

View File

@@ -1,4 +1,5 @@
import { NextResponse } from 'next/server';
import { revalidatePath } from 'next/cache';
import { isAdminAuthenticated, isAdminEnabled } from '@/lib/admin/auth';
import { invalidateConfigCache } from '@/lib/config';
import { immich } from '@/lib/immich';
@@ -14,6 +15,7 @@ export async function POST() {
invalidateConfigCache();
immich.invalidateAll();
revalidatePath('/', 'layout');
return NextResponse.json({ success: true, message: 'Config and cache reloaded' });
}

View File

@@ -1,4 +1,5 @@
import { NextResponse } from 'next/server';
import { revalidatePath } from 'next/cache';
import { isAdminAuthenticated, isAdminEnabled } from '@/lib/admin/auth';
import { readSettingsYaml, writeSettingsYaml } from '@/lib/admin/yaml-service';
import { invalidateConfigCache } from '@/lib/config';
@@ -38,6 +39,7 @@ export async function PUT(request: Request) {
await writeSettingsYaml(settings);
invalidateConfigCache();
immich.invalidateAll();
revalidatePath('/', 'layout');
return NextResponse.json({ success: true, message: 'Saved successfully. Backup of previous version created.' });
} catch (err) {
console.error('[Admin] Failed to write settings.yaml:', err);