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:
@@ -14,6 +14,7 @@ import { BookOfflineButton } from "@/components/ui/book-offline-button";
|
||||
import { useTranslate } from "@/hooks/useTranslate";
|
||||
import logger from "@/lib/logger";
|
||||
import { Container } from "@/components/ui/container";
|
||||
import { getBookData } from "@/app/actions/books";
|
||||
|
||||
type BookStatus = "idle" | "downloading" | "available" | "error";
|
||||
|
||||
@@ -45,17 +46,18 @@ export function DownloadManager() {
|
||||
const key = localStorage.key(i);
|
||||
if (key?.startsWith("book-status-")) {
|
||||
const bookId = key.replace("book-status-", "");
|
||||
const status = JSON.parse(localStorage.getItem(key) || "");
|
||||
if (status.status !== "idle") {
|
||||
try {
|
||||
const response = await fetch(`/api/komga/books/${bookId}`);
|
||||
if (!response.ok) throw new Error("Livre non trouvé");
|
||||
const bookData = await response.json();
|
||||
books.push({
|
||||
book: bookData.book,
|
||||
status,
|
||||
});
|
||||
} catch (error) {
|
||||
const status = JSON.parse(localStorage.getItem(key) || "");
|
||||
if (status.status !== "idle") {
|
||||
try {
|
||||
const result = await getBookData(bookId);
|
||||
if (!result.success || !result.data) {
|
||||
throw new Error("Livre non trouvé");
|
||||
}
|
||||
books.push({
|
||||
book: result.data.book,
|
||||
status,
|
||||
});
|
||||
} catch (error) {
|
||||
logger.error({ err: error }, `Erreur lors de la récupération du livre ${bookId}:`);
|
||||
localStorage.removeItem(key);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import { ErrorMessage } from "@/components/ui/ErrorMessage";
|
||||
import { ERROR_CODES } from "@/constants/errorCodes";
|
||||
import type { KomgaBook } from "@/types/komga";
|
||||
import logger from "@/lib/logger";
|
||||
import { getBookData } from "@/app/actions/books";
|
||||
|
||||
interface ClientBookPageProps {
|
||||
bookId: string;
|
||||
@@ -48,15 +49,12 @@ export function ClientBookPage({ bookId, initialData, initialError }: ClientBook
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
|
||||
const response = await fetch(`/api/komga/books/${bookId}`);
|
||||
|
||||
if (!response.ok) {
|
||||
const errorData = await response.json();
|
||||
throw new Error(errorData.error?.code || ERROR_CODES.BOOK.PAGES_FETCH_ERROR);
|
||||
const result = await getBookData(bookId);
|
||||
if (!result.success || !result.data) {
|
||||
throw new Error(result.message || ERROR_CODES.BOOK.PAGES_FETCH_ERROR);
|
||||
}
|
||||
|
||||
const bookData = await response.json();
|
||||
setData(bookData);
|
||||
setData(result.data);
|
||||
} catch (err) {
|
||||
logger.error({ err }, "Error fetching book");
|
||||
setError(err instanceof Error ? err.message : ERROR_CODES.BOOK.PAGES_FETCH_ERROR);
|
||||
|
||||
Reference in New Issue
Block a user