feat: ajout des services spécialisés (base, book, home, library, series) et des types associés

This commit is contained in:
Julien Froidefond
2025-02-12 08:47:13 +01:00
parent 2fa96072e8
commit 545f44749a
7 changed files with 405 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
import { BaseApiService } from "./base-api.service";
import { KomgaBook } from "@/types/komga";
export class BookService extends BaseApiService {
static async getBook(bookId: string): Promise<{ book: KomgaBook; pages: number[] }> {
try {
const config = await this.getKomgaConfig();
const headers = this.getAuthHeaders(config);
return this.fetchWithCache<{ book: KomgaBook; pages: number[] }>(
`book-${bookId}`,
async () => {
// Récupération des détails du tome
const bookResponse = await fetch(this.buildUrl(config, `books/${bookId}`), { headers });
if (!bookResponse.ok) {
throw new Error("Erreur lors de la récupération des détails du tome");
}
const book = await bookResponse.json();
// Récupération des pages du tome
const pagesResponse = await fetch(this.buildUrl(config, `books/${bookId}/pages`), {
headers,
});
if (!pagesResponse.ok) {
throw new Error("Erreur lors de la récupération des pages du tome");
}
const pages = await pagesResponse.json();
return {
book,
pages: pages.map((page: any) => page.number),
};
},
5 * 60 // Cache de 5 minutes
);
} catch (error) {
return this.handleError(error, "Impossible de récupérer le tome");
}
}
static getPageUrl(bookId: string, pageNumber: number): string {
return `/api/komga/books/${bookId}/pages/${pageNumber}`;
}
static getThumbnailUrl(bookId: string): string {
return `/api/komga/images/books/${bookId}/thumbnail`;
}
}