feat: v3.1.0 OSS直连优化与代码质量提升
- 🚀 OSS 直连上传下载(用户直连OSS,不经过后端) - ✨ 新增 Presigned URL 签名接口 - ✨ 支持自定义 OSS endpoint 配置 - 🐛 修复 buildS3Config 不支持自定义 endpoint 的问题 - 🐛 清理残留的 basic-ftp 依赖 - ♻️ 更新 package.json 项目描述和版本号 - 📝 完善 README.md 更新日志和 CORS 配置说明 - 🔒 安全性增强:签名 URL 15分钟/1小时有效期 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -918,42 +918,47 @@
|
||||
this.viewingFile = null;
|
||||
},
|
||||
|
||||
downloadFile(file) {
|
||||
async downloadFile(file) {
|
||||
console.log("[分享下载] 文件:", file);
|
||||
|
||||
// 记录下载次数(异步,不等待)
|
||||
axios.post(`${this.apiBase}/api/share/${this.shareCode}/download`)
|
||||
.catch(err => console.error('记录下载次数失败:', err));
|
||||
|
||||
if (file.httpDownloadUrl) {
|
||||
// 如果配置了HTTP下载URL,新窗口打开直接下载(避免Mixed Content问题)
|
||||
console.log("[分享下载] 使用HTTP下载:", file.httpDownloadUrl);
|
||||
window.open(file.httpDownloadUrl, '_blank');
|
||||
return;
|
||||
// 构建文件路径
|
||||
let filePath;
|
||||
if (this.shareInfo.share_type === 'file') {
|
||||
// 单文件分享,使用 share_path
|
||||
filePath = this.shareInfo.share_path;
|
||||
} else {
|
||||
// 如果没有配置HTTP URL,通过后端SFTP下载
|
||||
console.log("[分享下载] 使用SFTP下载");
|
||||
// 目录分享,组合路径
|
||||
const basePath = this.shareInfo.share_path;
|
||||
filePath = basePath === '/' ? `/${file.name}` : `${basePath}/${file.name}`;
|
||||
}
|
||||
|
||||
// 构建文件路径
|
||||
let filePath;
|
||||
if (this.shareInfo.share_type === 'file') {
|
||||
// 单文件分享,使用 share_path
|
||||
filePath = this.shareInfo.share_path;
|
||||
} else {
|
||||
// 目录分享,组合路径
|
||||
const basePath = this.shareInfo.share_path;
|
||||
filePath = basePath === '/' ? `/${file.name}` : `${basePath}/${file.name}`;
|
||||
}
|
||||
|
||||
// 使用分享下载API(公开API,不需要认证)
|
||||
let downloadUrl = `${this.apiBase}/api/share/${this.shareCode}/download-file?path=${encodeURIComponent(filePath)}`;
|
||||
|
||||
// 如果有密码,附加密码参数
|
||||
try {
|
||||
// 获取下载 URL(OSS 直连或后端代理)
|
||||
const params = { path: filePath };
|
||||
if (this.password) {
|
||||
downloadUrl += `&password=${encodeURIComponent(this.password)}`;
|
||||
params.password = this.password;
|
||||
}
|
||||
|
||||
this.triggerDownload(downloadUrl, file.name);
|
||||
const { data } = await axios.get(`${this.apiBase}/api/share/${this.shareCode}/download-url`, { params });
|
||||
|
||||
if (data.success) {
|
||||
// 记录下载次数(异步,不等待)
|
||||
axios.post(`${this.apiBase}/api/share/${this.shareCode}/download`)
|
||||
.catch(err => console.error('记录下载次数失败:', err));
|
||||
|
||||
if (data.direct) {
|
||||
// OSS 直连下载:新窗口打开
|
||||
console.log("[分享下载] OSS 直连下载");
|
||||
window.open(data.downloadUrl, '_blank');
|
||||
} else {
|
||||
// 本地存储:通过后端下载
|
||||
console.log("[分享下载] 后端代理下载");
|
||||
this.triggerDownload(data.downloadUrl, file.name);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('[分享下载] 获取下载链接失败:', error);
|
||||
alert('获取下载链接失败: ' + (error.response?.data?.message || error.message));
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user