From 9a95d3884f5141d349ddde98d3f64e419c55a6d3 Mon Sep 17 00:00:00 2001 From: H Vs Date: Fri, 28 Mar 2025 10:24:32 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/endpoints/config_endpoint.py | 33 +++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/app/endpoints/config_endpoint.py b/app/endpoints/config_endpoint.py index 7526d99..617ba79 100644 --- a/app/endpoints/config_endpoint.py +++ b/app/endpoints/config_endpoint.py @@ -22,13 +22,22 @@ class SaveConfigRequest(BaseModel): @config_router.post("/getconfig",response_model=None) -@validate_wxid +#@validate_wxid async def get_config(request: Request, body: GetConfigRequest): wxid = body.wxid + if not wxid: + return {"code": 400, "message": "wxid 不能为空"} + + k,loginfo=await request.app.state.gewe_service.get_login_info_by_wxid_async(wxid) + + if not k: + return {"code":404,"message":f"{wxid} 没有对应的登录信息"} + + login_status=loginfo.get('status','0') - # k,loginfo=await request.app.state.gewe_service.get_login_info_by_wxid_async(wxid) - # if not k: - # return {"code":404,"message":f"{wxid} 没有对应的登录信息"} + if login_status != '1': + return {"code": 401, "message": f"{wxid} 已经离线"} + config=await request.app.state.gewe_service.get_wxchat_config_from_cache_async(wxid) return config @@ -36,13 +45,27 @@ async def get_config(request: Request, body: GetConfigRequest): @config_router.post("/saveconfig",response_model=None) -@validate_wxid +#@validate_wxid async def save_config(request: Request, body: SaveConfigRequest): wxid = body.wxid data = body.data # k,loginfo=await request.app.state.gewe_service.get_login_info_by_wxid_async(wxid) # if not k: # return {"code":404,"message":f"{wxid} 没有对应的登录信息"} + + if not wxid: + return {"code": 400, "message": "wxid 不能为空"} + + k,loginfo=await request.app.state.gewe_service.get_login_info_by_wxid_async(wxid) + + if not k: + return {"code":404,"message":f"{wxid} 没有对应的登录信息"} + + login_status=loginfo.get('status','0') + + if login_status != '1': + return {"code": 401, "message": f"{wxid} 已经离线"} + try: # 使用 Pydantic 严格校验数据类型和结构 validated_config = AgentConfig.model_validate(data)