diff --git a/src/bot/__init__.py b/src/bot/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/src/change_url/__init__.py b/src/change_url/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/src/change_url/app.py b/src/change_url/app.py new file mode 100644 index 0000000..519ae7a --- /dev/null +++ b/src/change_url/app.py @@ -0,0 +1,37 @@ +import uvicorn +from fastapi import FastAPI, Request, Form +from fastapi.responses import HTMLResponse +from fastapi.staticfiles import StaticFiles +from fastapi.templating import Jinja2Templates +from pydantic import BaseModel, constr + +from src.change_url.change_url import change_url + +app = FastAPI() + +app.mount("/static", StaticFiles(directory="static"), name="static") + +templates = Jinja2Templates(directory="templates") + + +@app.get("/", response_class=HTMLResponse) +async def index(request: Request): + return templates.TemplateResponse("index.html", {"request": request}) + + +class UrlModel(BaseModel): + text: constr(min_length=1) + + +@app.post('/changeurl') +async def changeurl(url_model: UrlModel): + text = url_model.text + res, js_type = change_url(text) + return { + 'res': res, + 'msg': js_type + } + + +if __name__ == "__main__": + uvicorn.run(app) diff --git a/src/change_url/change_url.py b/src/change_url/change_url.py index d89e49c..65822ed 100644 --- a/src/change_url/change_url.py +++ b/src/change_url/change_url.py @@ -151,7 +151,7 @@ def update_agent_url(url_list, url_type): def update_js_content(url_mapping, url_type): - js_file = 'link.js' + js_file = 'static/link.js' # 读取现有的 link.js 文件内容 try: @@ -234,14 +234,28 @@ def change_url(text): if __name__ == '__main__': try: text = ''' -web https://www.buusiw9.vip:7443 【新】 -H5 https://www.rnygj7.vip:9443 -全站APP https://www.csmbmex.vip:6004 -体育APP https://www.loo34.vip:6004 -代理web https://www.0rlnof1.com:8005 【新】 -代理H5 https://www.1c1s9fr.com:9443 【新】 +九游娱乐 +SEO 专用域名 + +WEB https://www.1zsaxz.com:9514 +H5 https://www.1l3dee.vip:9192  【新】 +全站 https://www.sjieu.vip:9013 +棋牌   https://www.2w33ay.vip:8001 +电子 https://www.3ku3z2.vip:9443 + +九游娱乐【SEO防拦截域名】 +WEB https://www.as421r.vip:9520 +H5 https://www.c0azge.vip:7988  【新】 ''' - change_url(text) + res = requests.post("http://127.0.0.1:8000/changeurl", json={'text': text}) + if res.status_code == 200: + if res.json()['res']: + msg = f'{res.json()["msg"]}修改成功' + else: + msg = f'{res.json()["msg"]}修改失败' + else: + msg = '请求发生错误,请检查服务是否正常' + print(msg) except Exception as e: print(f"An error occurred in the main program: {e}") \ No newline at end of file diff --git a/src/change_url/change_url_bot.py b/src/change_url/change_url_bot.py index e9166b4..ddb94aa 100644 --- a/src/change_url/change_url_bot.py +++ b/src/change_url/change_url_bot.py @@ -1,4 +1,5 @@ import telebot +import requests from loguru import logger from src.change_url.change_url import change_url @@ -33,11 +34,14 @@ def handle_forwarded_message(message): # user_info = message.forward_origin # response = f"这是一条转发的消息。{user_info}" try: - res, filename = change_url(message.text) - if res: - msg = f'{filename}修改成功' + res = requests.post("http://127.0.0.1:8080/changeurl", params={'text': message.text}) + if res.status_code == 200: + if res.json()['res']: + msg = f'{res.json()["msg"]}修改成功' + else: + msg = f'{res.json()["msg"]}修改失败' else: - msg = f'{filename}修改失败' + msg = '请求发生错误,请检查服务是否正常' except Exception as e: logger.error(f"An error occurred in change_url: {e}") msg = "处理您的请求时发生错误。" diff --git a/src/change_url/templates/index.html b/src/change_url/templates/index.html new file mode 100644 index 0000000..fb56d1e --- /dev/null +++ b/src/change_url/templates/index.html @@ -0,0 +1,62 @@ + + + + + 链接修改小工具v0.0.1 + + + + + +
+
+
+
+
+ +
+ +
+
+
+
+ + +
+
+
+
+
+
+ + + + + + \ No newline at end of file