增加关键字替换接口

This commit is contained in:
zhl 2021-06-17 17:11:53 +08:00
parent 102c2db617
commit bae9f4070f
2 changed files with 24 additions and 2 deletions

View File

@ -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)

21
main.py
View File

@ -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)