截断JD
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user