diff --git a/lib/service/local.py b/lib/service/local.py index 00b01ea..4a5a302 100644 --- a/lib/service/local.py +++ b/lib/service/local.py @@ -8,3 +8,8 @@ def check_local(txt): if len(result) > 0: risk = 1 return {'errcode': 0, 'risk': risk, 'reason': result} + + +def replace_local(txt: str): + t = TextFilter() + return t.filter(txt) diff --git a/main.py b/main.py index 564e423..859ddd7 100644 --- a/main.py +++ b/main.py @@ -1,11 +1,11 @@ # encoding:utf-8 -from fastapi import FastAPI +from fastapi import FastAPI, BackgroundTasks from pydantic import BaseModel import uvicorn from lib.service.baidu import check_baidu -from lib.service.local import check_local +from lib.service.local import check_local, replace_local from lib.service.wechat import msg_sec_check app = FastAPI() @@ -15,6 +15,10 @@ class Item(BaseModel): content: str +def begin_audit_task(task_id: str): + print('begin audit task: %s' % (task_id)) + + @app.post("/check_wx") async def check_with_wx(item: Item): res_wechat = await msg_sec_check(item.content) @@ -33,6 +37,19 @@ async def check_with_local(item: Item): return res_local +@app.post("/replace_local") +async def replace_with_local(item: Item): + res_local = replace_local(item.content) + return res_local + + +# @app.post("/begin_task") +# async def begin_task(item: Item, background_tasks: BackgroundTasks): +# res_local = check_local(item.content) +# background_tasks.add_task(begin_audit_task, item.content) +# return res_local + + @app.post("/check_all") async def check_content(item: Item): res_wechat = await msg_sec_check(item.content)