Files
libnovel/ui/src/routes/api/audio/books/+server.ts
root 015cb8a0cd
Some checks failed
Release / Test backend (push) Successful in 53s
Release / Check ui (push) Failing after 45s
Release / Docker (push) Has been skipped
Release / Gitea Release (push) Has been skipped
add Ready to Listen feature: audio book shelf on home + /listen browse page
- 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
2026-04-12 10:18:40 +05:00

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' } }
);
};