refactor(videos): 优化视频下载功能

- 移除了使用 fetch API 下载视频的复杂逻辑
- 采用直接创建 <a> 元素并触发点击的方法简化下载过程
- 修改了下载文件名的生成逻辑,使用 URL 的最后一部分作为文件名
This commit is contained in:
2025-02-06 20:44:55 +08:00
Unverified
parent 7587fa61d5
commit 1d26b682fc

View File

@@ -98,18 +98,12 @@
});
function downloadVideo() {
fetch(videoUrl)
.then(response => response.blob())
.then(blob => {
const link = document.createElement('a');
link.href = URL.createObjectURL(blob);
link.download = videoTitle + '.mp4'; // 设置下载文件名
var link = document.createElement('a');
link.href = videoUrl;
link.download = videoUrl.split('/').pop();
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
URL.revokeObjectURL(link.href);
})
.catch(error => console.error('Error downloading the video:', error));
}
</script>
</body>