haha
This commit is contained in:
7
API文档.md
7
API文档.md
@@ -358,7 +358,7 @@ Set-Cookie: auth_token=a1b2c3d4e5f6...; HttpOnly; Max-Age=31536000; SameSite=Lax
|
||||
| 状态码 | 说明 |
|
||||
|--------|------|
|
||||
| 201 | 成功,任务已创建并派发 |
|
||||
| 400 | 未指定 id、worker_id 或 account_name |
|
||||
| 400 | 未指定 id、boss_id、worker_id 或 account_name |
|
||||
| 401 | 未登录或 token 失效 |
|
||||
| 404 | 未找到拥有该浏览器环境的在线 Worker |
|
||||
| 503 | Worker 不在线 / WebSocket 连接不存在 / 派发失败 |
|
||||
@@ -369,11 +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/环境) |
|
||||
| worker_id | string | 否 | 目标 Worker ID |
|
||||
| account_name | string | 否 | 浏览器环境名称(系统自动查找对应 Worker) |
|
||||
| params | object | 否 | 任务附加参数,默认 `{}` |
|
||||
|
||||
**路由规则**: `id` 优先,根据账号 ID 自动解析电脑和环境;否则 `worker_id` 或 `account_name`。
|
||||
**路由规则**: `id` 优先;其次 `boss_id`(查库得账号);否则 `worker_id` 或 `account_name`。
|
||||
|
||||
**请求示例 — 检查登录(推荐用 id)**:
|
||||
```json
|
||||
@@ -416,7 +417,7 @@ Set-Cookie: auth_token=a1b2c3d4e5f6...; HttpOnly; Max-Age=31536000; SameSite=Lax
|
||||
|
||||
| 状态码 | 说明 |
|
||||
|--------|------|
|
||||
| 400 | 未指定 id、worker_id 或 account_name |
|
||||
| 400 | 未指定 id、boss_id、worker_id 或 account_name |
|
||||
| 401 | 未登录或 token 失效 |
|
||||
| 404 | 未找到拥有该浏览器环境的在线 Worker |
|
||||
| 503 | Worker 不在线 / WebSocket 连接不存在 / 派发失败 |
|
||||
|
||||
@@ -69,6 +69,7 @@ def task_list(request):
|
||||
|
||||
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 可能把数字传成字符串
|
||||
if account_id is not None:
|
||||
try:
|
||||
@@ -92,6 +93,18 @@ 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)
|
||||
@@ -103,7 +116,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, "请指定 id、worker_id 或 account_name")
|
||||
return api_error(http_status.HTTP_400_BAD_REQUEST, "请指定 id、boss_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} 不在线")
|
||||
|
||||
@@ -39,6 +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,按此查账号
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user