refactor(file): replace window.open with blob download pattern in registry

This commit is contained in:
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 2026-05-01 09:43:00 +07:00
parent 14195e972f
commit e5d9800294
9 changed files with 122 additions and 36 deletions

View file

@ -297,8 +297,20 @@ async function getHistory() {
async function onDownloadFile(id: string, profileId: string) {
showLoader();
try {
const data = await getPathUploadFlie(fileGroup.value, profileId, id);
window.open(data.downloadUrl, "_blank");
const res = await getPathUploadFlie(fileGroup.value, profileId, id);
const downloadUrl = res.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 = `เอกสารปฏิบัติราชการพิเศษ`;
document.body.appendChild(link);
link.click();
setTimeout(() => {
document.body.removeChild(link);
URL.revokeObjectURL(url);
}, 100);
} catch (e) {
messageError($q, e);
} finally {
@ -311,7 +323,7 @@ function onSearch() {
rows.value = onSearchDataTable(
filter.value,
rowsData.value,
columns.value ? columns.value : []
columns.value ? columns.value : [],
);
}