refactor: replace book details GET route with server action
All checks were successful
Deploy with Docker Compose / deploy (push) Successful in 6m16s

This commit is contained in:
2026-02-28 12:21:07 +01:00
parent 5eba969846
commit 26021ea907
5 changed files with 55 additions and 73 deletions

36
src/app/actions/books.ts Normal file
View File

@@ -0,0 +1,36 @@
"use server";
import { BookService } from "@/lib/services/book.service";
import { AppError } from "@/utils/errors";
import type { KomgaBook } from "@/types/komga";
interface BookDataResult {
success: boolean;
data?: {
book: KomgaBook;
pages: number[];
nextBook: KomgaBook | null;
};
message?: string;
}
export async function getBookData(bookId: string): Promise<BookDataResult> {
try {
const data = await BookService.getBook(bookId);
const nextBook = await BookService.getNextBook(bookId, data.book.seriesId);
return {
success: true,
data: {
...data,
nextBook,
},
};
} catch (error) {
if (error instanceof AppError) {
return { success: false, message: error.code };
}
return { success: false, message: "BOOK_DATA_FETCH_ERROR" };
}
}