import { json, readJsonBody, requireAdmin } from "../../../../_lib/auth"; import { syncAlbum, syncAll } from "../../../../_lib/photos"; import { readSettings } from "../../../../_lib/store"; export const dynamic = "force-dynamic"; /** Syncs one album ({ id }) or all of them, and waits for the result. */ export async function POST(request: Request) { const denied = await requireAdmin(request, { mutating: true }); if (denied) return denied; const body = await readJsonBody<{ id?: string }>(request); if (body?.id) { const album = (await readSettings()).photos.albums.find((entry) => entry.id === body.id); if (!album) return json({ error: "Unknown album." }, 404); const index = await syncAlbum(album); return json({ ok: !index.lastError || index.photos.length > 0, photoCount: index.photos.length, lastError: index.lastError }); } await syncAll(); return json({ ok: true }); }