From da2ef69cb9d3dfc1f349adeaf5b4d3dd08d1abe3 Mon Sep 17 00:00:00 2001 From: root <3234374354@qq.com> Date: Thu, 6 Feb 2025 20:46:36 +0800 Subject: [PATCH] =?UTF-8?q?fix(videos):=20=E4=BC=98=E5=8C=96=E8=A7=86?= =?UTF-8?q?=E9=A2=91=E4=B8=8B=E8=BD=BD=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 使用 Fetch API 替代直接创建 anchor 元素 - 改进错误处理,增加错误日志输出 - 优化代码结构,提高可读性和可维护性 --- index/videos/template-video.html | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/index/videos/template-video.html b/index/videos/template-video.html index 5b25188b..e06c8108 100644 --- a/index/videos/template-video.html +++ b/index/videos/template-video.html @@ -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)); }