feat(douyu): unify account probes and lifecycle writes
Centralize Douyu client creation, CK session probing, identity refresh, role alias resolution, capability persistence, cache and batch throttling across collaboration, fulfillment, tasks and cookie management. Add the account-name copy action in the collaboration table.
This commit is contained in:
@@ -7,6 +7,8 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import os
|
||||
import time
|
||||
|
||||
from fastapi import (
|
||||
APIRouter,
|
||||
@@ -57,6 +59,14 @@ from ..services.douyu_collab_events import collab_events
|
||||
router = APIRouter(prefix="/api/douyu", tags=["斗鱼外部单协作"])
|
||||
|
||||
|
||||
def _verify_batch_interval() -> float:
|
||||
try:
|
||||
value = float(os.getenv("DOUYU_COLLAB_VERIFY_BATCH_INTERVAL_SECONDS", "0.2"))
|
||||
except ValueError:
|
||||
value = 0.2
|
||||
return max(0.0, min(value, 5.0))
|
||||
|
||||
|
||||
def _http_error(exc: collab.CollabError) -> ApiError:
|
||||
return ApiError(
|
||||
status_code=exc.status_code,
|
||||
@@ -356,7 +366,10 @@ def verify_external_orders_batch(
|
||||
current: User = Depends(require_permission("douyu:collab:edit")),
|
||||
):
|
||||
results: list[dict] = []
|
||||
for order_id in ids:
|
||||
interval = _verify_batch_interval()
|
||||
for index, order_id in enumerate(ids):
|
||||
if index and interval:
|
||||
time.sleep(interval)
|
||||
try:
|
||||
order = collab.get_order(db, order_id)
|
||||
result = collab.verify_order(db, current, order)
|
||||
|
||||
Reference in New Issue
Block a user