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:
60
ui/src/lib/server/scraper.ts
Normal file
60
ui/src/lib/server/scraper.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
* Backend API helper.
|
||||
*
|
||||
* Centralises the BACKEND_URL constant and provides a thin fetch wrapper that:
|
||||
* - Resolves paths relative to BACKEND_API_URL.
|
||||
* - Throws 502 on network errors (unreachable backend).
|
||||
* - Re-throws SvelteKit `error()` objects so callers can still short-circuit.
|
||||
* - Passes a RequestInit through verbatim so callers keep full control.
|
||||
*
|
||||
* Import only from server-side modules (`+server.ts`, `*.server.ts`).
|
||||
*/
|
||||
|
||||
import { error } from '@sveltejs/kit';
|
||||
import { env } from '$env/dynamic/private';
|
||||
|
||||
export const BACKEND_URL = env.BACKEND_API_URL ?? 'http://localhost:8080';
|
||||
|
||||
/**
|
||||
* Fetch a path on the backend, throwing a 502 on network failures.
|
||||
*
|
||||
* The `path` must start with `/` (e.g. `/api/voices`).
|
||||
*
|
||||
* SvelteKit `error()` exceptions are always re-thrown so callers can
|
||||
* short-circuit correctly inside their own catch blocks.
|
||||
*/
|
||||
export async function backendFetch(path: string, init?: RequestInit): Promise<Response> {
|
||||
try {
|
||||
return await fetch(`${BACKEND_URL}${path}`, init);
|
||||
} catch (e) {
|
||||
// Re-throw SvelteKit HTTP errors so they propagate to the framework.
|
||||
if (e instanceof Error && 'status' in e) throw e;
|
||||
throw error(502, 'Could not reach backend');
|
||||
}
|
||||
}
|
||||
|
||||
// ─── Response types ───────────────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* Metadata shape returned inside the 200 response from GET /api/book-preview/{slug}.
|
||||
* Used in both the SSR page load and the API proxy to avoid duplicating the inline type.
|
||||
*/
|
||||
export interface BookPreviewMeta {
|
||||
slug: string;
|
||||
title: string;
|
||||
author: string;
|
||||
cover: string;
|
||||
status: string;
|
||||
genres: string[];
|
||||
summary: string;
|
||||
total_chapters: number;
|
||||
source_url: string;
|
||||
}
|
||||
|
||||
/** Full 200 response from GET /api/book-preview/{slug}. */
|
||||
export interface BookPreviewResponse {
|
||||
in_lib: boolean;
|
||||
meta: BookPreviewMeta;
|
||||
chapters: { number: number; title: string; date?: string }[];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user