增加模型库模型下载入口

This commit is contained in:
zhangshun
2026-06-01 14:34:44 +08:00
parent 5b6d29f0f6
commit b1ef3deb03
4 changed files with 59 additions and 2 deletions

View File

@@ -0,0 +1,28 @@
export async function downloadFileFromUrl(fileUrl: string, fileName: string) {
const response = await fetch(fileUrl, {
credentials: "include"
});
if (!response.ok) {
throw new Error(`文件下载失败:${response.status} ${response.statusText}`);
}
const blob = await response.blob();
const objectUrl = URL.createObjectURL(blob);
try {
const anchor = document.createElement("a");
anchor.href = objectUrl;
anchor.download = ensureGlbFileName(fileName);
anchor.rel = "noopener";
anchor.style.display = "none";
document.body.appendChild(anchor);
anchor.click();
anchor.remove();
} finally {
window.setTimeout(() => URL.revokeObjectURL(objectUrl), 1000);
}
}
function ensureGlbFileName(fileName: string) {
const name = fileName.trim() || "model.glb";
return name.toLowerCase().endsWith(".glb") ? name : `${name}.glb`;
}