Repository navigation
feat: 新增 /v1/checkin-status 与 /v1/checkin(每日签到透传) #7
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
Merged
Merged
Changes from all commits
Commits
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
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 |
|---|---|---|
|
|
@@ -815,6 +815,61 @@ async def health(): | |
| } | ||
|
|
||
|
|
||
| # ============================================================================ | ||
| # 端点:/v1/checkin-status 与 /v1/checkin(每日签到透传) | ||
| # ============================================================================ | ||
|
|
||
| async def _billing_post(path: str) -> dict[str, Any]: | ||
| """用本地已登录会话调用官方 billing 端点并返回原始 JSON。 | ||
|
|
||
| 自动处理 401:先走 ensure_authenticated 刷新 token 再重试一次。 | ||
| """ | ||
| state = get_state() | ||
| url = state.client.endpoint.rstrip("/") + path | ||
| async with httpx.AsyncClient(timeout=httpx.Timeout(10.0)) as client: | ||
| resp = await client.post(url, json={}, headers=state.client.auth_headers()) | ||
| if resp.status_code == 401: | ||
| # token 过期:触发一次刷新后重试 | ||
| try: | ||
| await asyncio.to_thread(state.client.ensure_authenticated, False) | ||
| except Exception: | ||
| pass | ||
| resp = await client.post(url, json={}, headers=state.client.auth_headers()) | ||
| try: | ||
| return resp.json() | ||
| except Exception: | ||
| return {"code": resp.status_code, "msg": f"non-JSON response (HTTP {resp.status_code})"} | ||
|
|
||
|
|
||
| @app.get("/v1/checkin-status") | ||
| async def checkin_status(): | ||
| """查询每日签到活动状态(透传官方 /v2/billing/meter/checkin-status)。""" | ||
| state = get_state() | ||
| try: | ||
| state.ensure_auth() | ||
| except Exception as e: | ||
| raise HTTPException(status_code=503, detail={"error": {"message": f"not authenticated: {e}", "type": "auth_error"}}) | ||
| result = await _billing_post("/v2/billing/meter/checkin-status") | ||
| return {"status": "ok", "upstream": result} | ||
|
|
||
|
|
||
| @app.post("/v1/checkin") | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Blocking: 返回包装对象会改变上游 |
||
| async def checkin(): | ||
| """执行每日签到(透传官方 /v2/billing/meter/daily-checkin)。 | ||
|
|
||
| 业务结果原样返回:code=0 且 data 非空为领取成功;已签到/活动结束等 | ||
| 业务拒绝通过上游 data.status / msg 区分,这里不做二次解释。 | ||
| """ | ||
| state = get_state() | ||
| try: | ||
| state.ensure_auth() | ||
| except Exception as e: | ||
| raise HTTPException(status_code=503, detail={"error": {"message": f"not authenticated: {e}", "type": "auth_error"}}) | ||
| result = await _billing_post("/v2/billing/meter/daily-checkin") | ||
| diagnostic("checkin_claim_result", code=result.get("code"), msg=result.get("msg")) | ||
| return {"status": "ok", "upstream": result} | ||
|
|
||
|
|
||
| # ============================================================================ | ||
| # 端点:/v1/models | ||
| # ============================================================================ | ||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Blocking:
_billing_post固定client.post,导致/v1/checkin-status虽然对外是 GET,向上游却发送 POST。请支持 method 并保证 GET 不发送多余 JSON body。