Wrapped logic to perform HTTP requests with fetch into an HttpClient class

This commit is contained in:
Alejandro Celaya
2022-11-15 20:31:35 +01:00
parent a0767417b3
commit 9b3bdebb28
13 changed files with 142 additions and 115 deletions

View File

@@ -1,11 +1,11 @@
import { Fetch } from '../../utils/types';
import { saveUrl } from '../../utils/helpers/files';
import { HttpClient } from './HttpClient';
export class ImageDownloader {
public constructor(private readonly fetch: Fetch, private readonly window: Window) {}
public constructor(private readonly httpClient: HttpClient, private readonly window: Window) {}
public async saveImage(imgUrl: string, filename: string): Promise<void> {
const data = await this.fetch(imgUrl).then((resp) => resp.blob());
const data = await this.httpClient.fetchBlob(imgUrl);
const url = URL.createObjectURL(data);
saveUrl(this.window, url, filename);