fix(service): image service with cache
This commit is contained in:
@@ -11,20 +11,18 @@ export class ImageService extends BaseApiService {
|
|||||||
const config = await this.getKomgaConfig();
|
const config = await this.getKomgaConfig();
|
||||||
const url = this.buildUrl(config, path);
|
const url = this.buildUrl(config, path);
|
||||||
const headers = this.getAuthHeaders(config);
|
const headers = this.getAuthHeaders(config);
|
||||||
|
|
||||||
// Ajout des headers pour accepter les images
|
|
||||||
headers.set("Accept", "image/jpeg, image/png, image/gif, image/webp, */*");
|
headers.set("Accept", "image/jpeg, image/png, image/gif, image/webp, */*");
|
||||||
|
|
||||||
|
return this.fetchWithCache<ImageResponse>(
|
||||||
|
`image-${path}`,
|
||||||
|
async () => {
|
||||||
const response = await fetch(url, { headers });
|
const response = await fetch(url, { headers });
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error(`Erreur HTTP: ${response.status} ${response.statusText}`);
|
throw new Error(`Erreur HTTP: ${response.status} ${response.statusText}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Récupérer le type MIME de l'image
|
|
||||||
const contentType = response.headers.get("content-type");
|
const contentType = response.headers.get("content-type");
|
||||||
|
|
||||||
// Convertir la réponse en buffer
|
|
||||||
const arrayBuffer = await response.arrayBuffer();
|
const arrayBuffer = await response.arrayBuffer();
|
||||||
const buffer = Buffer.from(arrayBuffer);
|
const buffer = Buffer.from(arrayBuffer);
|
||||||
|
|
||||||
@@ -32,6 +30,9 @@ export class ImageService extends BaseApiService {
|
|||||||
buffer,
|
buffer,
|
||||||
contentType,
|
contentType,
|
||||||
};
|
};
|
||||||
|
},
|
||||||
|
"IMAGES"
|
||||||
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Erreur lors de la récupération de l'image:", error);
|
console.error("Erreur lors de la récupération de l'image:", error);
|
||||||
return this.handleError(error, "Impossible de récupérer l'image");
|
return this.handleError(error, "Impossible de récupérer l'image");
|
||||||
|
|||||||
Reference in New Issue
Block a user