feat(douyu): 精英宝典工作台支持 CK 检测与失效重登
This commit is contained in:
@@ -41,6 +41,7 @@ from ..models import (
|
||||
)
|
||||
from ..permissions import user_has_permission
|
||||
from ..schemas import (
|
||||
CookieReloginRequest,
|
||||
DouyuConfigOut,
|
||||
DouyuConfigUpdate,
|
||||
DouyuGoodsOut,
|
||||
@@ -333,6 +334,8 @@ def _account_out(account: Account) -> DouyuTaskAccountOut:
|
||||
uid=account.uid or "",
|
||||
nickname=account.nickname or "",
|
||||
tag=account.tag or "",
|
||||
ck_check_status=account.ck_check_status or "",
|
||||
ck_checked_at=account.ck_checked_at,
|
||||
points=account.points,
|
||||
game_name=account.game_name or "",
|
||||
game_channel=account.game_channel or "",
|
||||
@@ -471,6 +474,54 @@ def list_task_account_ids(
|
||||
return {"account_ids": account_ids, "total": len(account_ids)}
|
||||
|
||||
|
||||
@router.post("/accounts/ck-check")
|
||||
def check_task_accounts_ck(
|
||||
ids: str = Query(""),
|
||||
db: Session = Depends(get_db),
|
||||
current: User = Depends(require_permission("douyu:task")),
|
||||
):
|
||||
"""工作台批量检测 CK,只返回有效性,不暴露 Cookie 原文。
|
||||
|
||||
复用 CK 操作页的检测逻辑:检测结果会写回 ``accounts.ck_check_status``,
|
||||
因此导入账号后刷新列表仍能看到「有效 / 失效」。
|
||||
"""
|
||||
from .cookies import _check_cookies
|
||||
|
||||
return _check_cookies(ids, db, current, detailed=False)
|
||||
|
||||
|
||||
@router.post("/accounts/relogin-invalid")
|
||||
def relogin_invalid_task_accounts(
|
||||
req: CookieReloginRequest,
|
||||
db: Session = Depends(get_db),
|
||||
current: User = Depends(get_current_user),
|
||||
):
|
||||
"""重登工作台选中的 CK 失效账号(仅超级管理员)。"""
|
||||
if current.role != "super_admin":
|
||||
raise HTTPException(status_code=403, detail="仅超级管理员可重登失效账号")
|
||||
ids = sorted({int(item) for item in req.ids if int(item) > 0})
|
||||
if not ids:
|
||||
raise HTTPException(status_code=400, detail="请先勾选账号")
|
||||
accounts = (
|
||||
_visible_task_accounts_query(db, current)
|
||||
.filter(
|
||||
Account.id.in_(ids),
|
||||
Account.ck_check_status == "invalid",
|
||||
)
|
||||
.all()
|
||||
)
|
||||
if not accounts:
|
||||
raise HTTPException(status_code=400, detail="选中的账号里没有 CK 失效账号")
|
||||
from .cookies import _start_relogin_accounts
|
||||
|
||||
return _start_relogin_accounts(
|
||||
accounts,
|
||||
db,
|
||||
current,
|
||||
action="douyu:task:relogin_invalid",
|
||||
)
|
||||
|
||||
|
||||
@router.get("/workbench-accounts")
|
||||
def list_workbench_accounts(
|
||||
handbook_scope: str = Query(..., pattern="^(elite|esports|peace)$"),
|
||||
|
||||
@@ -1025,6 +1025,8 @@ class DouyuTaskAccountOut(BaseModel):
|
||||
uid: str = ""
|
||||
nickname: str = ""
|
||||
tag: str = ""
|
||||
ck_check_status: str = ""
|
||||
ck_checked_at: datetime | None = None
|
||||
points: int | None = None
|
||||
game_name: str = ""
|
||||
game_channel: str = ""
|
||||
|
||||
Reference in New Issue
Block a user