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} 不在线")

View File

@@ -200,7 +200,6 @@ class TaskCreate(BaseModel):
task_type: TaskType
worker_id: Optional[str] = None
account_name: Optional[str] = None
boss_id: Optional[str] = None
params: Dict[str, Any] = {}

View File

@@ -37,9 +37,9 @@ class AccountBindSerializer(serializers.Serializer):
class TaskCreateSerializer(serializers.Serializer):
"""提交任务请求。"""
task_type = serializers.CharField(max_length=64)
id = serializers.IntegerField(required=False, allow_null=True, default=None) # 账号 ID直接指定
worker_id = serializers.CharField(max_length=64, required=False, allow_blank=True, default="")
account_name = serializers.CharField(max_length=128, required=False, allow_blank=True, default="")
boss_id = serializers.CharField(max_length=128, required=False, allow_blank=True, default="")
params = serializers.JSONField(required=False, default=dict)