import { json, readJsonBody, requireAdmin } from "../../../_lib/auth"; import { syncAll } from "../../../_lib/photos"; import { listHistory, readHistorySnapshot, saveSettings } from "../../../_lib/store"; export const dynamic = "force-dynamic"; export async function GET(request: Request) { const denied = await requireAdmin(request); if (denied) return denied; return json({ history: await listHistory() }); } /** Reverts calendars and photo settings to a snapshot. The current state is itself snapshotted first, so a revert can be undone. */ export async function POST(request: Request) { const denied = await requireAdmin(request, { mutating: true }); if (denied) return denied; const body = await readJsonBody<{ id?: string }>(request); const snapshot = body?.id ? await readHistorySnapshot(body.id) : null; if (!snapshot) return json({ error: "That version no longer exists." }, 404); const saved = await saveSettings({ calendars: snapshot.calendars, photos: snapshot.photos }, `Reverted to version from ${snapshot.updatedAt}`); console.log(`[admin] settings reverted to ${body?.id}`); void syncAll(); // re-fetch any album the restored version brings back return json({ ok: true, updatedAt: saved.updatedAt }); }