From a791569b17314bfe47511a5be5318b9d4294c8d2 Mon Sep 17 00:00:00 2001 From: WanWanYun Date: Wed, 12 Nov 2025 22:50:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D:=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E5=AD=98=E5=82=A8=E5=88=87=E6=8D=A2=E9=80=BB=E8=BE=91=EF=BC=8C?= =?UTF-8?q?=E8=A7=A3=E5=86=B3SFTP=E9=85=8D=E7=BD=AE=E5=92=8C=E6=9D=83?= =?UTF-8?q?=E9=99=90=E5=88=87=E6=8D=A2=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 登录时智能修正存储类型: - 当用户为SFTP模式但未配置SFTP时,如果有本地存储权限,自动切换到本地存储 - 避免管理员更改用户权限后,用户登录时出现"加载文件失败"错误 2. SFTP配置后自动切换存储模式: - 用户成功配置SFTP后,自动切换到SFTP存储模式 - 无需用户手动再次切换,提升用户体验 3. 改进存储切换提示信息: - 当用户尝试切换到未配置的SFTP时,显示更友好的提示 - 明确告知用户配置完成后将自动切换到SFTP存储 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- frontend/app.js | 44 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 5 deletions(-) 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; }