refactor: replace book details GET route with server action
All checks were successful
Deploy with Docker Compose / deploy (push) Successful in 6m16s
All checks were successful
Deploy with Docker Compose / deploy (push) Successful in 6m16s
This commit is contained in:
36
src/app/actions/books.ts
Normal file
36
src/app/actions/books.ts
Normal 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" };
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user