Skip to content

fix: 保存自动备份前置同步 WebDAV、恢复兼容后端格式、文件名加时间戳#20

Merged
lostiv merged 1 commit into
mainfrom
fix/autosync
May 12, 2026
Merged

fix: 保存自动备份前置同步 WebDAV、恢复兼容后端格式、文件名加时间戳#20
lostiv merged 1 commit into
mainfrom
fix/autosync

Conversation

@lostiv
Copy link
Copy Markdown
Owner

@lostiv lostiv commented May 12, 2026

No description provided.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 12, 2026

Review Change Stack
No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: de8d8961-e589-4e4c-bc5a-3d4366d66374

📥 Commits

Reviewing files that changed from the base of the PR and between c5ec1a0 and bf6f321.

📒 Files selected for processing (1)
  • src/components/settings/BackupPanel.tsx
📜 Recent review details
🧰 Additional context used
📓 Path-based instructions (2)
src/components/**

⚙️ CodeRabbit configuration file

src/components/**: React 组件目录(TypeScript + Tailwind CSS)。审查时请关注: 1. 是否同时兼容暗色(dark: 前缀)和亮色主题 2. 响应式布局是否完整(Tailwind 断点系统:sm/md/lg/xl) 3. Props 类型定义是否完整(TypeScript interface) 4. 组件是否保持单一职责 5. 无障碍访问(aria-label、role、键盘导航) 6. React.memo / useMemo / useCallback 的使用是否合理

Files:

  • src/components/settings/BackupPanel.tsx
src/components/settings/**

⚙️ CodeRabbit configuration file

src/components/settings/**: 设置面板组件。审查时请关注: 1. 表单状态管理和输入校验 2. 多语言文本处理(t(zh, en) 函数) 3. API 密钥/密码等敏感信息的输入框类型(type="password") 4. 异步操作的状态反馈(loading/error/success)

Files:

  • src/components/settings/BackupPanel.tsx
🔇 Additional comments (5)
src/components/settings/BackupPanel.tsx (5)

101-104: 逻辑合理,确保后端配置同步在前。

启用自动备份时先同步 WebDAV 配置到后端,保证后端校验时有最新的活跃配置,避免因配置不同步导致的自动备份失败。实现符合预期。


154-154: 文件名格式改进正确。

使用 replace(/:/g, '-') 移除冒号确保跨平台兼容(Windows 文件名不支持冒号),replace(/\..+/, '') 移除毫秒和时区后缀使文件名更简洁。toISOString() 始终包含毫秒部分,正则表达式可正常工作。


185-189: 选择逻辑完善,覆盖边界情况。

正确处理三种场景:

  1. 之前选中的文件已被删除 → 自动选择第一个
  2. 无备份文件 → 清空选择
  3. 选择仍有效 → 保持不变

227-255: 后端格式兼容转换实现良好。

正确处理 snake_case → camelCase 映射,加密字段(api_key_encryptedpassword_encrypted)使用 '***' 占位符掩码,与下游恢复逻辑(Lines 296-310)配合正确保留现有密钥。

Record<string, unknown> 类型虽然松散,但作为防御性解析处理历史格式数据是合理的。


340-340: 恢复后刷新状态,保持 UI 同步。

恢复操作可能影响自动备份配置,调用 loadAutoStatus() 确保状态信息及时更新,用户体验更一致。


📝 Walkthrough

Summary by CodeRabbit

更新说明

  • Bug Fixes
    • 改进备份文件命名,现采用基于时间戳的格式
    • 当之前选择的备份文件缺失时,自动选择第一个可用备份
    • 增强了旧版备份格式的兼容性处理
    • 备份恢复完成后,自动刷新自动备份状态

概览

BackupPanel组件增强了备份生命周期管理,新增WebDAV配置自动同步、改进备份文件选择逻辑、实现向后兼容的格式转换,以及还原后的自动备份状态刷新。

变更详情

备份还原功能增强

层级 / 文件 摘要
自动备份设置与WebDAV同步
src/components/settings/BackupPanel.tsx
saveAutoSettings在启用自动备份时,持久化备份设置前先同步WebDAV配置到后端。
备份文件管理与选择优化
src/components/settings/BackupPanel.tsx
备份文件名采用时间戳格式;加载备份列表时若选择失效自动切换到首个备份,列表为空则清空选择。
还原流程兼容性与状态刷新
src/components/settings/BackupPanel.tsx
还原流程检测并转换旧版snake_case格式为camelCase,掩码处理加密字段;成功还原后刷新自动备份计时状态。

代码审查重点

  • WebDAV同步时序:确认syncWebDAVConfigs调用在配置持久化前执行,防止配置不一致
  • 文件选择容错性:验证空列表、失效选择的边界情况处理正确性
  • 向后兼容映射:检查旧格式字段(ai_configswebdav_configscategories)到新格式的转换完整性和加密值掩码正确性
  • 状态同步:确保loadAutoStatus()调用时序避免竞态条件,后端状态与前端同步

相关PRs

建议标签

frontend, bug


🎯 3 (中等) | ⏱️ ~20 分钟

🚥 Pre-merge checks | ✅ 3 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive 未提供拉取请求描述,但鉴于标题和提交摘要已清晰说明目的,此项为可接受状态。 建议补充简要描述,说明为什么需要这些变更及其影响范围,便于审阅者快速理解背景和测试要点。
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed 标题遵循 Conventional Commits 格式(fix: 类型),描述清晰准确地对应变更内容(WebDAV 同步、兼容后端格式、文件名时间戳)。
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/autosync
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch fix/autosync

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot added bug Something isn't working frontend labels May 12, 2026
@lostiv lostiv merged commit f8f36ca into main May 12, 2026
1 check passed
@lostiv lostiv deleted the fix/autosync branch May 12, 2026 06:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working frontend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant