Skip to content

Conversation

@johnnyee
Copy link
Contributor

@johnnyee johnnyee commented Jan 5, 2026

Summary

  • 修复 Issue 接口不返回用量数据 #26:接口不返回用量数据
  • /api/usage 返回无效数据(creditLimit=null, subscriptionEntityList=null)时,自动 fallback 到 /api/subscription 获取用量数据

问题原因

88code 的 /api/usage 接口返回的关键字段全是 null,导致状态栏无法正确显示用量。

解决方案

采用双重保障策略:优先使用原接口,失败时 fallback

  1. 添加自定义反序列化函数处理 null 值(转换为默认值)
  2. 新增 is_valid() 方法判断 usage 数据是否有效
  3. 新增 SubscriptionPlan 结构体解析嵌套的 creditLimit
  4. 新增 from_subscriptions() 方法从订阅数据构造等价的 UsageData
  5. get_usage() 中加入 fallback 逻辑
  6. 修复 fetch_usage_with_cache() 传入正确的 subscription_url

优势

  • 向后兼容:88code 修复接口后自动恢复原方案
  • 当前可用:接口没修复时 subscription 方案兜底
  • 最小改动:原方案代码基本不动,只加判断层
  • 风险隔离:新方案只在原方案失败时才启用

Test plan

  • 本地编译通过
  • 本地测试:正确显示 PLUS 套餐的用量和进度条
  • cargo fmt 格式化通过

Closes #26

🤖 Generated with Claude Code

修复 Issue #26:接口不返回用量数据

## 问题
88code 的 /api/usage 接口返回的 creditLimit、currentCredits、
subscriptionEntityList 字段全是 null,导致状态栏无法正确显示用量。

## 解决方案
采用双重保障策略:优先使用 /api/usage,失败时 fallback 到 /api/subscription

1. 添加自定义反序列化函数处理 null 值(转换为默认值)
2. 新增 is_valid() 方法判断 usage 数据是否有效
3. 新增 SubscriptionPlan 结构体解析嵌套的 creditLimit
4. 新增 from_subscriptions() 方法从订阅数据构造等价的 UsageData
5. 在 get_usage() 中加入 fallback 逻辑
6. 修复 fetch_usage_with_cache() 传入正确的 subscription_url

## 优势
- 向后兼容:88code 修复接口后自动恢复原方案
- 当前可用:接口没修复时 subscription 方案兜底
- 最小改动:原方案代码基本不动,只加判断层

Closes #26

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@johnnyee johnnyee merged commit e37aaf6 into main Jan 5, 2026
6 checks passed
johnnyee added a commit that referenced this pull request Jan 5, 2026
- 在分支列表中添加 fix/issue-26-usage-api-fallback
- 在已提交的 PR 中添加 PR #27
- 添加详细的 Issue #26 修复说明文档

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

接口不返回用量数据

2 participants