diff --git a/src/modules/10_registry/05_Other/02_File.vue b/src/modules/10_registry/05_Other/02_File.vue index 1be029f..bb9f287 100644 --- a/src/modules/10_registry/05_Other/02_File.vue +++ b/src/modules/10_registry/05_Other/02_File.vue @@ -6,6 +6,7 @@ import { ref, onMounted, watch } from "vue"; import http from "@/plugins/http"; import config from "@/app.config"; import { useRegistryInFormationStore } from "@/modules/10_registry/store/registry"; +import { downloadBlobFile } from "@/modules/10_registry/utils/downloadFile"; import type { FileFormType } from "@/modules/10_registry/interface/index/Main"; @@ -57,18 +58,10 @@ async function downloadFile(fileName: string) { ) .then(async (res) => { const downloadUrl = res.data.downloadUrl; - const response = await fetch(downloadUrl); - const blob = await response.blob(); - const url = URL.createObjectURL(blob); - const link = document.createElement("a"); - link.href = url; - link.download = fileName; - document.body.appendChild(link); - link.click(); - setTimeout(() => { - document.body.removeChild(link); - URL.revokeObjectURL(url); - }, 100); + await downloadBlobFile({ + downloadUrl: downloadUrl, + fileName: fileName, + }); }) .catch((e) => { messageError($q, e); diff --git a/src/modules/10_registry/05_Other/03_FileOther.vue b/src/modules/10_registry/05_Other/03_FileOther.vue index 05e740b..585e68c 100644 --- a/src/modules/10_registry/05_Other/03_FileOther.vue +++ b/src/modules/10_registry/05_Other/03_FileOther.vue @@ -6,6 +6,7 @@ import { useQuasar } from "quasar"; import http from "@/plugins/http"; import config from "@/app.config"; import { useRegistryInFormationStore } from "@/modules/10_registry/store/registry"; +import { downloadBlobFile } from "@/modules/10_registry/utils/downloadFile"; import type { FileFormType } from "@/modules/10_registry/interface/index/Main"; @@ -57,18 +58,10 @@ async function downloadFile(fileName: string) { ) .then(async (res) => { const downloadUrl = res.data.downloadUrl; - const response = await fetch(downloadUrl); - const blob = await response.blob(); - const url = URL.createObjectURL(blob); - const link = document.createElement("a"); - link.href = url; - link.download = fileName; - document.body.appendChild(link); - link.click(); - setTimeout(() => { - document.body.removeChild(link); - URL.revokeObjectURL(url); - }, 100); + await downloadBlobFile({ + downloadUrl: downloadUrl, + fileName: fileName, + }); }) .catch((e) => { messageError($q, e); diff --git a/src/modules/10_registry/utils/downloadFile.ts b/src/modules/10_registry/utils/downloadFile.ts index 341b7f9..99c06c5 100644 --- a/src/modules/10_registry/utils/downloadFile.ts +++ b/src/modules/10_registry/utils/downloadFile.ts @@ -49,7 +49,8 @@ export async function downloadBlobFile({ const url = URL.createObjectURL(blobForDownload); const link = document.createElement("a"); link.href = url; - link.download = `${fileName}.${extension}`; + const downloadFileName = fileName.includes(".") ? fileName : `${fileName}.${extension}`; + link.download = downloadFileName; document.body.appendChild(link); link.click(); setTimeout(() => {