Files
stripstream/src/app/api/provider/search/route.ts
Froidefond Julien 7d0f1c4457
Some checks failed
Deploy with Docker Compose / deploy (push) Has been cancelled
feat: add multi-provider support (Komga + Stripstream Librarian)
- Introduce provider abstraction layer (IMediaProvider, KomgaProvider, StripstreamProvider)
- Add Stripstream Librarian as second media provider with full feature parity
- Migrate all pages and components from direct Komga services to provider factory
- Remove dead service code (BaseApiService, HomeService, LibraryService, SearchService, TestService)
- Fix library/series page-based pagination for both providers (Komga 0-indexed, Stripstream 1-indexed)
- Fix unread filter and search on library page for both providers
- Fix read progress display for Stripstream (reading_status mapping)
- Fix series read status (books_read_count) for Stripstream
- Add global search with series results for Stripstream (series_hits from Meilisearch)
- Fix thumbnail proxy to return 404 gracefully instead of JSON on upstream error
- Replace duration-based cache debug detection with x-nextjs-cache header

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-11 11:48:17 +01:00

45 lines
1.5 KiB
TypeScript

import type { NextRequest } from "next/server";
import { NextResponse } from "next/server";
import { getProvider } from "@/lib/providers/provider.factory";
import { AppError, getErrorMessage } from "@/utils/errors";
import { ERROR_CODES } from "@/constants/errorCodes";
const MIN_QUERY_LENGTH = 2;
const DEFAULT_LIMIT = 6;
const MAX_LIMIT = 10;
export async function GET(request: NextRequest) {
try {
const query = request.nextUrl.searchParams.get("q")?.trim() ?? "";
const limitParam = request.nextUrl.searchParams.get("limit");
const parsedLimit = limitParam ? Number(limitParam) : Number.NaN;
const limit = Number.isFinite(parsedLimit)
? Math.max(1, Math.min(parsedLimit, MAX_LIMIT))
: DEFAULT_LIMIT;
if (query.length < MIN_QUERY_LENGTH) {
return NextResponse.json([], { headers: { "Cache-Control": "no-store" } });
}
const provider = await getProvider();
if (!provider) {
return NextResponse.json([], { headers: { "Cache-Control": "no-store" } });
}
const results = await provider.search(query, limit);
return NextResponse.json(results, { headers: { "Cache-Control": "no-store" } });
} catch (error) {
if (error instanceof AppError) {
return NextResponse.json(
{ error: { code: error.code, message: getErrorMessage(error.code) } },
{ status: 500 }
);
}
return NextResponse.json(
{ error: { code: ERROR_CODES.CLIENT.FETCH_ERROR, message: "Search error" } },
{ status: 500 }
);
}
}