调整了部分结构,使用api方式调用修改js文件了
This commit is contained in:
parent
ddac0c900e
commit
b51fdcca32
37
src/change_url/app.py
Normal file
37
src/change_url/app.py
Normal file
@ -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)
|
@ -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}")
|
@ -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 = "处理您的请求时发生错误。"
|
||||
|
62
src/change_url/templates/index.html
Normal file
62
src/change_url/templates/index.html
Normal file
@ -0,0 +1,62 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>链接修改小工具v0.0.1</title>
|
||||
<!-- 引入 Layui CSS -->
|
||||
<link href="//unpkg.com/layui@2.9.6/dist/css/layui.css" rel="stylesheet">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="layui-container" style="margin-top: 50px;">
|
||||
<div class="layui-row">
|
||||
<div class="layui-col-md6 layui-col-md-offset3">
|
||||
<form class="layui-form">
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">msg</label>
|
||||
<div class="layui-input-block">
|
||||
<textarea name="text" placeholder="请复制粘贴飞机原始信息,如果报错请修改飞机信息格式!" autocomplete="off" class="layui-textarea" lay-verify="required" style="height: 300px"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<div class="layui-input-block">
|
||||
<button class="layui-btn" lay-submit="" lay-filter="doChange">提交</button>
|
||||
<button type="reset" class="layui-btn layui-btn-primary">重置</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 引入 layui.js -->
|
||||
<script src="//unpkg.com/layui@2.9.6/dist/layui.js"></script>
|
||||
<script>
|
||||
layui.use(['form', 'layer','jquery'], function () {
|
||||
var $ = layui.$,
|
||||
form = layui.form,
|
||||
layer = layui.layer;
|
||||
|
||||
form.on('submit(doChange)', function (data) {
|
||||
$.ajax({
|
||||
url: '/changeurl',
|
||||
method: 'POST',
|
||||
contentType: 'application/json',
|
||||
data: JSON.stringify(data.field),
|
||||
success: function (res) {
|
||||
if(!res.res){
|
||||
layer.alert(res.msg+"未知url,修改失败")
|
||||
}else {
|
||||
layer.msg(res.msg+"修改成功", {icon: 1});
|
||||
}
|
||||
},
|
||||
error: function (err) {
|
||||
layer.msg('请求失败:' + err.responseJSON.detail[0].msg, {icon: 2});
|
||||
}
|
||||
});
|
||||
return false;
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user