diff --git a/backend/server.js b/backend/server.js index 389648f..6121a3e 100644 --- a/backend/server.js +++ b/backend/server.js @@ -1346,8 +1346,6 @@ app.post('/api/share/:code/verify', async (req, res) => { responseData.file = shareFileCache.get(code); } else { // 缓存未命中,查询存储 - const storageType = share.storage_type || 'sftp'; - console.log(`[缓存未命中] 分享码: ${code},存储类型: ${storageType}`); try { // 获取分享者的用户信息 const shareOwner = UserDB.findById(share.user_id); @@ -1355,6 +1353,10 @@ app.post('/api/share/:code/verify', async (req, res) => { throw new Error('分享者不存在'); } + // 使用分享者当前的存储类型(而不是分享创建时的存储类型) + const storageType = shareOwner.current_storage_type || 'sftp'; + console.log(`[缓存未命中] 分享码: ${code},存储类型: ${storageType} (分享者当前)`); + // 使用统一存储接口 const { StorageInterface } = require('./storage'); const userForStorage = { @@ -1409,7 +1411,7 @@ app.post('/api/share/:code/verify', async (req, res) => { const httpBaseUrl = share.http_download_base_url || ''; const baseUrl = httpBaseUrl ? httpBaseUrl.replace(/\/+$/, '') : ''; const normalizedFilePath = filePath.startsWith('/') ? filePath : `/${filePath}`; - const storageType = share.storage_type || 'sftp'; + const storageType = shareOwner.current_storage_type || 'sftp'; const httpDownloadUrl = (storageType === 'sftp' && baseUrl) ? `${baseUrl}${normalizedFilePath}` : null; responseData.file = { @@ -1472,8 +1474,8 @@ app.post('/api/share/:code/list', async (req, res) => { // 使用统一存储接口,根据分享的storage_type选择存储后端 const { StorageInterface } = require('./storage'); - const storageType = share.storage_type || 'sftp'; - console.log(`[分享列表] 存储类型: ${storageType}, 分享路径: ${share.share_path}`); + const storageType = shareOwner.current_storage_type || 'sftp'; + console.log(`[分享列表] 存储类型: ${storageType} (分享者当前), 分享路径: ${share.share_path}`); // 临时构造用户对象以使用存储接口 const userForStorage = { @@ -1657,8 +1659,8 @@ app.get('/api/share/:code/download-file', async (req, res) => { // 使用统一存储接口,根据分享的storage_type选择存储后端 const { StorageInterface } = require('./storage'); - const storageType = share.storage_type || 'sftp'; - console.log(`[分享下载] 存储类型: ${storageType}, 文件路径: ${filePath}`); + const storageType = shareOwner.current_storage_type || 'sftp'; + console.log(`[分享下载] 存储类型: ${storageType} (分享者当前), 文件路径: ${filePath}`); // 临时构造用户对象以使用存储接口 const userForStorage = {