新增boss激活功能
This commit is contained in:
@@ -21,6 +21,7 @@ from ..fingerprint import get_machine_summary
|
||||
from ..browser.manager import BrowserManager
|
||||
from ..browser.resume_scraper import ResumeScraper
|
||||
from ..browser.applicant import Applicant
|
||||
from ..browser.activator import Activator
|
||||
|
||||
WEB_DIR = Path(__file__).parent
|
||||
|
||||
@@ -38,6 +39,7 @@ class AppState:
|
||||
self.browser = BrowserManager()
|
||||
self.ai = AIClient()
|
||||
self.applicant: Applicant | None = None
|
||||
self.activator: Activator | None = None
|
||||
self.connected = False # 是否已注册/登录云端
|
||||
self.login_polling = False
|
||||
self._control_started = False
|
||||
@@ -48,6 +50,11 @@ class AppState:
|
||||
self.applicant = Applicant(self.browser, self.server_api, self.ai)
|
||||
return self.applicant
|
||||
|
||||
def ensure_activator(self) -> Activator:
|
||||
if self.activator is None:
|
||||
self.activator = Activator(self.browser)
|
||||
return self.activator
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# 控制线程:登录成功后启动,5s 一轮 = 心跳带全量状态 + outbox 补发 + 远程任务轮询
|
||||
# ------------------------------------------------------------------
|
||||
@@ -148,6 +155,8 @@ state = AppState()
|
||||
|
||||
def start_apply_shared(params: dict) -> dict:
|
||||
"""面板 / 远程任务共用的启动入口(返回 ok+msg,不抛业务异常)"""
|
||||
if state.activator and state.activator.is_running:
|
||||
return {"ok": False, "msg": "Boss 激活任务运行中,请先停止"}
|
||||
if not state.server_api.get_primary_resume():
|
||||
return {"ok": False, "msg": "请先设置主简历"}
|
||||
try:
|
||||
@@ -226,6 +235,14 @@ class ResumeUpdateReq(BaseModel):
|
||||
content: str | None = None
|
||||
|
||||
|
||||
class StartActivateReq(BaseModel):
|
||||
match_text: str # 匹配条件文本(最后一条消息与之比对)
|
||||
threshold: int = 80 # 相似度阈值(0-100)
|
||||
reply_message: str # 命中后发送的自定义消息
|
||||
max_count: int = 20 # 单次任务发送上限(0=不限)
|
||||
dry_run: bool = False # 试跑:只识别命中,不真正发送
|
||||
|
||||
|
||||
# =======================================================
|
||||
# 页面
|
||||
# =======================================================
|
||||
@@ -490,6 +507,52 @@ def stop_apply():
|
||||
return {"ok": True, "msg": "正在停止投递任务..."}
|
||||
|
||||
|
||||
# =======================================================
|
||||
# Boss 激活(单机功能,不依赖云端账号)
|
||||
# =======================================================
|
||||
@app.post("/api/start-activate")
|
||||
def start_activate(req: StartActivateReq):
|
||||
if not req.match_text.strip():
|
||||
raise HTTPException(status_code=400, detail="请填写匹配条件文本")
|
||||
if not req.reply_message.strip():
|
||||
raise HTTPException(status_code=400, detail="请填写激活消息内容")
|
||||
if state.applicant and state.applicant.is_running:
|
||||
raise HTTPException(status_code=400, detail="投递任务运行中,请先停止")
|
||||
activator = state.ensure_activator()
|
||||
if activator.is_running:
|
||||
raise HTTPException(status_code=400, detail="已有激活任务在运行")
|
||||
try:
|
||||
# 复用登录态 profile,浏览器被手动关闭时自动拉起
|
||||
state.browser.ensure_browser_started()
|
||||
except RuntimeError as e:
|
||||
raise HTTPException(status_code=400, detail=str(e))
|
||||
activator.start(
|
||||
match_text=req.match_text,
|
||||
threshold=req.threshold / 100.0,
|
||||
reply_message=req.reply_message,
|
||||
max_count=req.max_count,
|
||||
dry_run=req.dry_run,
|
||||
)
|
||||
return {"ok": True, "msg": "Boss 激活任务已启动"}
|
||||
|
||||
|
||||
@app.post("/api/stop-activate")
|
||||
def stop_activate():
|
||||
activator = state.ensure_activator()
|
||||
if not activator.is_running:
|
||||
return {"ok": False, "msg": "当前没有运行中的激活任务"}
|
||||
activator.stop()
|
||||
return {"ok": True, "msg": "正在停止激活任务..."}
|
||||
|
||||
|
||||
@app.get("/api/activate-status")
|
||||
def activate_status():
|
||||
activator = state.activator
|
||||
if activator is None:
|
||||
return {"running": False, "stats": None}
|
||||
return {"running": activator.is_running, "stats": activator.stats}
|
||||
|
||||
|
||||
# =======================================================
|
||||
# 投递条件模板(服务端持久化)
|
||||
# =======================================================
|
||||
|
||||
Reference in New Issue
Block a user