Introduces a logger.ts module emitting slog-compatible JSON lines to stderr. Replaces silent catch blocks and console.error calls throughout minio.ts, pocketbase.ts, hooks.server.ts, login, books, browse, and all API routes so auth/registration failures, MinIO presign errors, and scraper proxy failures are now visible in container logs.
28 lines
777 B
TypeScript
28 lines
777 B
TypeScript
import type { PageServerLoad } from './$types';
|
|
import { listBooks, allProgress } from '$lib/server/pocketbase';
|
|
import { log } from '$lib/server/logger';
|
|
|
|
export const load: PageServerLoad = async ({ locals }) => {
|
|
let books: Awaited<ReturnType<typeof listBooks>>;
|
|
let progressList: Awaited<ReturnType<typeof allProgress>>;
|
|
|
|
try {
|
|
[books, progressList] = await Promise.all([
|
|
listBooks(),
|
|
allProgress(locals.sessionId)
|
|
]);
|
|
} catch (e) {
|
|
log.error('books', 'failed to load books or progress', { err: String(e) });
|
|
books = [];
|
|
progressList = [];
|
|
}
|
|
|
|
// Build a quick lookup: slug → last chapter read
|
|
const progressMap: Record<string, number> = {};
|
|
for (const p of progressList) {
|
|
progressMap[p.slug] = p.chapter;
|
|
}
|
|
|
|
return { books, progressMap };
|
|
};
|