fix: move share quota block to download and add 3s download alert

This commit is contained in:
2026-02-17 19:05:12 +08:00
parent 10a3f09952
commit 19d3f29f6b
2 changed files with 49 additions and 4 deletions

View File

@@ -5661,9 +5661,9 @@ app.post('/api/share/:code/list', shareRateLimitMiddleware, async (req, res) =>
shareLimiter.recordSuccess(req.shareRateLimitKey); shareLimiter.recordSuccess(req.shareRateLimitKey);
} }
// 获取分享者的用户信息 // 获取分享者的用户信息(查看列表不触发下载流量策略)
const ownerPolicyState = enforceDownloadTrafficPolicy(share.user_id, 'share_download_url'); // 仅在实际下载接口中校验和消耗下载流量,避免“可见性”受配额影响
const shareOwner = ownerPolicyState?.user || UserDB.findById(share.user_id); const shareOwner = UserDB.findById(share.user_id);
if (!shareOwner) { if (!shareOwner) {
return res.status(404).json({ return res.status(404).json({
success: false, success: false,

View File

@@ -791,6 +791,11 @@
color: #991b1b; color: #991b1b;
} }
body.enterprise-netdisk-share .download-alert {
margin-bottom: 12px;
animation: fadeInOut 0.2s ease;
}
body.enterprise-netdisk-share .view-controls { body.enterprise-netdisk-share .view-controls {
display: flex; display: flex;
gap: 8px; gap: 8px;
@@ -970,6 +975,17 @@
padding: 16px; padding: 16px;
} }
} }
@keyframes fadeInOut {
from {
opacity: 0;
transform: translateY(-4px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
</style> </style>
</head> </head>
<body class="enterprise-netdisk-share"> <body class="enterprise-netdisk-share">
@@ -1016,6 +1032,7 @@
<!-- 文件列表 --> <!-- 文件列表 -->
<div v-else-if="verified"> <div v-else-if="verified">
<div v-if="downloadAlertMessage" class="alert alert-error download-alert">{{ downloadAlertMessage }}</div>
<p class="share-meta-bar"> <p class="share-meta-bar">
分享者: <strong style="color: var(--text-primary);">{{ shareInfo.username }}</strong> | 分享者: <strong style="color: var(--text-primary);">{{ shareInfo.username }}</strong> |
创建时间: {{ formatDate(shareInfo.created_at) }} 创建时间: {{ formatDate(shareInfo.created_at) }}
@@ -1111,6 +1128,8 @@
files: [], files: [],
loading: true, loading: true,
errorMessage: '', errorMessage: '',
downloadAlertMessage: '',
downloadAlertTimer: null,
viewMode: "grid", // 视图模式: grid 大图标, list 列表(默认大图标) viewMode: "grid", // 视图模式: grid 大图标, list 列表(默认大图标)
// 主题 // 主题
currentTheme: 'dark', currentTheme: 'dark',
@@ -1176,6 +1195,7 @@
async verifyShare() { async verifyShare() {
this.errorMessage = ''; this.errorMessage = '';
this.downloadAlertMessage = '';
this.loading = true; this.loading = true;
try { try {
@@ -1288,10 +1308,28 @@
} }
} catch (error) { } catch (error) {
console.error('[分享下载] 获取下载链接失败:', error); console.error('[分享下载] 获取下载链接失败:', error);
this.errorMessage = '获取下载链接失败: ' + (error.response?.data?.message || error.message); const message = error.response?.data?.message || '当前网络繁忙,请稍后再试';
this.showDownloadAlert(message);
} }
}, },
showDownloadAlert(message) {
const safeMessage = typeof message === 'string' && message.trim()
? message.trim()
: '当前网络繁忙,请稍后再试';
this.downloadAlertMessage = safeMessage;
if (this.downloadAlertTimer) {
clearTimeout(this.downloadAlertTimer);
this.downloadAlertTimer = null;
}
this.downloadAlertTimer = setTimeout(() => {
this.downloadAlertMessage = '';
this.downloadAlertTimer = null;
}, 3000);
},
// 触发下载使用隐藏的a标签避免页面闪动 // 触发下载使用隐藏的a标签避免页面闪动
triggerDownload(url, filename) { triggerDownload(url, filename) {
const link = document.createElement('a'); const link = document.createElement('a');
@@ -1430,6 +1468,13 @@
} }
this.init(); this.init();
},
beforeUnmount() {
if (this.downloadAlertTimer) {
clearTimeout(this.downloadAlertTimer);
this.downloadAlertTimer = null;
}
} }
}).mount('#app'); }).mount('#app');
</script> </script>