资源本地化,管理面板,口令转二维码

This commit is contained in:
lan-air
2022-12-10 02:02:50 +08:00
parent c3b141f650
commit 7d2de3466b
2 changed files with 48 additions and 2 deletions
+32 -1
View File
@@ -19,13 +19,17 @@ if not os.path.exists('./static'):
os.makedirs('./static')
app.mount("/static", StaticFiles(directory="static"), name="static")
index_html = open('templates/index.html', 'r').read()
admin_html = open('templates/admin.html', 'r').read()
# 过期时间
exp_hour = 24
# 允许错误次数
error_count = 5
# 禁止分钟数
error_minute = 60
# 后台地址
admin_address = 'admin'
# 管理密码
admin_password = 'admin'
error_ip_count = {}
@@ -56,6 +60,33 @@ def get_file_name(key, ext, file):
return key, len(file), path[1:] + name
@app.get(f'/{admin_address}')
async def admin(request: Request):
return HTMLResponse(admin_html)
@app.post(f'/{admin_address}')
async def admin_post(request: Request, db: Session = Depends(get_db)):
if request.headers.get('pwd') == admin_password:
codes = db.query(database.Codes).all()
return {'code': 200, 'msg': '查询成功', 'data': codes}
else:
return {'code': 400, 'msg': '密码错误'}
@app.delete(f'/{admin_address}')
async def admin_delete(request: Request, code: str, db: Session = Depends(get_db)):
if request.headers.get('pwd') == admin_password:
file = db.query(database.Codes).filter(database.Codes.code == code)
if file.first().type != 'text/plain':
os.remove('.' + file.first().text)
file.delete()
db.commit()
return {'code': 200, 'msg': '删除成功'}
else:
return {'code': 400, 'msg': '密码错误'}
@app.get('/')
async def index():
return HTMLResponse(index_html)