-
Notifications
You must be signed in to change notification settings - Fork 1
feat(api): 实现 Dashboard API 客户端集成 #10
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
Open
Disaster-Terminator
wants to merge
2
commits into
main
Choose a base branch
from
feature/dashboard-api
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -87,5 +87,6 @@ screenshots/*.html | |
|
|
||
| # Trae 规格和文档 | ||
| .trae/spec/ | ||
| .trae/specs/ | ||
| .trae/documents/ | ||
| .trae/data/ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| # TASK: Dashboard API 集成 | ||
|
|
||
| > 分支: `feature/dashboard-api` | ||
| > 并行组: 第一组 | ||
| > 优先级: 🔴 最高 | ||
| > 预计时间: 3-4 天 | ||
| > 依赖: 无 | ||
|
|
||
| *** | ||
|
|
||
| ## 一、目标 | ||
|
|
||
| 利用已验证可用的 Dashboard API,增强积分检测能力,替代现有的 HTML 解析方案。 | ||
|
|
||
| *** | ||
|
|
||
| ## 二、背景 | ||
|
|
||
| ### 2.1 API 验证结果 | ||
|
|
||
| | API | 状态 | HTTP 状态码 | 备注 | | ||
| |-----|------|-------------|------| | ||
| | Dashboard API | ✅ 可用 | 200 | 返回完整用户数据 | | ||
|
|
||
| ### 2.2 API 端点 | ||
|
|
||
| ``` | ||
| GET https://rewards.bing.com/api/getuserinfo?type=1 | ||
| Headers: | ||
| Cookie: {session_cookies} | ||
| Referer: https://rewards.bing.com/ | ||
| ``` | ||
|
|
||
| ### 2.3 响应示例 | ||
|
|
||
| ```json | ||
| { | ||
| "dashboard": { | ||
| "userStatus": { | ||
| "levelInfo": { | ||
| "activeLevel": "newLevel3", | ||
| "activeLevelName": "Gold Member", | ||
| "progress": 1790, | ||
| "progressMax": 750 | ||
| }, | ||
| "availablePoints": 12345, | ||
| "counters": { | ||
| "pcSearch": [...], | ||
| "mobileSearch": [...] | ||
| } | ||
| }, | ||
| "dailySetPromotions": {...}, | ||
| "morePromotions": [...], | ||
| "punchCards": [...] | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| *** | ||
|
|
||
| ## 三、任务清单 | ||
|
|
||
| ### 3.1 数据结构定义 | ||
|
|
||
| - [ ] 创建 `src/api/__init__.py` | ||
| - [ ] 创建 `src/api/models.py` | ||
| - [ ] `DashboardData` dataclass | ||
| - [ ] `UserStatus` dataclass | ||
| - [ ] `LevelInfo` dataclass | ||
| - [ ] `Counters` dataclass | ||
| - [ ] `Promotion` dataclass | ||
| - [ ] `PunchCard` dataclass | ||
|
|
||
| ### 3.2 DashboardClient 实现 | ||
|
|
||
| - [ ] 创建 `src/api/dashboard_client.py` | ||
| - [ ] `get_dashboard_data()` - 获取完整 Dashboard 数据 | ||
| - [ ] `get_search_counters()` - 获取搜索计数器 | ||
| - [ ] `get_level_info()` - 获取会员等级信息 | ||
| - [ ] `get_promotions()` - 获取推广任务列表 | ||
| - [ ] `get_current_points()` - 获取当前积分 | ||
|
|
||
| ### 3.3 HTML Fallback 机制 | ||
|
|
||
| - [ ] 实现 API 失败时的 HTML 解析 fallback | ||
| - [ ] 从页面脚本提取 `var dashboard = {...}` | ||
|
|
||
| ### 3.4 集成与测试 | ||
|
|
||
| - [ ] 更新 `PointsDetector` 使用新 API | ||
| - [ ] 创建 `tests/unit/test_dashboard_client.py` | ||
| - [ ] 验证积分检测准确性 | ||
|
|
||
| *** | ||
|
|
||
| ## 四、参考资源 | ||
|
|
||
| ### 4.1 TS 项目参考 | ||
|
|
||
| | 文件 | 路径 | | ||
| |------|------| | ||
| | Dashboard API 实现 | `Microsoft-Rewards-Script/src/browser/BrowserFunc.ts` | | ||
| | 数据结构定义 | `Microsoft-Rewards-Script/src/interface/DashboardData.ts` | | ||
|
|
||
| ### 4.2 关键代码参考 | ||
|
|
||
| ```python | ||
| async def get_dashboard_data(self) -> DashboardData: | ||
| try: | ||
| response = await self._call_api() | ||
| if response.data and response.data.get('dashboard'): | ||
| return self._parse_dashboard(response.data['dashboard']) | ||
| except Exception as e: | ||
| self.logger.warn(f"API failed: {e}, trying HTML fallback") | ||
| return await self._html_fallback() | ||
| raise DashboardError("Failed to get dashboard data") | ||
| ``` | ||
|
|
||
| *** | ||
|
|
||
| ## 五、验收标准 | ||
|
|
||
| - [ ] DashboardClient 可成功调用 API | ||
| - [ ] 返回完整的用户数据(积分、等级、任务) | ||
| - [ ] HTML fallback 机制正常工作 | ||
| - [ ] 单元测试覆盖率 > 80% | ||
| - [ ] 无 mypy 类型错误 | ||
|
|
||
| *** | ||
|
|
||
| ## 六、合并条件 | ||
|
|
||
| - [ ] 所有测试通过 | ||
| - [ ] Code Review 通过 | ||
| - [ ] 文档更新完成 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| """API 模块 | ||
|
|
||
| 提供面向业务层的统一 API 访问入口,包括仪表盘相关的客户端封装以及数据模型。 | ||
| 该模块聚合了对外公开的主要类型,方便调用方通过 `api` 包进行导入和使用。 | ||
|
|
||
| 主要组件 | ||
| ------- | ||
| - ``DashboardClient``: 仪表盘 API 客户端,对外提供高层封装的请求接口 | ||
| - ``DashboardError``: 仪表盘相关错误类型,用于封装请求或解析过程中的异常 | ||
| - ``DashboardData``: 仪表盘整体数据模型 | ||
| - ``UserStatus``: 用户当前状态信息模型 | ||
| - ``LevelInfo``: 用户等级与经验值等信息模型 | ||
| - ``SearchCounter`` / ``SearchCounters``: 搜索计数与统计信息模型 | ||
| - ``Promotion``: 活动与促销信息模型 | ||
| - ``PunchCard``: 打卡与活跃度相关的数据模型 | ||
| """ | ||
|
|
||
| from .dashboard_client import DashboardClient, DashboardError | ||
| from .models import ( | ||
| DashboardData, | ||
| LevelInfo, | ||
| Promotion, | ||
| PunchCard, | ||
| SearchCounter, | ||
| SearchCounters, | ||
| UserStatus, | ||
| ) | ||
|
|
||
| __all__ = [ | ||
| "DashboardClient", | ||
| "DashboardError", | ||
| "DashboardData", | ||
| "UserStatus", | ||
Disaster-Terminator marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "LevelInfo", | ||
| "SearchCounter", | ||
| "SearchCounters", | ||
| "Promotion", | ||
| "PunchCard", | ||
| ] | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.