From bd600ee153d9e14e6f3088cc1689970da99f82a4 Mon Sep 17 00:00:00 2001 From: satori Date: Mon, 4 Nov 2024 07:07:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=90=AF=E5=8A=A8=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 ++- main.py | 3 ++- routers/webhook.py | 20 ++++++++++++++++++++ start.sh | 8 ++++++-- 4 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 routers/webhook.py diff --git a/.gitignore b/.gitignore index 6d17870..20a06be 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ __pycache__ -.env \ No newline at end of file +.env +venv diff --git a/main.py b/main.py index 800885b..043fc2c 100755 --- a/main.py +++ b/main.py @@ -6,7 +6,7 @@ import uvicorn from fastapi import FastAPI from starlette.middleware.cors import CORSMiddleware from functools import lru_cache -from routers import reverse, user, task, img, user_collect +from routers import reverse, user, task, img, user_collect, webhook # 初始化 FastAPI @@ -20,6 +20,7 @@ app.include_router(task.router, prefix='/api/task', tags=['任务']) app.include_router(reverse.router, prefix='/api/default', tags=['搜图']) app.include_router(user_collect.router, prefix='/api/user_collect', tags=['收藏']) app.include_router(img.router, prefix='/imgs', tags=['图片']) +app.include_router(webhook.router, prefix='/api/webhook', tags=['webhook']) # 启动服务 diff --git a/routers/webhook.py b/routers/webhook.py new file mode 100644 index 0000000..11184f5 --- /dev/null +++ b/routers/webhook.py @@ -0,0 +1,20 @@ +import os +from fastapi import APIRouter + + +router = APIRouter() + + +# 获取标准原尺寸图 +@router.get("", summary="webhook", description="自动更新") +def webhook(): + print("webhook") + + # 执行 Bash 命令 + exit_code = os.system('git pull') + print('Exit code:', exit_code) + + exit_code = os.system('npm restart reverse-5002') + print('Exit code:', exit_code) + + return {"code": 200, "msg": "success"} diff --git a/start.sh b/start.sh index 054c05e..e21e03e 100755 --- a/start.sh +++ b/start.sh @@ -1,13 +1,17 @@ #!/bin/sh +# 创建虚拟环境 Python 3.10.12 +cd ~/reverse_image_search_gpu +python3.10 -m venv venv +source venv/bin/activate + # 安装依赖(使用清华镜像) pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple # 启动服务 -cd ~/reverse_image_search_gpu -pm2 start python3 --name reverse_image_search_gpu -- main.py 5002 +pm2 start python3 --name reverse-5002 -- main.py 5002 # pip freeze > requirements.txt