添加虎牙自动注册

This commit is contained in:
yml2213
2026-07-06 00:31:34 +08:00
parent 3f50d962a0
commit af98ea8416
12 changed files with 1060 additions and 19 deletions
+55
View File
@@ -19,6 +19,7 @@ from core.huya import (
send_huya_sms_code,
)
from core.huya.cookie_utils import normalize_huya_cookie
from core.sms_provider import parse_sms_lines
from ..database import SessionLocal, get_db
from ..deps import authenticate_websocket, get_current_user, require_permission
@@ -29,6 +30,8 @@ from ..schemas import (
AccountTag,
BatchAssign,
HuyaAccountOut,
HuyaAutoRegisterBatchOut,
HuyaAutoRegisterRequest,
HuyaConfigOut,
HuyaConfigUpdate,
HuyaCookieImport,
@@ -55,6 +58,7 @@ from ..services.huya_service import (
upsert_huya_cookie,
)
from ..services.huya_runner import HuyaBatchRunner, huya_batch_registry
from ..services.huya_register_runner import huya_register_registry
router = APIRouter(prefix="/api/huya", tags=["虎牙"])
@@ -337,6 +341,57 @@ def sms_login_account(
}
@router.post("/register/batches", response_model=HuyaAutoRegisterBatchOut)
def create_auto_register_batch(
req: HuyaAutoRegisterRequest,
current: User = Depends(get_current_user),
):
"""启动虎牙手机号自动注册批次。"""
_require_huya_perm(current, "huya:import")
sms_lines = parse_sms_lines(req.text)
if not sms_lines:
raise HTTPException(status_code=400, detail="没有识别到有效手机号,格式为:手机号----短信查询URL")
runner = huya_register_registry.create(
sms_lines=sms_lines,
tag=req.tag.strip(),
created_by=current.id,
concurrency=req.concurrency,
wait_seconds=req.wait_seconds,
poll_interval=req.poll_interval,
)
thread = threading.Thread(target=runner.run, daemon=True)
thread.start()
return runner.snapshot()
@router.get("/register/batches/{batch_id}", response_model=HuyaAutoRegisterBatchOut)
def get_auto_register_batch(
batch_id: str,
current: User = Depends(get_current_user),
):
"""查询虎牙手机号自动注册批次状态。"""
_require_huya_perm(current, "huya:import")
runner = huya_register_registry.get(batch_id)
if not runner:
raise HTTPException(status_code=404, detail="批次不存在或服务已重启")
return runner.snapshot()
@router.post("/register/batches/{batch_id}/stop")
def stop_auto_register_batch(
batch_id: str,
current: User = Depends(get_current_user),
):
"""停止虎牙手机号自动注册批次。"""
_require_huya_perm(current, "huya:import")
runner = huya_register_registry.get(batch_id)
if not runner:
raise HTTPException(status_code=404, detail="批次不存在或服务已重启")
runner.stop()
return {"message": "已发送停止信号", "success": True}
@router.post("/accounts/password-login/selected")
def password_login_selected_accounts(
req: HuyaPasswordLoginSelectedRequest,