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

This commit is contained in:
lan-air
2022-12-10 02:02:50 +08:00
parent c1d2575ffb
commit 19a85fc1f7
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') os.makedirs('./static')
app.mount("/static", StaticFiles(directory="static"), name="static") app.mount("/static", StaticFiles(directory="static"), name="static")
index_html = open('templates/index.html', 'r').read() index_html = open('templates/index.html', 'r').read()
admin_html = open('templates/admin.html', 'r').read()
# 过期时间 # 过期时间
exp_hour = 24 exp_hour = 24
# 允许错误次数 # 允许错误次数
error_count = 5 error_count = 5
# 禁止分钟数 # 禁止分钟数
error_minute = 60 error_minute = 60
# 后台地址
admin_address = 'admin'
# 管理密码
admin_password = 'admin'
error_ip_count = {} error_ip_count = {}
@@ -56,6 +60,33 @@ def get_file_name(key, ext, file):
return key, len(file), path[1:] + name 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('/') @app.get('/')
async def index(): async def index():
return HTMLResponse(index_html) return HTMLResponse(index_html)
+16 -1
View File
@@ -16,22 +16,37 @@
- [x] 无需注册:无需注册,无需登录 - [x] 无需注册:无需注册,无需登录
- [x] Sqlite3数据库:无需安装数据库 - [x] Sqlite3数据库:无需安装数据库
- [x] 可以加get参数code,这样打开就会读取取件码如:http://xxx.com?code=12345 - [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.png)
![取件](https://raw.githubusercontent.com/vastsa/FileCodeBox/master/images/img_1.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_2.png)
![取件](https://raw.githubusercontent.com/vastsa/FileCodeBox/master/images/img_3.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_4.png)
![取件](https://raw.githubusercontent.com/vastsa/FileCodeBox/master/images/img_5.png) ![取件](https://raw.githubusercontent.com/vastsa/FileCodeBox/master/images/img_5.png)
## 部署方式 ## 部署方式
先拉取代码,然后修改main.py文件,将里面写了注释的可以根据需求改一下
### 服务端部署 ### 服务端部署
1. 安装Python3 1. 安装Python3