refacto(services): fetchFromApi simpler + bug libraries fetch

This commit is contained in:
Julien Froidefond
2025-02-23 10:42:04 +01:00
parent 9c1889cf7d
commit fd2632c394
6 changed files with 90 additions and 84 deletions

View File

@@ -8,15 +8,12 @@ interface ImageResponse {
export class ImageService extends BaseApiService {
static async getImage(path: string): Promise<ImageResponse> {
try {
const config = await this.getKomgaConfig();
const url = this.buildUrl(config, path);
const headers = this.getAuthHeaders(config);
headers.set("Accept", "image/jpeg, image/png, image/gif, image/webp, */*");
const headers = { Accept: "image/jpeg, image/png, image/gif, image/webp, */*" };
return this.fetchWithCache<ImageResponse>(
`image-${path}`,
async () => {
const response = await this.fetchFromApi<Response>(url, headers, { isImage: true });
const response = await this.fetchFromApi<Response>({ path }, headers, { isImage: true });
const contentType = response.headers.get("content-type");
const arrayBuffer = await response.arrayBuffer();
const buffer = Buffer.from(arrayBuffer);