Skip to content

Commit 7d2de34

Browse files
author
lan-air
committed
资源本地化,管理面板,口令转二维码
1 parent c3b141f commit 7d2de34

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

main.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,17 @@
1919
os.makedirs('./static')
2020
app.mount("/static", StaticFiles(directory="static"), name="static")
2121
index_html = open('templates/index.html', 'r').read()
22+
admin_html = open('templates/admin.html', 'r').read()
2223
# 过期时间
2324
exp_hour = 24
2425
# 允许错误次数
2526
error_count = 5
2627
# 禁止分钟数
2728
error_minute = 60
28-
29+
# 后台地址
30+
admin_address = 'admin'
31+
# 管理密码
32+
admin_password = 'admin'
2933
error_ip_count = {}
3034

3135

@@ -56,6 +60,33 @@ def get_file_name(key, ext, file):
5660
return key, len(file), path[1:] + name
5761

5862

63+
@app.get(f'/{admin_address}')
64+
async def admin(request: Request):
65+
return HTMLResponse(admin_html)
66+
67+
68+
@app.post(f'/{admin_address}')
69+
async def admin_post(request: Request, db: Session = Depends(get_db)):
70+
if request.headers.get('pwd') == admin_password:
71+
codes = db.query(database.Codes).all()
72+
return {'code': 200, 'msg': '查询成功', 'data': codes}
73+
else:
74+
return {'code': 400, 'msg': '密码错误'}
75+
76+
77+
@app.delete(f'/{admin_address}')
78+
async def admin_delete(request: Request, code: str, db: Session = Depends(get_db)):
79+
if request.headers.get('pwd') == admin_password:
80+
file = db.query(database.Codes).filter(database.Codes.code == code)
81+
if file.first().type != 'text/plain':
82+
os.remove('.' + file.first().text)
83+
file.delete()
84+
db.commit()
85+
return {'code': 200, 'msg': '删除成功'}
86+
else:
87+
return {'code': 400, 'msg': '密码错误'}
88+
89+
5990
@app.get('/')
6091
async def index():
6192
return HTMLResponse(index_html)

readme.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,37 @@
1616
- [x] 无需注册:无需注册,无需登录
1717
- [x] Sqlite3数据库:无需安装数据库
1818
- [x] 可以加get参数code,这样打开就会读取取件码如:http://xxx.com?code=12345
19-
- [ ] 管理面板:简单列表页删除违规文件
19+
- [x] 管理面板:简单列表页删除违规文件
2020
- [ ] 口令使用次数,口令有效期,二维码分享
2121

22+
## 更新记录
23+
24+
### 2022年12月10日 01:56:43
25+
26+
1. 管理面板已新增,一如既往的极简,只有删除
27+
2. 二维码图片(调用的网络接口,如果离线环境将无法使用,一切为了极简)
28+
2229
## 系统截图
30+
2331
### 取件
32+
2433
![取件](https://raw.githubusercontent.com/vastsa/FileCodeBox/master/images/img.png)
2534
![取件](https://raw.githubusercontent.com/vastsa/FileCodeBox/master/images/img_1.png)
35+
2636
### 寄件
37+
2738
![取件](https://raw.githubusercontent.com/vastsa/FileCodeBox/master/images/img_2.png)
2839
![取件](https://raw.githubusercontent.com/vastsa/FileCodeBox/master/images/img_3.png)
40+
2941
### 管理面板
42+
3043
![取件](https://raw.githubusercontent.com/vastsa/FileCodeBox/master/images/img_4.png)
3144
![取件](https://raw.githubusercontent.com/vastsa/FileCodeBox/master/images/img_5.png)
3245

3346
## 部署方式
3447

48+
先拉取代码,然后修改main.py文件,将里面写了注释的可以根据需求改一下
49+
3550
### 服务端部署
3651

3752
1. 安装Python3

0 commit comments

Comments
 (0)