refacto(images): component cover dans refacto services and routes

This commit is contained in:
Julien Froidefond
2025-02-17 09:14:57 +01:00
parent 5c1138f287
commit 7ee99ac31a
13 changed files with 270 additions and 511 deletions

View File

@@ -67,14 +67,6 @@ export class BookService extends BaseApiService {
static async getPage(bookId: string, pageNumber: number): Promise<Response> {
try {
// Récupérer les préférences de l'utilisateur
const preferences = await PreferencesService.getPreferences();
// Si l'utilisateur préfère les vignettes, utiliser getPageThumbnail
if (preferences.showThumbnails) {
return this.getPageThumbnail(bookId, pageNumber);
}
// Ajuster le numéro de page pour l'API Komga (zero-based)
const adjustedPageNumber = pageNumber - 1;
const response = await ImageService.getImage(
@@ -83,6 +75,7 @@ export class BookService extends BaseApiService {
return new Response(response.buffer, {
headers: {
"Content-Type": response.contentType || "image/jpeg",
"Cache-Control": "public, max-age=31536000, immutable",
},
});
} catch (error) {
@@ -90,35 +83,26 @@ export class BookService extends BaseApiService {
}
}
static async getPageThumbnail(bookId: string, pageNumber: number): Promise<Response> {
static async getCover(bookId: string): Promise<Response> {
try {
// Ajuster le numéro de page pour l'API Komga (zero-based)
const adjustedPageNumber = pageNumber;
const response = await ImageService.getImage(
`books/${bookId}/pages/${adjustedPageNumber}/thumbnail?zero_based=true`
);
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");
}
}
// Récupérer les préférences de l'utilisateur
const preferences = await PreferencesService.getPreferences();
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",
},
});
// Si l'utilisateur préfère les vignettes, utiliser la miniature
if (preferences.showThumbnails) {
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",
},
});
}
// Sinon, récupérer la première page
return this.getPage(bookId, 1);
} catch (error) {
throw this.handleError(error, "Impossible de récupérer la miniature du livre");
throw this.handleError(error, "Impossible de récupérer la couverture");
}
}
@@ -130,7 +114,23 @@ export class BookService extends BaseApiService {
return `/api/komga/images/books/${bookId}/pages/${pageNumber}/thumbnail`;
}
static getThumbnailUrl(bookId: string): string {
return ImageService.getBookThumbnailUrl(bookId);
static async getPageThumbnail(bookId: string, pageNumber: number): Promise<Response> {
try {
const response = await ImageService.getImage(
`books/${bookId}/pages/${pageNumber}/thumbnail?zero_based=true`
);
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 page");
}
}
static getCoverUrl(bookId: string): string {
return `/api/komga/images/books/${bookId}/thumbnail`;
}
}

View File

@@ -77,14 +77,20 @@ export class SeriesService extends BaseApiService {
}
}
static async getFirstPage(seriesId: string): Promise<Response> {
static async getCover(seriesId: string): Promise<Response> {
try {
// Récupérer les préférences de l'utilisateur
const preferences = await PreferencesService.getPreferences();
// Si l'utilisateur préfère les vignettes, utiliser getThumbnail
// Si l'utilisateur préfère les vignettes, utiliser la miniature
if (preferences.showThumbnails) {
return this.getThumbnail(seriesId);
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",
},
});
}
// Sinon, récupérer la première page
@@ -92,21 +98,11 @@ export class SeriesService extends BaseApiService {
const response = await BookService.getPage(firstBookId, 1);
return response;
} catch (error) {
throw this.handleError(error, "Impossible de récupérer la première page");
throw this.handleError(error, "Impossible de récupérer la couverture");
}
}
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");
}
static getCoverUrl(seriesId: string): string {
return `/api/komga/images/series/${seriesId}/thumbnail`;
}
}