feat(huya): 统一积分兑换并完善兑换记录

This commit is contained in:
yml
2026-11-13 19:03:55 +08:00
parent b89ee4fd18
commit 711be0e2b6
17 changed files with 2064 additions and 193 deletions
+13 -2
View File
@@ -31,10 +31,21 @@ def create_browser_exchange_kit(
raise HTTPException(status_code=400, detail="该账号没有可用 Cookie,请先登录")
config = ensure_huya_config(db)
room_pid = huya_config_value("room_pid", config.room_pid)
points_page_code = huya_config_value("points_page_code", config.points_page_code)
points_source_id = huya_config_value("points_source_id", config.points_source_id)
target = req.target if req and req.target else DEFAULT_EXCHANGE_TARGET
targets = exchange_target_options(room_pid)
targets = exchange_target_options(
room_pid,
points_page_code=points_page_code,
points_source_id=points_source_id,
)
try:
target_url = exchange_target_url(target, room_pid)
target_url = exchange_target_url(
target,
room_pid,
points_page_code=points_page_code,
points_source_id=points_source_id,
)
except ValueError as exc:
raise HTTPException(status_code=400, detail=str(exc)) from exc
pairs = dict(cookie_pairs(normalize_huya_cookie(account.cookie)))
+16 -3
View File
@@ -165,11 +165,24 @@ def list_goods(
db: Session = Depends(get_db),
current: User = Depends(require_permission("huya:task")),
):
"""查看已缓存的虎牙商品快照。"""
rows = db.query(HuyaGoodsSnapshot).order_by(HuyaGoodsSnapshot.id.desc()).all()
"""查看最近一次从积分中心 ``queryAllocation`` 刷新的商品快照。"""
rows = (
db.query(HuyaGoodsSnapshot)
.filter(HuyaGoodsSnapshot.account_id.is_not(None))
.order_by(
HuyaGoodsSnapshot.updated_at.desc(),
HuyaGoodsSnapshot.id.desc(),
)
.all()
)
if not rows:
return []
newest = rows[0].updated_at
latest = {}
for row in rows:
latest.setdefault((row.sid, row.product_id), row)
if row.updated_at != newest:
continue
latest.setdefault(row.product_id, row)
return list(latest.values())