haha
This commit is contained in:
@@ -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_id 和 account_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_id、account_name 或 boss_id")
|
||||
return api_error(http_status.HTTP_400_BAD_REQUEST, "请指定 id、worker_id 或 account_name")
|
||||
|
||||
if not worker_manager.is_online(target_worker_id):
|
||||
return api_error(http_status.HTTP_503_SERVICE_UNAVAILABLE, f"Worker {target_worker_id} 不在线")
|
||||
|
||||
@@ -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] = {}
|
||||
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user