From 6f4cb467fddbed83b43a3654370d9945638e25ec Mon Sep 17 00:00:00 2001 From: ralksta Date: Fri, 29 May 2026 18:10:48 +0200 Subject: [PATCH] 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. --- app/api/admin/gallery/route.ts | 3 +++ app/api/admin/reload/route.ts | 2 ++ app/api/admin/settings/route.ts | 2 ++ 3 files changed, 7 insertions(+) diff --git a/app/api/admin/gallery/route.ts b/app/api/admin/gallery/route.ts index f35a927..aa39ae0 100644 --- a/app/api/admin/gallery/route.ts +++ b/app/api/admin/gallery/route.ts @@ -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); diff --git a/app/api/admin/reload/route.ts b/app/api/admin/reload/route.ts index a45cec3..157a96c 100644 --- a/app/api/admin/reload/route.ts +++ b/app/api/admin/reload/route.ts @@ -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' }); } diff --git a/app/api/admin/settings/route.ts b/app/api/admin/settings/route.ts index bffef3c..bcd91b0 100644 --- a/app/api/admin/settings/route.ts +++ b/app/api/admin/settings/route.ts @@ -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);