import { json, error } from '@sveltejs/kit';
import type { RequestHandler } from './$types';
import { listAudioJobs } from '$lib/server/pocketbase';

/**
 * GET /api/admin/audio-jobs
 * Returns the current audio jobs list (served from 30 s Valkey cache).
 * Used by the admin audio page for lightweight polling instead of invalidateAll().
 */
export const GET: RequestHandler = async ({ locals }) => {
	if (!locals.user || locals.user.role !== 'admin') {
		throw error(403, 'Forbidden');
	}
	const jobs = await listAudioJobs().catch(() => []);
	return json({ jobs });
};
