mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-04-20 13:36:20 +00:00
Move more components to shlink-web-component when applicable
This commit is contained in:
13
shlink-web-component/utils/services/ImageDownloader.ts
Normal file
13
shlink-web-component/utils/services/ImageDownloader.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user