mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-04-18 12:36:20 +00:00
Migrated ImageDownloader from axios to fetch
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -19,10 +19,10 @@ const provideServices = (bottle: Bottle, connect: ConnectDecorator) => {
|
||||
bottle.constant('window', (global as any).window);
|
||||
bottle.constant('console', global.console);
|
||||
bottle.constant('axios', axios);
|
||||
bottle.constant('fetch', (global as any).fetch.bind((global as any)));
|
||||
bottle.constant('fetch', (global as any).fetch.bind(global));
|
||||
bottle.serviceFactory('jsonFetch', jsonFetch, 'fetch');
|
||||
|
||||
bottle.service('ImageDownloader', ImageDownloader, 'axios', 'window');
|
||||
bottle.service('ImageDownloader', ImageDownloader, 'fetch', 'window');
|
||||
bottle.service('ReportExporter', ReportExporter, 'window', 'jsonToCsv');
|
||||
|
||||
// Components
|
||||
|
||||
Reference in New Issue
Block a user