Files
shlink-web-client/src/common/services/ImageDownloader.ts
2022-11-15 11:41:05 +01:00

14 lines
455 B
TypeScript

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