surface audio-ready chapters: headphones badge on chapter list, instant-play prompt on reader
- getReadyChaptersForSlug(slug, preferredVoice) in pocketbase.ts: per-slug done jobs map, cached 60s, prefers user's voice - GET /api/audio/chapters?slug=&voice= endpoint - Chapter list (/books/[slug]/chapters): amber headphones icon on ready rows, play button for instant listen, banner showing ready count - Chapter reader: audioReady + availableVoice from server load; 'Audio ready — Listen now' banner shown when audio exists and player is not yet active; sets voice preference before expanding player
This commit is contained in:
18
ui/src/routes/api/audio/chapters/+server.ts
Normal file
18
ui/src/routes/api/audio/chapters/+server.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { json, error } from '@sveltejs/kit';
|
||||
import type { RequestHandler } from './$types';
|
||||
import { getReadyChaptersForSlug } from '$lib/server/pocketbase';
|
||||
|
||||
export const GET: RequestHandler = async ({ url }) => {
|
||||
const slug = url.searchParams.get('slug') ?? '';
|
||||
if (!slug) error(400, 'slug is required');
|
||||
|
||||
const voice = url.searchParams.get('voice') ?? '';
|
||||
const readyMap = await getReadyChaptersForSlug(slug, voice);
|
||||
|
||||
// Return array of { chapter, voice } pairs
|
||||
const chapters = [...readyMap.entries()].map(([chapter, v]) => ({ chapter, voice: v }));
|
||||
|
||||
return json({ chapters }, {
|
||||
headers: { 'Cache-Control': 'public, max-age=60' }
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user