From 19a85fc1f71a60fffe9a13f6b0f9eb4fd3a2ed5d Mon Sep 17 00:00:00 2001 From: lan-air Date: Sat, 10 Dec 2022 02:02:50 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B5=84=E6=BA=90=E6=9C=AC=E5=9C=B0=E5=8C=96?= =?UTF-8?q?=EF=BC=8C=E7=AE=A1=E7=90=86=E9=9D=A2=E6=9D=BF=EF=BC=8C=E5=8F=A3?= =?UTF-8?q?=E4=BB=A4=E8=BD=AC=E4=BA=8C=E7=BB=B4=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 33 ++++++++++++++++++++++++++++++++- readme.md | 17 ++++++++++++++++- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index b69f242..c3ceadf 100644 --- a/main.py +++ b/main.py @@ -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) diff --git a/readme.md b/readme.md index 1da82a9..768565b 100644 --- a/readme.md +++ b/readme.md @@ -16,22 +16,37 @@ - [x] 无需注册:无需注册,无需登录 - [x] Sqlite3数据库:无需安装数据库 - [x] 可以加get参数code,这样打开就会读取取件码如:http://xxx.com?code=12345 -- [ ] 管理面板:简单列表页删除违规文件 +- [x] 管理面板:简单列表页删除违规文件 - [ ] 口令使用次数,口令有效期,二维码分享 +## 更新记录 + +### 2022年12月10日 01:56:43 + +1. 管理面板已新增,一如既往的极简,只有删除 +2. 二维码图片(调用的网络接口,如果离线环境将无法使用,一切为了极简) + ## 系统截图 + ### 取件 + ![取件](https://raw.githubusercontent.com/vastsa/FileCodeBox/master/images/img.png) ![取件](https://raw.githubusercontent.com/vastsa/FileCodeBox/master/images/img_1.png) + ### 寄件 + ![取件](https://raw.githubusercontent.com/vastsa/FileCodeBox/master/images/img_2.png) ![取件](https://raw.githubusercontent.com/vastsa/FileCodeBox/master/images/img_3.png) + ### 管理面板 + ![取件](https://raw.githubusercontent.com/vastsa/FileCodeBox/master/images/img_4.png) ![取件](https://raw.githubusercontent.com/vastsa/FileCodeBox/master/images/img_5.png) ## 部署方式 +先拉取代码,然后修改main.py文件,将里面写了注释的可以根据需求改一下 + ### 服务端部署 1. 安装Python3