From ea8eba883eac838c56b6cff9a6a02d22c536ffea Mon Sep 17 00:00:00 2001 From: xtaodada Date: Sun, 3 Nov 2024 14:30:36 +0800 Subject: [PATCH] feat: support app key --- src/env.py | 1 + src/route/predict.py | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/env.py b/src/env.py index b5ce842..1ecc23e 100644 --- a/src/env.py +++ b/src/env.py @@ -8,3 +8,4 @@ DEBUG = os.getenv("DEBUG", "True").lower() == "true" DOMAIN = os.getenv("DOMAIN", "") HOST = os.getenv("HOST", "0.0.0.0") PORT = int(os.getenv("PORT", 8888)) +APPKEY = os.getenv("APPKEY", "") diff --git a/src/route/predict.py b/src/route/predict.py index 812fff0..e34fcae 100644 --- a/src/route/predict.py +++ b/src/route/predict.py @@ -13,6 +13,7 @@ from src.core.click_model import ClickModel from src.core.resnet_model import ResnetModel from src.core.web_app import WebApp from src.crack import Crack, GeetestInitError +from src.env import APPKEY class ResultData(BaseModel): @@ -90,7 +91,9 @@ class PredictPlugin(AsyncInitializingComponent): traceback.print_exc() return Result(code=1, msg=msg, data=ResultData(gt=gt, challenge=challenge)) - async def bypass_gt_challenge(self, gt: str, challenge: str) -> Result: + async def bypass_gt_challenge(self, gt: str, challenge: str, appkey: str) -> Result: + if APPKEY and appkey != APPKEY: + return self.default_result # 使用新线程进行遍历,避免堵塞主线程 loop = asyncio.get_event_loop() # 可以使用with语句来确保线程执行完成后及时被清理