mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-13 13:22:57 +00:00
Co-authored-by: Christopher Oliphant <RALifeCoach@users.noreply.github.com> Co-authored-by: bflatastic <bombayapirat@gmail.com>
18 lines
551 B
TypeScript
18 lines
551 B
TypeScript
import { AddToast, ToastTypes } from "~/contexts/ToasterContext";
|
|
|
|
export const downloadFile = (url: string, addToast: AddToast) => {
|
|
fetch(url)
|
|
.then((resp) => resp.blob())
|
|
.then((blob) => {
|
|
const url = window.URL.createObjectURL(blob);
|
|
const a = document.createElement("a");
|
|
a.style.display = "none";
|
|
a.href = url;
|
|
a.download = url;
|
|
document.body.appendChild(a);
|
|
a.click();
|
|
window.URL.revokeObjectURL(url);
|
|
})
|
|
.catch(() => addToast(ToastTypes.ERROR, "Could not download file."));
|
|
};
|