111 lines
3.3 KiB
Markdown
111 lines
3.3 KiB
Markdown
# Market Backend Metrics Design
|
|
|
|
## Goal
|
|
|
|
Connect the current Chrome extension to the real backend search API and display six backend metrics in the plugin UI, while preserving the existing two Xingtu rate columns.
|
|
|
|
## Confirmed Decisions
|
|
|
|
- Keep the existing two Xingtu metrics unchanged:
|
|
- `singleVideoAfterSearchRate`
|
|
- `personalVideoAfterSearchRate`
|
|
- Add one new UI column named `秒探指标`.
|
|
- Render the six backend metrics inside that column as a compact 2-column metrics panel:
|
|
- `avg_after_view_search_rate`
|
|
- `avg_after_view_search_cnt`
|
|
- `avg_a3_increase_cnt`
|
|
- `avg_new_a3_rate`
|
|
- `cpa3`
|
|
- `cp_search`
|
|
- Fetch backend metrics through the background service worker, not directly from the content script.
|
|
- Use Logto access tokens from the existing background auth flow.
|
|
- Query the backend by `star_id`, not by nickname.
|
|
- Send one batched request per visible page of creators.
|
|
- Use a code-level default backend base URL. Do not build a settings UI in this change.
|
|
- Do not change CSV export or batch submission payloads in this change.
|
|
|
|
## API Contract
|
|
|
|
- Base URL:
|
|
- default to `http://192.168.31.29:8083`
|
|
- Endpoint:
|
|
- `POST /api/v1/history/talents/search`
|
|
- Headers:
|
|
- `Authorization: Bearer <Logto access token>`
|
|
- `Content-Type: application/json`
|
|
- Request body:
|
|
|
|
```json
|
|
{
|
|
"type": "star_id",
|
|
"values": ["7252982749131178039", "7290491710910496809"],
|
|
"page": 1,
|
|
"size": 100
|
|
}
|
|
```
|
|
|
|
## Architecture
|
|
|
|
### Background
|
|
|
|
- Add a new background message for backend metrics search.
|
|
- The background handler:
|
|
- gets the current Logto access token
|
|
- calls the backend search API
|
|
- returns parsed metric rows to the content script
|
|
|
|
This follows the same rule already used for protected API and batch submission: token-bearing business requests belong in the background layer.
|
|
|
|
### Content
|
|
|
|
- Replace per-row metric loading with page-level batched loading for backend metrics.
|
|
- Collect all visible `authorId` values from the current page.
|
|
- Send them to the background as `star_id[]`.
|
|
- Map the backend response back to rows by `star_id`.
|
|
|
|
### UI
|
|
|
|
- Keep the old two columns where they are today.
|
|
- Add one new `秒探指标` column.
|
|
- Each cell shows:
|
|
- `加载中...`
|
|
- a compact 6-metric panel
|
|
- `暂无数据`
|
|
- `加载失败`
|
|
|
|
## Data Model
|
|
|
|
Add a new backend metrics structure to market records:
|
|
|
|
- `afterViewSearchRate`
|
|
- `afterViewSearchCount`
|
|
- `a3IncreaseCount`
|
|
- `newA3Rate`
|
|
- `cpa3`
|
|
- `cpSearch`
|
|
|
|
The old Xingtu rates stay in the existing `rates` structure.
|
|
|
|
## Failure Handling
|
|
|
|
- No token: show `加载失败`
|
|
- Backend request failure: show `加载失败`
|
|
- Backend success but row missing in response: show `暂无数据`
|
|
- Partial page matches: render matched rows, mark unmatched rows as `暂无数据`
|
|
|
|
## Testing
|
|
|
|
- Add failing tests first for:
|
|
- backend metrics request message handling
|
|
- backend metrics client request/response mapping
|
|
- page-level batch loading by `star_id`
|
|
- UI rendering of the new `秒探指标` column for loading, success, missing, and failure states
|
|
- Run focused tests first, then full `npm test`, then `npm run build`
|
|
|
|
## Out of Scope
|
|
|
|
- Popup-based backend URL settings
|
|
- CSV export changes for the six backend metrics
|
|
- Batch submit payload changes
|
|
- Cross-page deduplicated backend caching beyond current in-memory record storage
|