Merge branch 'develop' into dev
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m18s

This commit is contained in:
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 2026-05-01 11:24:41 +07:00
commit 6ad798a2a2

View file

@ -139,10 +139,38 @@ async function onDownloadFile(id: string, profileId: string) {
const downloadUrl = res.data.downloadUrl;
const response = await fetch(downloadUrl);
const blob = await response.blob();
const url = URL.createObjectURL(blob);
const contentType: string | null = response.headers.get("Content-Type");
// 2. MIME Type
const extensionMap: Record<string, string> = {
"application/pdf": "pdf",
"image/jpeg": "jpg",
"image/png": "png",
"image/gif": "gif",
"application/zip": "zip",
"application/vnd.openxmlformats-officedocument.wordprocessingml.document":
"docx",
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":
"xlsx",
};
let extension = contentType ? extensionMap[contentType] : undefined;
if (!extension) {
const urlWithoutQuery = downloadUrl.split("?")[0];
extension = urlWithoutQuery.includes(".")
? urlWithoutQuery.split(".").pop()
: "pdf";
}
const blobForDownload = new Blob([blob], {
type: "application/octet-stream",
});
const url = URL.createObjectURL(blobForDownload);
const link = document.createElement("a");
link.href = url;
link.download = `ประวัติการเปลี่ยนชื่อ-นามสกุล_`;
link.download = `ประวัติการเปลี่ยนชื่อ-นามสกุล.${extension}`;
document.body.appendChild(link);
link.click();
setTimeout(() => {