From 53e77ebf4e0c38a8ba1615534b4e9c2e295ed734 Mon Sep 17 00:00:00 2001 From: yuyx <237899745@qq.com> Date: Tue, 17 Feb 2026 19:08:47 +0800 Subject: [PATCH] fix: precheck local share download quota at download-url stage --- backend/server.js | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/backend/server.js b/backend/server.js index 97fedc3..e182c50 100644 --- a/backend/server.js +++ b/backend/server.js @@ -5892,6 +5892,44 @@ app.post('/api/share/:code/download-url', shareRateLimitMiddleware, async (req, // 本地存储:继续走后端下载 if (storageType !== 'oss') { + if (!ownerTrafficState.isUnlimited) { + const { StorageInterface } = require('./storage'); + const userForStorage = buildStorageUserContext(shareOwner, { + current_storage_type: storageType + }); + const storageInterface = new StorageInterface(userForStorage); + let storage = null; + try { + storage = await storageInterface.connect(); + const fileStats = await storage.stat(normalizedFilePath); + const fileSize = Number(fileStats?.size || 0); + if (!Number.isFinite(fileSize) || fileSize <= 0) { + return res.status(503).json({ + success: false, + message: getBusyDownloadMessage() + }); + } + if (fileSize > ownerTrafficState.remaining) { + return res.status(503).json({ + success: false, + message: getBusyDownloadMessage() + }); + } + } catch (statError) { + if (statError && (statError.code === 'ENOENT' || String(statError.message || '').includes('不存在'))) { + return res.status(404).json({ + success: false, + message: '文件不存在' + }); + } + throw statError; + } finally { + if (storage) { + await storage.end(); + } + } + } + let downloadUrl = `${getSecureBaseUrl(req)}/api/share/${code}/download-file?path=${encodeURIComponent(normalizedFilePath)}`; if (share.share_password) {