diff --git a/frontend/app.js b/frontend/app.js index 57170d1..0cd8ca5 100644 --- a/frontend/app.js +++ b/frontend/app.js @@ -298,7 +298,21 @@ handleDragLeave(e) { this.localQuota = this.user.local_storage_quota || 0; this.localUsed = this.user.local_storage_used || 0; - console.log('[登录] 存储权限:', this.storagePermission, '存储类型:', this.storageType); + console.log('[登录] 存储权限:', this.storagePermission, '存储类型:', this.storageType, 'SFTP配置:', this.user.has_ftp_config); + + // 智能存储类型修正:如果当前是SFTP但未配置,且用户有本地存储权限,自动切换到本地 + if (this.storageType === 'sftp' && !this.user.has_ftp_config) { + if (this.storagePermission === 'local_only' || this.storagePermission === 'user_choice') { + console.log('[登录] SFTP未配置但用户有本地存储权限,自动切换到本地存储'); + this.storageType = 'local'; + // 异步更新到后端(不等待,避免阻塞登录流程) + axios.post( + `${this.apiBase}/api/user/switch-storage`, + { storage_type: 'local' }, + { headers: { Authorization: `Bearer ${this.token}` } } + ).catch(err => console.error('[登录] 自动切换存储类型失败:', err)); + } + } // 启动定期检查用户配置 this.startProfileSync(); @@ -374,6 +388,25 @@ handleDragLeave(e) { alert('SFTP配置已保存!'); // 更新用户信息 this.user.has_ftp_config = 1; + + // 如果用户有 user_choice 权限,自动切换到 SFTP 存储 + if (this.storagePermission === 'user_choice' || this.storagePermission === 'sftp_only') { + try { + const switchResponse = await axios.post( + `${this.apiBase}/api/user/switch-storage`, + { storage_type: 'sftp' }, + { headers: { Authorization: `Bearer ${this.token}` } } + ); + + if (switchResponse.data.success) { + this.storageType = 'sftp'; + console.log('[SFTP配置] 已自动切换到SFTP存储模式'); + } + } catch (err) { + console.error('[SFTP配置] 自动切换存储模式失败:', err); + } + } + // 刷新到文件页面 this.currentView = 'files'; this.loadFiles('/'); @@ -1516,7 +1549,6 @@ handleDragLeave(e) { console.error('加载用户资料失败:', error); } }, - // 启动定期检查用户配置 startProfileSync() { // 清除已有的定时器 @@ -1543,12 +1575,14 @@ handleDragLeave(e) { } }, - // 用户切换存储方式 + // 用户切换存储方式 async switchStorage(type) { // 检查是否尝试切换到SFTP但未配置 if (type === 'sftp' && !this.user.has_ftp_config) { - this.showToast('warning', '提示', '请先在设置页面配置SFTP信息'); - this.currentView = 'settings'; + const goToSettings = confirm('您还未配置SFTP服务器。\n\n是否现在前往设置页面进行配置?配置完成后将自动切换到SFTP存储。'); + if (goToSettings) { + this.currentView = 'settings'; + } return; }