reacto: images not called directly in routes

This commit is contained in:
Julien Froidefond
2025-02-17 08:17:31 +01:00
parent 50e583f58d
commit 4ae606ea09
6 changed files with 63 additions and 59 deletions

View File

@@ -98,6 +98,20 @@ export class BookService extends BaseApiService {
}
}
static async getThumbnail(bookId: string): Promise<Response> {
try {
const response = await ImageService.getImage(`books/${bookId}/thumbnail`);
return new Response(response.buffer, {
headers: {
"Content-Type": response.contentType || "image/jpeg",
"Cache-Control": "public, max-age=31536000, immutable",
},
});
} catch (error) {
throw this.handleError(error, "Impossible de récupérer la miniature du livre");
}
}
static getPageUrl(bookId: string, pageNumber: number): string {
return `/api/komga/images/books/${bookId}/pages/${pageNumber}`;
}

View File

@@ -1,6 +1,8 @@
import { BaseApiService } from "./base-api.service";
import { LibraryResponse } from "@/types/library";
import { KomgaBook, KomgaSeries } from "@/types/komga";
import { BookService } from "./book.service";
import { ImageService } from "./image.service";
export class SeriesService extends BaseApiService {
static async getSeries(seriesId: string): Promise<KomgaSeries> {
@@ -73,4 +75,39 @@ export class SeriesService extends BaseApiService {
return this.handleError(error, "Impossible de récupérer le premier livre");
}
}
static async getFirstPage(seriesId: string): Promise<Response> {
try {
// Récupérer l'ID du premier livre
const firstBookId = await this.getFirstBook(seriesId);
return await BookService.getPage(firstBookId, 1);
} catch (error) {
// En cas d'erreur, on essaie de récupérer le thumbnail comme fallback
try {
const response = await ImageService.getImage(`series/${seriesId}/thumbnail`);
return new Response(response.buffer, {
headers: {
"Content-Type": response.contentType || "image/jpeg",
"Cache-Control": "public, max-age=31536000, immutable",
},
});
} catch (fallbackError) {
throw this.handleError(fallbackError, "Impossible de récupérer l'image de la série");
}
}
}
static async getThumbnail(seriesId: string): Promise<Response> {
try {
const response = await ImageService.getImage(`series/${seriesId}/thumbnail`);
return new Response(response.buffer, {
headers: {
"Content-Type": response.contentType || "image/jpeg",
"Cache-Control": "public, max-age=31536000, immutable",
},
});
} catch (error) {
throw this.handleError(error, "Impossible de récupérer la miniature de la série");
}
}
}