Migrated ImageDownloader from axios to fetch

This commit is contained in:
Alejandro Celaya
2022-11-15 11:41:05 +01:00
parent a88ebc26a9
commit 34aa156d5f
9 changed files with 21 additions and 31 deletions

View File

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