-
Notifications
You must be signed in to change notification settings - Fork 0
refactor: 重构 OpenRouter API 客户端并改进 AI 翻译功能 #49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
在书签详情视图模型中添加对OpenRouter API密钥的检查,如果未配置则阻止翻译操作 移除AI设置屏幕中API密钥的必填验证,改为在翻译时检查 close #39
添加ReadeckApiClient的单元测试,包括配置测试、书签操作测试和标签测试 添加测试用的书签和标签数据类TestBookmarkData和TestLabelData 生成Mockito模拟类用于HTTP客户端测试
添加 http.Client 参数以支持自定义 HTTP 客户端 新增 dispose 方法用于释放 http.Client 资源 替换所有直接使用 http 为使用 _httpClient
移除未使用的HTTP-Referer头并添加mock测试文件
Walkthrough本次变更主要对 OpenRouter API 客户端的构造方式进行了增强,允许通过依赖注入自定义 HTTP 客户端,并增加了资源释放方法。Bookmark 详情 ViewModel 增加了对 SettingsRepository 的依赖,并在翻译前校验 API Key 配置。测试代码大量补充了单元测试和模拟实现。 Changes
Sequence Diagram(s)sequenceDiagram
participant ViewModel as BookmarkDetailViewModel
participant SettingsRepo as SettingsRepository
participant APIClient as OpenRouterApiClient
participant HTTP as http.Client
ViewModel->>SettingsRepo: 获取 OpenRouter API Key
alt API Key 未配置
ViewModel-->>ViewModel: 抛出“未配置 API Key”异常
else API Key 已配置
ViewModel->>APIClient: 发起翻译请求
APIClient->>HTTP: 发送 HTTP 请求
HTTP-->>APIClient: 返回响应
APIClient-->>ViewModel: 返回翻译结果
end
Possibly related PRs
Suggested labels
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (10)
💤 Files with no reviewable changes (1)
🧰 Additional context used🧠 Learnings (5)📓 Common learningslib/routing/router.dart (1)lib/ui/bookmarks/view_models/bookmark_detail_viewmodel.dart (2)test/unit/data/service/openrouter_api_client_test.dart (2)test/unit/data/service/readeck_api_client_test.dart (2)⏰ Context from checks skipped due to timeout of 90000ms (1)
🔇 Additional comments (15)
✨ Finishing Touches🧪 Generate Unit Tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## beta #49 +/- ##
=========================================
+ Coverage 2.17% 10.09% +7.91%
=========================================
Files 58 58
Lines 3403 3408 +5
=========================================
+ Hits 74 344 +270
+ Misses 3329 3064 -265
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Summary by CodeRabbit
新功能
功能改进
Bug 修复
测试
杂项