优化虎牙默认配置
This commit is contained in:
+18
-17
@@ -20,9 +20,12 @@ from ..schemas import (
|
||||
HuyaTaskOut,
|
||||
)
|
||||
from ..services.huya_service import (
|
||||
HUYA_CONFIG_FIELDS,
|
||||
SUPPORTED_TASK_TYPES,
|
||||
apply_huya_config_defaults,
|
||||
create_planned_tasks,
|
||||
ensure_huya_config,
|
||||
huya_config_value,
|
||||
import_huya_cookies,
|
||||
)
|
||||
from ..services.huya_runner import HuyaBatchRunner, huya_batch_registry
|
||||
@@ -79,6 +82,17 @@ def _task_out(task: HuyaTask) -> HuyaTaskOut:
|
||||
)
|
||||
|
||||
|
||||
def _config_out(config: HuyaConfig) -> HuyaConfigOut:
|
||||
return HuyaConfigOut(
|
||||
room_pid=huya_config_value("room_pid", config.room_pid),
|
||||
sid=huya_config_value("sid", config.sid),
|
||||
outer_act_id=huya_config_value("outer_act_id", config.outer_act_id),
|
||||
bind_act_id=huya_config_value("bind_act_id", config.bind_act_id),
|
||||
pay_channel=huya_config_value("pay_channel", config.pay_channel),
|
||||
updated_at=config.updated_at,
|
||||
)
|
||||
|
||||
|
||||
@router.get("/task-types")
|
||||
def task_types(current: User = Depends(require_permission("huya:task"))):
|
||||
"""返回当前规划的虎牙任务类型。"""
|
||||
@@ -154,14 +168,7 @@ def get_config(
|
||||
):
|
||||
"""获取虎牙配置。"""
|
||||
config = ensure_huya_config(db)
|
||||
return HuyaConfigOut(
|
||||
room_pid=config.room_pid or "",
|
||||
sid=config.sid or "",
|
||||
outer_act_id=config.outer_act_id or "9504",
|
||||
bind_act_id=config.bind_act_id or "17096",
|
||||
pay_channel=config.pay_channel or "Zfb",
|
||||
updated_at=config.updated_at,
|
||||
)
|
||||
return _config_out(config)
|
||||
|
||||
|
||||
@router.put("/config", response_model=HuyaConfigOut)
|
||||
@@ -172,21 +179,15 @@ def update_config(
|
||||
):
|
||||
"""更新虎牙配置。"""
|
||||
config = ensure_huya_config(db)
|
||||
for field in ("room_pid", "sid", "outer_act_id", "bind_act_id", "pay_channel"):
|
||||
for field in HUYA_CONFIG_FIELDS:
|
||||
value = getattr(req, field)
|
||||
if value is not None:
|
||||
setattr(config, field, value.strip())
|
||||
apply_huya_config_defaults(config)
|
||||
config.updated_at = datetime.now(timezone.utc)
|
||||
db.commit()
|
||||
db.refresh(config)
|
||||
return HuyaConfigOut(
|
||||
room_pid=config.room_pid or "",
|
||||
sid=config.sid or "",
|
||||
outer_act_id=config.outer_act_id or "9504",
|
||||
bind_act_id=config.bind_act_id or "17096",
|
||||
pay_channel=config.pay_channel or "Zfb",
|
||||
updated_at=config.updated_at,
|
||||
)
|
||||
return _config_out(config)
|
||||
|
||||
|
||||
@router.get("/goods", response_model=list[HuyaGoodsOut])
|
||||
|
||||
Reference in New Issue
Block a user