mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2024-12-26 19:08:23 +03:00
13 lines
442 B
TypeScript
13 lines
442 B
TypeScript
import { saveUrl } from '../helpers/files';
|
|
import type { Fetch } from '../types';
|
|
|
|
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);
|
|
}
|
|
}
|