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

/**
 * GET /api/audio/slugs
 * Returns the list of book slugs that have at least one completed audio chapter.
 * Cached for 5 minutes at the CDN/proxy level.
 */
export const GET: RequestHandler = async () => {
	const slugs = await getSlugsWithAudio().catch(() => new Set<string>());
	return json(
		{ slugs: [...slugs] },
		{ headers: { 'Cache-Control': 'public, max-age=300' } }
	);
};
