This commit is contained in:
2026-08-31 16:57:09 +08:00
parent 692b166d9f
commit 493287c99f
3 changed files with 41 additions and 2 deletions
+14 -1
View File
@@ -248,11 +248,24 @@ class ServerAPI:
# ------------------------------------------------------------------
# 投递记录
# ------------------------------------------------------------------
# 上报字段长度上限(与服务端列长对齐;jd_text 上限同服务端 JD_TEXT_LIMIT,
# 防止超大包触发 MySQL max_allowed_packet=1153 导致记录反复上报失败)
_REPORT_TEXT_LIMITS = {
"job_title": 128, "company": 128, "salary": 32, "location": 64,
"ai_reason": 255, "skip_reason": 255, "greeting": 500,
"jd_text": 20000,
}
def report_application(self, session_id: int | None, data: dict) -> dict:
params = {"session_id": session_id} if session_id else {}
payload = dict(data)
for key, limit in self._REPORT_TEXT_LIMITS.items():
val = payload.get(key)
if isinstance(val, str) and len(val) > limit:
payload[key] = val[:limit]
resp = self._req("post",
f"{self.base_url}/api/jobs/report",
json=data, params=params, headers=self._headers(), timeout=15,
json=payload, params=params, headers=self._headers(), timeout=15,
)
resp.raise_for_status()
return resp.json()
+3 -1
View File
@@ -11,11 +11,13 @@ services:
MYSQL_ROOT_PASSWORD: ${DB_PASSWORD:-root123456}
MYSQL_DATABASE: ${DB_NAME:-jianli_boss}
TZ: Asia/Shanghai
# 统一 utf8mb4,避免中文乱码
# 统一 utf8mb4,避免中文乱码;显式放大 max_allowed_packet(JD 全文归档入库,
# 防止大包触发 1153 'Got a packet bigger than max_allowed_packet')
command:
- --character-set-server=utf8mb4
- --collation-server=utf8mb4_unicode_ci
- --default-authentication-plugin=mysql_native_password
- --max-allowed-packet=64M
ports:
- "3306:3306"
volumes:
+24
View File
@@ -15,6 +15,29 @@ from ..schemas import ApplicationIn, ApplicationOut, Message, StatsOut
router = APIRouter(prefix="/api/jobs", tags=["投递记录"])
# jd_text 归档上限(字符):控制写入包体积,避免触发 MySQL max_allowed_packet(1153);
# 正常 JD 全文远低于此值,超限基本意味着抓取异常(如抓到整页文本)
JD_TEXT_LIMIT = 20000
def _clip(value: Optional[str], limit: int) -> Optional[str]:
"""按列长度截断文本,防止超长写入导致 1153 / Data too long"""
return value[:limit] if value else value
def _sanitize(req: ApplicationIn) -> ApplicationIn:
"""上报字段统一裁剪(与 models.py 列长度保持一致)"""
req.job_title = _clip(req.job_title, 128)
req.company = _clip(req.company, 128)
req.salary = _clip(req.salary, 32)
req.location = _clip(req.location, 64)
req.apply_type = _clip(req.apply_type, 20) or "skipped"
req.ai_reason = _clip(req.ai_reason, 255)
req.skip_reason = _clip(req.skip_reason, 255)
req.greeting = _clip(req.greeting, 500)
req.jd_text = _clip(req.jd_text, JD_TEXT_LIMIT)
return req
@router.post("/report", response_model=ApplicationOut)
def report_application(
@@ -27,6 +50,7 @@ def report_application(
客户端上报一条投递/跳过记录(前置校验:RPA 必须在线)。
同一用户 + 同一职位 ID 去重,已存在则更新。
"""
req = _sanitize(req)
existing = db.query(JobApplication).filter(
JobApplication.user_id == current_user.id,
JobApplication.job_id == req.job_id,