修复: 优化存储切换逻辑,解决SFTP配置和权限切换问题
1. 登录时智能修正存储类型: - 当用户为SFTP模式但未配置SFTP时,如果有本地存储权限,自动切换到本地存储 - 避免管理员更改用户权限后,用户登录时出现"加载文件失败"错误 2. SFTP配置后自动切换存储模式: - 用户成功配置SFTP后,自动切换到SFTP存储模式 - 无需用户手动再次切换,提升用户体验 3. 改进存储切换提示信息: - 当用户尝试切换到未配置的SFTP时,显示更友好的提示 - 明确告知用户配置完成后将自动切换到SFTP存储 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -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() {
|
||||
// 清除已有的定时器
|
||||
@@ -1547,8 +1579,10 @@ handleDragLeave(e) {
|
||||
async switchStorage(type) {
|
||||
// 检查是否尝试切换到SFTP但未配置
|
||||
if (type === 'sftp' && !this.user.has_ftp_config) {
|
||||
this.showToast('warning', '提示', '请先在设置页面配置SFTP信息');
|
||||
const goToSettings = confirm('您还未配置SFTP服务器。\n\n是否现在前往设置页面进行配置?配置完成后将自动切换到SFTP存储。');
|
||||
if (goToSettings) {
|
||||
this.currentView = 'settings';
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user