feat(huya): 精英宝典账号支持转入外部单协作
This commit is contained in:
@@ -50,6 +50,7 @@ from .workbench import (
|
||||
stop_batch,
|
||||
task_types,
|
||||
tasks_summary,
|
||||
transfer_workbench_to_collab,
|
||||
update_config,
|
||||
update_huya_workbench_accounts,
|
||||
ws_huya_logs,
|
||||
@@ -105,6 +106,7 @@ __all__ = [
|
||||
"task_types",
|
||||
"tasks_summary",
|
||||
"test_sms_url_endpoint",
|
||||
"transfer_workbench_to_collab",
|
||||
"update_config",
|
||||
"update_huya_workbench_accounts",
|
||||
"ws_huya_logs",
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
from fastapi import APIRouter
|
||||
|
||||
from ...schemas import HuyaWorkbenchTransferToCollab
|
||||
from ._common import *
|
||||
|
||||
router = APIRouter()
|
||||
@@ -114,6 +115,51 @@ def update_huya_workbench_accounts(
|
||||
return {"account_ids": ids, "success": True}
|
||||
|
||||
|
||||
@router.post("/workbench-accounts/transfer-to-collab")
|
||||
def transfer_workbench_to_collab(
|
||||
req: HuyaWorkbenchTransferToCollab,
|
||||
db: Session = Depends(get_db),
|
||||
current: User = Depends(require_permission("huya:task")),
|
||||
):
|
||||
"""把单个精英宝典账号移出工作台,并返回其网页 CK 供外部单新建表单使用。"""
|
||||
_require_huya_perm(current, "huya:collab:edit")
|
||||
_require_huya_task_account_access(db, current, [req.account_id])
|
||||
|
||||
membership = (
|
||||
db.query(HuyaWorkbenchAccount)
|
||||
.filter(
|
||||
HuyaWorkbenchAccount.user_id == current.id,
|
||||
HuyaWorkbenchAccount.handbook_scope == "elite",
|
||||
HuyaWorkbenchAccount.account_id == req.account_id,
|
||||
)
|
||||
.first()
|
||||
)
|
||||
if membership is None:
|
||||
raise HTTPException(status_code=404, detail="该账号不在精英宝典工作台")
|
||||
|
||||
account = db.query(HuyaAccount).filter(HuyaAccount.id == req.account_id).first()
|
||||
ck_text = str(account.cookie or "").strip() if account else ""
|
||||
if not ck_text:
|
||||
raise HTTPException(
|
||||
status_code=400, detail="该账号没有可用 Cookie,无法转入外部单协作"
|
||||
)
|
||||
|
||||
db.delete(membership)
|
||||
record_audit(
|
||||
db,
|
||||
current,
|
||||
action="huya:workbench:transfer_collab",
|
||||
target=f"huya_account:{account.id}",
|
||||
detail={"account_id": account.id, "uid": account.uid},
|
||||
)
|
||||
db.commit()
|
||||
return {
|
||||
"account_id": account.id,
|
||||
"ck_text": ck_text,
|
||||
"success": True,
|
||||
}
|
||||
|
||||
|
||||
@router.get("/goods", response_model=list[HuyaGoodsOut])
|
||||
def list_goods(
|
||||
db: Session = Depends(get_db),
|
||||
|
||||
@@ -1199,6 +1199,12 @@ class HuyaWorkbenchCookieImport(BaseModel):
|
||||
handbook_scope: str = Field("elite", pattern="^elite$|^browser_exchange$")
|
||||
|
||||
|
||||
class HuyaWorkbenchTransferToCollab(BaseModel):
|
||||
"""精英宝典工作台把单个账号转入外部单协作。"""
|
||||
|
||||
account_id: int = Field(..., gt=0)
|
||||
|
||||
|
||||
class HuyaBrowserExchangeRequest(BaseModel):
|
||||
"""浏览器兑换的目标页选择(常量见 services/huya_exchange_targets.py)。"""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user