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

- 使用 Fetch API 替代直接创建 anchor 元素
- 改进错误处理,增加错误日志输出
- 优化代码结构,提高可读性和可维护性
This commit is contained in:
2025-02-06 20:46:36 +08:00
Unverified
parent 1d26b682fc
commit da2ef69cb9

View File

@@ -98,12 +98,18 @@
});
function downloadVideo() {
var link = document.createElement('a');
link.href = videoUrl;
link.download = videoUrl.split('/').pop();
fetch(videoUrl)
.then(response => response.blob())
.then(blob => {
const link = document.createElement('a');
link.href = URL.createObjectURL(blob);
link.download = videoTitle + '.mp4'; // 设置下载文件名
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>