Some checks failed
Deploy / Deploy Production (push) Has been skipped
Deploy / Cleanup Preview (push) Has been skipped
Deploy / Deploy Preview (push) Failing after 0s
CI / Scraper / Test (pull_request) Successful in 11s
CI / UI / Build (pull_request) Failing after 14s
CI / Scraper / Lint (pull_request) Successful in 23s
CI / Scraper / Build (pull_request) Successful in 24s
iOS CI / Build (push) Has been cancelled
iOS CI / Test (push) Has been cancelled
iOS CI / Build (pull_request) Failing after 2s
iOS CI / Test (pull_request) Has been skipped
- iOS SwiftUI app (ios/LibNovel/) targeting iOS 17+, generated via xcodegen - Full feature set: auth, home, library, book detail, chapter reader, browse, audio player, profile - Kingfisher for image loading, swift-markdown-ui for chapter rendering - Base URL: https://v2.libnovel.kalekber.cc - SvelteKit JSON API routes (ui/src/routes/api/) for iOS consumption: auth/login, auth/register, auth/me, auth/logout, auth/change-password, home, library, book/[slug], chapter/[slug]/[n], search, ranking, progress/[slug], presign/audio (updated) - Gitea Actions CI: .gitea/workflows/ios.yaml (build + test on macos-latest) - justfile: ios-gen, ios-build, ios-test recipes
37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
import { json, error } from '@sveltejs/kit';
|
|
import type { RequestHandler } from './$types';
|
|
import { env } from '$env/dynamic/private';
|
|
import { log } from '$lib/server/logger';
|
|
|
|
const SCRAPER_URL = env.SCRAPER_API_URL ?? 'http://localhost:8080';
|
|
|
|
/**
|
|
* GET /api/search?q=<query>
|
|
* Proxies to the Go scraper's /api/search endpoint.
|
|
* Returns: { results, local_count, remote_count }
|
|
*
|
|
* Response shape mirrors SearchResponse in the iOS APIClient.
|
|
*/
|
|
export const GET: RequestHandler = async ({ url }) => {
|
|
const q = url.searchParams.get('q') ?? '';
|
|
|
|
if (q.trim().length < 2) {
|
|
return json({ results: [], local_count: 0, remote_count: 0 });
|
|
}
|
|
|
|
const apiURL = `${SCRAPER_URL}/api/search?q=${encodeURIComponent(q.trim())}`;
|
|
try {
|
|
const res = await fetch(apiURL);
|
|
if (!res.ok) {
|
|
log.error('api/search', 'scraper returned error', { status: res.status, q });
|
|
error(502, `Search failed: ${res.status}`);
|
|
}
|
|
const data = await res.json();
|
|
return json(data);
|
|
} catch (e) {
|
|
if (e instanceof Error && 'status' in e) throw e;
|
|
log.error('api/search', 'network error', { q, err: String(e) });
|
|
error(502, 'Could not reach search service');
|
|
}
|
|
};
|