- Replace double inline player controls with compact 'now playing' indicator when mini-bar is active - Add user_settings PocketBase collection (auto_next, voice, speed) and audio_time field on progress - Add getSettings/saveSettings/setAudioTime/getAudioTime server functions - Add GET/PUT /api/settings and GET/PATCH /api/progress/audio-time API routes - Load settings server-side in layout and apply to audioStore on mount - Debounced 800ms effect persists settings changes to DB - Save audio currentTime on pause/end; restore position when replaying a chapter
33 lines
863 B
TypeScript
33 lines
863 B
TypeScript
import { redirect } from '@sveltejs/kit';
|
|
import type { LayoutServerLoad } from './$types';
|
|
import { getSettings } from '$lib/server/pocketbase';
|
|
import { log } from '$lib/server/logger';
|
|
|
|
// Routes that are accessible without being logged in
|
|
const PUBLIC_ROUTES = new Set(['/login']);
|
|
|
|
export const load: LayoutServerLoad = async ({ locals, url }) => {
|
|
if (!PUBLIC_ROUTES.has(url.pathname) && !locals.user) {
|
|
redirect(302, `/login`);
|
|
}
|
|
|
|
let settings = { autoNext: false, voice: 'af_bella', speed: 1.0 };
|
|
try {
|
|
const row = await getSettings(locals.sessionId, locals.user?.id);
|
|
if (row) {
|
|
settings = {
|
|
autoNext: row.auto_next ?? false,
|
|
voice: row.voice ?? 'af_bella',
|
|
speed: row.speed ?? 1.0
|
|
};
|
|
}
|
|
} catch (e) {
|
|
log.warn('layout', 'failed to load settings', { err: String(e) });
|
|
}
|
|
|
|
return {
|
|
user: locals.user,
|
|
settings
|
|
};
|
|
};
|