This commit is contained in:
ddrwode
2026-02-27 15:22:28 +08:00
parent 338eae98b3
commit 435bd2d81a
4 changed files with 16 additions and 15 deletions

View File

@@ -65,18 +65,19 @@ def task_list(request):
ser.is_valid(raise_exception=True)
validated = ser.validated_data.copy()
boss_id_raw = validated.pop("boss_id", "") or ""
account_id = validated.pop("id", None)
req = TaskCreate(**validated)
target_worker_id = req.worker_id or ""
account_name = req.account_name or ""
# 指定 worker_id/account_name 时,用 boss_id 自动解析
if not target_worker_id and not account_name and boss_id_raw:
account = BossAccount.objects.filter(boss_id=boss_id_raw.strip()).first()
if not account:
# 指定 id 时,直接从数据库解析 worker_idaccount_name
if account_id:
try:
account = BossAccount.objects.get(pk=account_id)
except BossAccount.DoesNotExist:
return api_error(
http_status.HTTP_404_NOT_FOUND,
f"未找到 boss_id 为 '{boss_id_raw}' 的账号",
f"未找到 id={account_id} 的账号",
)
target_worker_id = account.worker_id
account_name = account.browser_name
@@ -93,7 +94,7 @@ def task_list(request):
req.worker_id = target_worker_id
if not target_worker_id:
return api_error(http_status.HTTP_400_BAD_REQUEST, "请指定 worker_idaccount_name 或 boss_id")
return api_error(http_status.HTTP_400_BAD_REQUEST, "请指定 id、worker_idaccount_name")
if not worker_manager.is_online(target_worker_id):
return api_error(http_status.HTTP_503_SERVICE_UNAVAILABLE, f"Worker {target_worker_id} 不在线")