- getBooksWithAudioCount() in pocketbase.ts aggregates done audio_jobs, deduplicates by chapter per slug, caches 5 min - GET /api/audio/books endpoint - home page: readyToListen shelf with headphones badge, chapter count, Listen button, hideable - /listen page: full grid with search, sort (most narrated / A-Z / recent), empty state
18 lines
567 B
TypeScript
18 lines
567 B
TypeScript
import { json } from '@sveltejs/kit';
|
|
import type { RequestHandler } from './$types';
|
|
import { getBooksWithAudioCount } from '$lib/server/pocketbase';
|
|
|
|
/**
|
|
* GET /api/audio/books
|
|
* Returns books that have at least one completed narrated chapter,
|
|
* sorted by number of narrated chapters descending.
|
|
* Cached 5 minutes at the CDN/proxy level.
|
|
*/
|
|
export const GET: RequestHandler = async () => {
|
|
const entries = await getBooksWithAudioCount(100).catch(() => []);
|
|
return json(
|
|
{ books: entries },
|
|
{ headers: { 'Cache-Control': 'public, max-age=300' } }
|
|
);
|
|
};
|