feat: 优化下载功能,支持路径编码和直接下载链接

This commit is contained in:
2025-11-15 14:19:07 +08:00
parent d0bd44c526
commit 9d5f753621
5 changed files with 181 additions and 63 deletions

View File

@@ -12,7 +12,12 @@ function attachDownloadButtonListeners() {
button.addEventListener("click", () => {
const key = button.dataset.downloadKey;
const name = button.dataset.downloadName;
downloadFile(`/download/${key}`, name);
// 对路径分段编码,保留路径分隔符,避免 # ? 等字符破坏 URL
const encoded = key
.split("/")
.map((seg) => encodeURIComponent(seg))
.join("/");
downloadFile(`/download/${encoded}`, name);
});
button.dataset.listenerAttached = "true";
}