Some checks failed
Deploy with Docker Compose / deploy (push) Has been cancelled
- 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>
47 lines
1.2 KiB
TypeScript
47 lines
1.2 KiB
TypeScript
"use server";
|
|
|
|
import { getProvider } from "@/lib/providers/provider.factory";
|
|
import { AppError } from "@/utils/errors";
|
|
import type { NormalizedBook } from "@/lib/providers/types";
|
|
import logger from "@/lib/logger";
|
|
|
|
interface BookDataResult {
|
|
success: boolean;
|
|
data?: {
|
|
book: NormalizedBook;
|
|
pages: number[];
|
|
nextBook: NormalizedBook | null;
|
|
};
|
|
message?: string;
|
|
}
|
|
|
|
export async function getBookData(bookId: string): Promise<BookDataResult> {
|
|
try {
|
|
const provider = await getProvider();
|
|
if (!provider) {
|
|
return { success: false, message: "KOMGA_MISSING_CONFIG" };
|
|
}
|
|
|
|
const book = await provider.getBook(bookId);
|
|
const pages = Array.from({ length: book.pageCount }, (_, i) => i + 1);
|
|
|
|
let nextBook: NormalizedBook | null = null;
|
|
try {
|
|
nextBook = await provider.getNextBook(bookId);
|
|
} catch (error) {
|
|
logger.warn({ err: error, bookId }, "Failed to fetch next book in server action");
|
|
}
|
|
|
|
return {
|
|
success: true,
|
|
data: { book, pages, nextBook },
|
|
};
|
|
} catch (error) {
|
|
if (error instanceof AppError) {
|
|
return { success: false, message: error.code };
|
|
}
|
|
|
|
return { success: false, message: "BOOK_DATA_FETCH_ERROR" };
|
|
}
|
|
}
|