mirror of
https://github.com/mealie-recipes/mealie.git
synced 2026-04-11 07:25:42 -04:00
chore: Nuxt 4 upgrade (#7426)
This commit is contained in:
28
frontend/app/composables/api/use-downloader.ts
Normal file
28
frontend/app/composables/api/use-downloader.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { alert } from "~/composables/use-toast";
|
||||
import { useGlobalI18n } from "~/composables/use-global-i18n";
|
||||
|
||||
export function useDownloader() {
|
||||
function download(url: string, filename: string) {
|
||||
useFetch(url, {
|
||||
method: "GET",
|
||||
responseType: "blob",
|
||||
onResponse({ response }) {
|
||||
if (!response.ok) {
|
||||
console.error("Download failed", response);
|
||||
const i18n = useGlobalI18n();
|
||||
alert.error(i18n.t("events.something-went-wrong"));
|
||||
return;
|
||||
}
|
||||
|
||||
const url = window.URL.createObjectURL(new Blob([response._data]));
|
||||
const link = document.createElement("a");
|
||||
link.href = url;
|
||||
link.setAttribute("download", filename);
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
return download;
|
||||
}
|
||||
Reference in New Issue
Block a user