feat(huya): 统一实时商品目录并增加兑换代理开关
This commit is contained in:
@@ -45,6 +45,7 @@ from .workbench import (
|
||||
import_workbench_cookies,
|
||||
list_goods,
|
||||
list_huya_workbench_accounts,
|
||||
list_live_goods,
|
||||
list_recharge_goods,
|
||||
list_tasks,
|
||||
stop_batch,
|
||||
@@ -92,6 +93,7 @@ __all__ = [
|
||||
"list_goods",
|
||||
"list_huya_account_ids",
|
||||
"list_huya_workbench_accounts",
|
||||
"list_live_goods",
|
||||
"list_recharge_goods",
|
||||
"list_tags",
|
||||
"list_tasks",
|
||||
|
||||
@@ -461,6 +461,9 @@ def _config_out(config: HuyaConfig) -> HuyaConfigOut:
|
||||
points_scene=huya_config_value("points_scene", config.points_scene),
|
||||
points_page_id=huya_config_value("points_page_id", config.points_page_id),
|
||||
points_tab_ids=huya_config_value("points_tab_ids", config.points_tab_ids),
|
||||
exchange_use_proxy=huya_config_value(
|
||||
"exchange_use_proxy", config.exchange_use_proxy
|
||||
),
|
||||
updated_at=config.updated_at,
|
||||
)
|
||||
|
||||
|
||||
@@ -73,6 +73,7 @@ from ...schemas import (
|
||||
)
|
||||
from ...services import huya_collab_service as collab
|
||||
from ...services.huya_collab_events import collab_events
|
||||
from ...services.huya_points_center import resolve_points_center_config
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@@ -452,7 +453,7 @@ def preview_external_order_ck(
|
||||
req.ck_text,
|
||||
with_gifts=req.with_gifts,
|
||||
sid=collab.resolve_gifts_sid(db),
|
||||
points_config=collab.resolve_points_center_config(db),
|
||||
points_config=resolve_points_center_config(db),
|
||||
)
|
||||
except collab.CollabError as exc:
|
||||
raise _http_error(exc) from exc
|
||||
|
||||
@@ -1,8 +1,16 @@
|
||||
"""虎牙工作台:配置、商品快照、任务批次与日志。"""
|
||||
|
||||
from fastapi import APIRouter
|
||||
from fastapi import APIRouter, Response
|
||||
|
||||
from core.huya.cookie_utils import cookie_value
|
||||
from core.huya.http_client import HuyaHttpClient
|
||||
|
||||
from ...schemas import HuyaWorkbenchTransferToCollab
|
||||
from ...services.huya_points_center import (
|
||||
fetch_points_center_catalog,
|
||||
resolve_points_center_config,
|
||||
)
|
||||
from ...services.huya_service import ensure_huya_config
|
||||
from ._common import *
|
||||
|
||||
router = APIRouter()
|
||||
@@ -169,6 +177,7 @@ def list_goods(
|
||||
rows = (
|
||||
db.query(HuyaGoodsSnapshot)
|
||||
.filter(HuyaGoodsSnapshot.account_id.is_not(None))
|
||||
.filter(HuyaGoodsSnapshot.product_id.like("hy-%"))
|
||||
.order_by(
|
||||
HuyaGoodsSnapshot.updated_at.desc(),
|
||||
HuyaGoodsSnapshot.id.desc(),
|
||||
@@ -186,6 +195,65 @@ def list_goods(
|
||||
return list(latest.values())
|
||||
|
||||
|
||||
@router.get("/goods/live", response_model=list[HuyaGoodsOut])
|
||||
def list_live_goods(
|
||||
account_id: int = Query(..., ge=1),
|
||||
response: Response = None,
|
||||
db: Session = Depends(get_db),
|
||||
current: User = Depends(require_permission("huya:task")),
|
||||
):
|
||||
"""按账号 CK 实时读取积分中心商品,不使用数据库快照。"""
|
||||
if response is not None:
|
||||
response.headers["Cache-Control"] = "no-store, max-age=0"
|
||||
_require_huya_task_account_access(db, current, [account_id])
|
||||
account = db.query(HuyaAccount).filter(HuyaAccount.id == account_id).first()
|
||||
if account is None:
|
||||
raise HTTPException(status_code=404, detail="虎牙账号不存在")
|
||||
cookie = normalize_huya_cookie(account.cookie or "")
|
||||
if not cookie:
|
||||
raise HTTPException(
|
||||
status_code=400, detail="账号 Cookie 为空,无法读取实时商品"
|
||||
)
|
||||
uid = (
|
||||
int(account.uid or account.yyuid or 0)
|
||||
or int(cookie_value(cookie, "yyuid") or 0)
|
||||
or int(cookie_value(cookie, "udb_uid") or 0)
|
||||
)
|
||||
if not uid:
|
||||
raise HTTPException(status_code=400, detail="无法解析账号 UID")
|
||||
|
||||
query_options = resolve_points_center_config(db)
|
||||
catalog = fetch_points_center_catalog(
|
||||
uid,
|
||||
cookie,
|
||||
client=HuyaHttpClient(
|
||||
logger=lambda value: logger.debug(f"[huya-live-goods] {value}")
|
||||
),
|
||||
**query_options,
|
||||
)
|
||||
if not catalog.goods:
|
||||
raise HTTPException(
|
||||
status_code=502,
|
||||
detail=f"实时商品加载失败:{catalog.message}",
|
||||
)
|
||||
now = datetime.now(UTC)
|
||||
sid = catalog.sid or 0
|
||||
return [
|
||||
HuyaGoodsOut(
|
||||
id=-(index + 1),
|
||||
account_id=account.id,
|
||||
sid=sid,
|
||||
product_id=str(item["product_id"]),
|
||||
name=str(item.get("name") or ""),
|
||||
price=item.get("price"),
|
||||
remain_text=str(item.get("remain_text") or ""),
|
||||
raw=item,
|
||||
updated_at=now,
|
||||
)
|
||||
for index, item in enumerate(catalog.goods)
|
||||
]
|
||||
|
||||
|
||||
@router.get("/recharge-goods", response_model=list[HuyaRechargeGoodsOut])
|
||||
def list_recharge_goods(
|
||||
db: Session = Depends(get_db),
|
||||
|
||||
Reference in New Issue
Block a user