diff --git a/API文档.md b/API文档.md index 181d53b..8d9a4dc 100644 --- a/API文档.md +++ b/API文档.md @@ -369,12 +369,12 @@ Set-Cookie: auth_token=a1b2c3d4e5f6...; HttpOnly; Max-Age=31536000; SameSite=Lax |------|------|------|------| | task_type | string | 是 | 任务类型:`check_login`(检查登录)、`boss_recruit`(招聘) | | id | int | 否 | 账号 ID(直接指定,推荐) | -| boss_id | string | 否 | BOSS 直聘用户 ID(按此查账号,再解析 worker/环境) | +| boss_id | int | 否 | 即 /api/accounts 返回的 id(账号主键),与 id 等价 | | worker_id | string | 否 | 目标 Worker ID | | account_name | string | 否 | 浏览器环境名称(系统自动查找对应 Worker) | | params | object | 否 | 任务附加参数,默认 `{}` | -**路由规则**: `id` 优先;其次 `boss_id`(查库得账号);否则 `worker_id` 或 `account_name`。 +**路由规则**: `id`、`account_id`、`boss_id` 等价(均为账号主键);否则 `worker_id` 或 `account_name`。 **请求示例 — 检查登录(推荐用 id)**: ```json diff --git a/server/api/tasks.py b/server/api/tasks.py index 8e72f25..c6e406b 100644 --- a/server/api/tasks.py +++ b/server/api/tasks.py @@ -68,9 +68,12 @@ def task_list(request): raise ValidationError(ser.errors) validated = ser.validated_data.copy() - account_id = validated.pop("id", None) or validated.pop("account_id", None) - boss_id = (validated.pop("boss_id", "") or "").strip() - # form-data 可能把数字传成字符串 + # boss_id 即 /api/accounts 返回的 id(账号主键),与 id/account_id 等价,均按主键查表 + account_id = ( + validated.pop("id", None) + or validated.pop("account_id", None) + or validated.pop("boss_id", None) + ) if account_id is not None: try: account_id = int(account_id) @@ -80,7 +83,7 @@ def task_list(request): target_worker_id = req.worker_id or "" account_name = req.account_name or "" - # 指定 id 时,直接从数据库解析 worker_id 和 account_name + # 指定 id / account_id / boss_id(均为账号主键)时,按主键查表 if account_id: try: account = BossAccount.objects.get(pk=account_id) @@ -93,18 +96,6 @@ def task_list(request): account_name = account.browser_name req.worker_id = target_worker_id req.account_name = account_name - # 指定 boss_id 时,按 BOSS 直聘用户 ID 查账号 - elif boss_id: - account = BossAccount.objects.filter(boss_id=boss_id).first() - if not account: - return api_error( - http_status.HTTP_404_NOT_FOUND, - f"未找到 boss_id={boss_id} 的账号", - ) - target_worker_id = account.worker_id - account_name = account.browser_name - req.worker_id = target_worker_id - req.account_name = account_name if not target_worker_id and account_name: target_worker_id = worker_manager.find_worker_by_account(account_name) diff --git a/server/serializers.py b/server/serializers.py index c57b701..dec0c1f 100644 --- a/server/serializers.py +++ b/server/serializers.py @@ -39,7 +39,7 @@ class TaskCreateSerializer(serializers.Serializer): task_type = serializers.CharField(max_length=64) id = serializers.IntegerField(required=False, allow_null=True, default=None) # 账号 ID account_id = serializers.IntegerField(required=False, allow_null=True, default=None) # 同上,别名 - boss_id = serializers.CharField(max_length=64, required=False, allow_blank=True, default="") # BOSS 直聘用户 ID,按此查账号 + boss_id = serializers.CharField(max_length=64, required=False, allow_blank=True, default="") # 即 /api/accounts 返回的 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="") params = serializers.JSONField(required=False, default=dict)