32f06297a6
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XNQ8ghPfzAfsyVYd6HgFb6
24 lines
1.1 KiB
TypeScript
24 lines
1.1 KiB
TypeScript
import type { APIRoute } from 'astro';
|
|
import { storageStats, runRetention, purgeSources, mirrorAllToNas, rebuildThumbs } from '../../../lib/maintenance';
|
|
import { one } from '../../../lib/db';
|
|
|
|
export const prerender = false;
|
|
const json = (b: unknown, s = 200) =>
|
|
new Response(JSON.stringify(b), { status: s, headers: { 'Content-Type': 'application/json' } });
|
|
|
|
export const GET: APIRoute = async () => json({ stats: await storageStats() });
|
|
|
|
// POST { action: 'retention' | 'purge_sources' }
|
|
export const POST: APIRoute = async ({ request }) => {
|
|
const b = await request.json().catch(() => ({}));
|
|
if (b.action === 'purge_sources') return json(await purgeSources());
|
|
if (b.action === 'mirror_all') return json(await mirrorAllToNas());
|
|
if (b.action === 'rebuild_thumbs') return json(await rebuildThumbs());
|
|
if (b.action === 'retention') {
|
|
const s = await one<{ retention_days: number | null }>('SELECT retention_days FROM settings WHERE id=1');
|
|
if (!s?.retention_days) return json({ error: 'Keine Aufbewahrungsfrist gesetzt.' }, 400);
|
|
return json(await runRetention(s.retention_days));
|
|
}
|
|
return json({ error: 'Unbekannte Aktion.' }, 400);
|
|
};
|