chore: migrate to v3, Doppler secrets, clean up legacy code
Some checks failed
CI / v3 / Check ui (pull_request) Failing after 15s
CI / v3 / Test backend (pull_request) Failing after 16s
CI / v3 / Docker / backend (pull_request) Has been skipped
CI / v3 / Docker / runner (pull_request) Has been skipped
CI / v3 / Docker / ui (pull_request) Has been skipped
Some checks failed
CI / v3 / Check ui (pull_request) Failing after 15s
CI / v3 / Test backend (pull_request) Failing after 16s
CI / v3 / Docker / backend (pull_request) Has been skipped
CI / v3 / Docker / runner (pull_request) Has been skipped
CI / v3 / Docker / ui (pull_request) Has been skipped
- Remove all pre-v3 code: scraper, ui-v2, backend v1, ios v1+v2, legacy CI workflows - Flatten v3/ contents to repo root - Add Doppler secrets management (project=libnovel, config=prd) - Add justfile with doppler run wrappers for all docker compose commands - Strip hardcoded env fallbacks from docker-compose.yml - Add minimal README.md - Clean up .gitignore
This commit is contained in:
47
ui/src/routes/api/catalogue-page/+server.ts
Normal file
47
ui/src/routes/api/catalogue-page/+server.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import { json, error } from '@sveltejs/kit';
|
||||
import type { RequestHandler } from './$types';
|
||||
import { log } from '$lib/server/logger';
|
||||
import { backendFetch } from '$lib/server/scraper';
|
||||
import { bookToListing, type CatalogueResponse } from '$lib/server/catalogue';
|
||||
|
||||
/**
|
||||
* GET /api/catalogue-page?page=2&genre=all&sort=popular&status=all&q=
|
||||
*
|
||||
* Thin proxy to the Go backend's /api/catalogue endpoint.
|
||||
* Used by the infinite-scroll catalogue page to append subsequent pages
|
||||
* without a full SSR navigation.
|
||||
*
|
||||
* Returns { novels, page, hasNext } — the shape expected by the client-side
|
||||
* infinite scroll in +page.svelte.
|
||||
*/
|
||||
export const GET: RequestHandler = async ({ url }) => {
|
||||
const page = url.searchParams.get('page') ?? '1';
|
||||
const genre = url.searchParams.get('genre') ?? 'all';
|
||||
const sort = url.searchParams.get('sort') ?? 'popular';
|
||||
const status = url.searchParams.get('status') ?? 'all';
|
||||
const q = url.searchParams.get('q') ?? '';
|
||||
|
||||
const params = new URLSearchParams({ page, genre, sort, status });
|
||||
if (q.trim().length >= 2) {
|
||||
params.set('q', q.trim());
|
||||
}
|
||||
|
||||
try {
|
||||
const res = await backendFetch(`/api/catalogue?${params.toString()}`);
|
||||
if (!res.ok) {
|
||||
log.error('catalogue-page', 'backend returned error', { status: res.status });
|
||||
throw error(502, `Catalogue fetch failed: ${res.status}`);
|
||||
}
|
||||
const data: CatalogueResponse = await res.json();
|
||||
|
||||
return json({
|
||||
novels: (data.books ?? []).map(bookToListing),
|
||||
page: data.page ?? (parseInt(page, 10) || 1),
|
||||
hasNext: data.has_next ?? false
|
||||
});
|
||||
} catch (e) {
|
||||
if (e instanceof Error && 'status' in e) throw e;
|
||||
log.error('catalogue-page', 'network error', { err: String(e) });
|
||||
throw error(502, 'Could not reach catalogue service');
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user