fix: precheck local share download quota at download-url stage
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user