浏览器兑换独立成页面并按斗鱼模式优化导入

新增 /huya/browser-exchange 页面(精英宝典下方),支持导入账号与
执行兑换,客服仅见已分配账号;账号管理页移除该功能。导入弹窗对齐
斗鱼操作台:服务端分页筛选、可搜索标签、无 CK 不展示、导入本页/
一键导入全部/导入选中;新增 /accounts/ids 接口与 workbench
browser_exchange scope。
This commit is contained in:
yml2213
2026-09-05 18:30:29 +08:00
parent 230d6c1918
commit 178eba1eea
11 changed files with 493 additions and 130 deletions
+26 -6
View File
@@ -315,10 +315,10 @@ def _require_huya_task_account_access(
raise HTTPException(status_code=403, detail="包含无权操作的虎牙账号")
def _elite_workbench_account_ids(db: Session, current: User) -> list[int]:
def _workbench_account_ids(db: Session, current: User, scope: str) -> list[int]:
query = db.query(HuyaWorkbenchAccount.account_id).filter(
HuyaWorkbenchAccount.user_id == current.id,
HuyaWorkbenchAccount.handbook_scope == "elite",
HuyaWorkbenchAccount.handbook_scope == scope,
)
if not _can_view_huya_all(current):
query = query.join(HuyaAccount, HuyaAccount.id == HuyaWorkbenchAccount.account_id).filter(
@@ -629,6 +629,26 @@ def accounts_summary(
}
@router.get("/accounts/ids")
def list_huya_account_ids(
search: str = "",
tag: str = "",
has_cookie: bool = False,
db: Session = Depends(get_db),
current: User = Depends(require_permission("huya:task")),
):
"""返回当前用户可见的全部账号 ID(不受分页限制),供工作台一键导入。"""
query = _filter_huya_accounts_query(
_visible_huya_accounts_query(db, current),
current,
tag=tag or None,
has_cookie=has_cookie,
search=search,
)
rows = query.with_entities(HuyaAccount.id).all()
return {"account_ids": [row[0] for row in rows], "total": len(rows)}
@router.post("/accounts/import-cookies")
def import_cookies(
req: HuyaCookieImport,
@@ -1821,12 +1841,12 @@ def update_config(
@router.get("/workbench-accounts")
def list_huya_workbench_accounts(
handbook_scope: str = Query(..., pattern="^elite$"),
handbook_scope: str = Query(..., pattern="^elite$|^browser_exchange$"),
db: Session = Depends(get_db),
current: User = Depends(require_permission("huya:task")),
):
"""读取当前用户的虎牙精英宝典账号集合。"""
ids = _elite_workbench_account_ids(db, current)
"""读取当前用户指定工作台(精英宝典/浏览器兑换)的账号集合。"""
ids = _workbench_account_ids(db, current, handbook_scope)
configured = db.query(HuyaWorkbench.id).filter(
HuyaWorkbench.user_id == current.id,
HuyaWorkbench.handbook_scope == handbook_scope,
@@ -1840,7 +1860,7 @@ def update_huya_workbench_accounts(
db: Session = Depends(get_db),
current: User = Depends(require_permission("huya:task")),
):
"""覆盖虎牙精英宝典账号集合,支持跨浏览器同步。"""
"""覆盖当前用户指定工作台(精英宝典/浏览器兑换)的账号集合,支持跨浏览器同步。"""
ids = sorted(set(req.account_ids))
if any(account_id < 1 for account_id in ids):
raise HTTPException(status_code=400, detail="无效的账号 ID")
+1 -1
View File
@@ -511,7 +511,7 @@ class HuyaTaskBatchRequest(BaseModel):
class HuyaWorkbenchAccountsUpdate(BaseModel):
handbook_scope: str = Field(..., pattern="^elite$")
handbook_scope: str = Field(..., pattern="^elite$|^browser_exchange$")
account_ids: list[int] = Field(default_factory=list)