Skip to content

Commit 12d28ec

Browse files
committed
add:开关上传功能,关闭则仅允许管理员上传
1 parent 65ad220 commit 12d28ec

File tree

7 files changed

+94
-167
lines changed

7 files changed

+94
-167
lines changed

a.md

Lines changed: 0 additions & 158 deletions
This file was deleted.

history.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
## 更新记录
2+
3+
### 2022年12月13日
4+
5+
- [x] 完善手机版上传文本
6+
- [x] 优化Index.html首页
7+
- [x] 填补了由于上面修改带来的坑
8+
- [x] 更新了
9+
10+
### 2022年12月12日
11+
12+
- [x] 重写用户登录和 IP 检查并重定义状态码
13+
- [x] 新增存储引擎统一文件读写
14+
- [x] 设置PORT
15+
16+
### 2022年12月11日
17+
18+
1. 修复取件不显示码的问题
19+
2. 修复文件次数为1时,文件被删除的问题
20+
3. 使用 aiosqlite 驱动异步化数据库操作
21+
4. 增加定时清理过期文件
22+
5. 优化部署方式,Docker映射,后续更新直接覆盖代码重启
23+
6. 优化配置文件,增加配置项
24+
7. 发布V1.4.5稳定版
25+
26+
### 2022年12月10日
27+
28+
1. 管理面板已新增,一如既往的极简,只有删除
29+
2. 二维码图片(调用的网络接口,如果离线环境将无法使用,一切为了极简)
30+
3. 取件码有效期,取件码使用次数
31+
4. 优化代码逻辑
32+
5. 限制上传文件大小
33+
6. 完善配置参数

main.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import asyncio
44
from pathlib import Path
55

6-
from fastapi import FastAPI, Depends, UploadFile, Form, File, HTTPException, BackgroundTasks
6+
from fastapi import FastAPI, Depends, UploadFile, Form, File, HTTPException, BackgroundTasks, Header
77
from starlette.responses import HTMLResponse, FileResponse
88
from starlette.staticfiles import StaticFiles
99

@@ -122,9 +122,11 @@ async def index(code: str, ip: str = Depends(error_ip_limit), s: AsyncSession =
122122

123123

124124
@app.post('/share')
125-
async def share(background_tasks: BackgroundTasks, text: str = Form(default=None), style: str = Form(default='2'),
126-
value: int = Form(default=1), file: UploadFile = File(default=None), ip: str = Depends(upload_ip_limit),
127-
s: AsyncSession = Depends(get_session)):
125+
async def share(background_tasks: BackgroundTasks, pwd: str = Header(default=None), text: str = Form(default=None),
126+
style: str = Form(default='2'), value: int = Form(default=1), file: UploadFile = File(default=None),
127+
ip: str = Depends(upload_ip_limit), s: AsyncSession = Depends(get_session)):
128+
if not settings.ENABLE_UPLOAD and pwd != settings.ADMIN_PASSWORD:
129+
raise HTTPException(status_code=403, detail="上传功能已关闭")
128130
code = await get_code(s)
129131
if style == '2':
130132
if value > 7:

readme.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div style="text-align: center">
2-
<h1>文件快递柜</h1>
2+
<h1>文件快递柜-Lite</h1>
33
<p><em>匿名口令分享文本,文件,像拿快递一样取文件</em></p>
44
</div>
55

@@ -19,6 +19,18 @@
1919
- [x] 管理面板:查看所有文件,删除文件
2020
- [x] 一键部署:docker一键部署
2121

22+
## 未来规划
23+
24+
2022年12月14日
25+
26+
这个项目主要是以轻量为主,主要是单用户,离线环境,因此也不需要加太多东西,所以其实这个项目到这基本功能已经完成了,剩下的就是维护和完善现有功能。
27+
28+
也不会再加入新的大功能了,如果有新的功能的话,那就是我们的Pro版本了,当然也是继续开源的,能和@veoco一起开源挺荣幸的,在他的代码中我学到了许多,此前我基本上是使用Django那一套,对Fastapi仅限于使用,他的许多写法让我受益匪浅,也让我对Fastapi有了更深的了解,所以我也会在Pro版本中使用Fastapi。
29+
30+
根据目前一些使用反馈来说,希望加入多用户功能,还有多存储引擎等,欢迎各位继续提意见,加入我们共同开发。
31+
32+
如果你有更好的想法和建议欢迎提issue。
33+
2234
## 预览
2335

2436
### 寄件
@@ -111,3 +123,11 @@ KEYWORDS=FileCodeBox,文件快递柜,口令传送箱,匿名口令分享文
111123
# 存储引擎
112124
STORAGE_ENGINE=filesystem
113125
```
126+
127+
## 状态
128+
129+
![Alt](https://repobeats.axiom.co/api/embed/7a6c92f1d96ee57e6fb67f0df371528397b0c9ac.svg "Repobeats analytics image")
130+
131+
## 免责声明
132+
133+
本项目开源仅供学习使用,不得用于任何违法用途,否则后果自负,与本人无关。使用请保留项目地址谢谢。

readme_en.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
---
77

8-
[English](./README_EN.md) | [简体中文](./README.md)
8+
[简体中文](./readme.md) | [English](./readme_en.md)
99

1010
## Main features
1111

@@ -19,6 +19,23 @@
1919
- [x] management Panel: View all files and delete them
2020
- [x] one-click deployment: docker one-click deployment
2121

22+
## Future Plan
23+
24+
December 14, 2022
25+
This project is mainly light-weight, mainly single-user, offline environment, so there is no need to add too many
26+
things, so in fact, the basic functions of this project have been completed, and the rest is to maintain and improve the
27+
existing functions.
28+
29+
No new major functions will be added. If there are new functions, it will be our Pro version. Of course, it will
30+
continue to be open source. It is an honor to be open source with @veoco. I learned from his code Many, I basically used
31+
the Django set before, and only used Fastapi. Many of his writing methods have benefited me a lot, and I have a deeper
32+
understanding of Fastapi, so I will also use Fastapi in the Pro version .
33+
34+
According to some current feedback, I hope to add multi-user functions and multi-storage engines, etc. Welcome to
35+
continue to give comments and join us in joint development.
36+
37+
If you have better ideas and suggestions, welcome to file an issue.
38+
2239
## Preview
2340

2441
### Send
@@ -113,3 +130,12 @@ KEYWORDS=FileCodeBox,文件快递柜,口令传送箱,匿名口令分享文
113130
# 存储引擎
114131
STORAGE_ENGINE=filesystem
115132
```
133+
134+
## Status
135+
136+
![Alt](https://repobeats.axiom.co/api/embed/7a6c92f1d96ee57e6fb67f0df371528397b0c9ac.svg "Repobeats analytics image")
137+
138+
## Disclaimer
139+
140+
this project is open source for learning only and cannot be used for any illegal purposes. Otherwise, you will be
141+
responsible for the consequences and have nothing to do with yourself. Please keep the project address. Thank you.

settings.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
DATA_ROOT = './data/' + config('DATA_ROOT', cast=str, default=f"static")
1616
# 静态文件夹URL
1717
STATIC_URL = config('STATIC_URL', cast=str, default="/static")
18+
# 开启上传
19+
ENABLE_UPLOAD = config('ENABLE_UPLOAD', cast=bool, default=False)
1820
# 错误次数
1921
ERROR_COUNT = config('ERROR_COUNT', cast=int, default=5)
2022
# 错误限制分钟数

templates/index.html

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<meta name="description" content="{{description}}"/>
1212
<meta name="keywords" content="{{keywords}}"/>
1313
<meta name="generator" content="FileCodeBox"/>
14-
<meta name="template" content="Lan-V1.5.1"/>
14+
<meta name="template" content="Lan-V1.5.4"/>
1515
<style>
1616
.qu .el-button {
1717
width: 100px;
@@ -102,6 +102,7 @@
102102
multiple
103103
style="margin: 1rem 0;"
104104
:data="uploadData"
105+
:headers="{'pwd':pwd}"
105106
:on-success="successUpload"
106107
:on-error="errorUpload"
107108
>
@@ -194,6 +195,7 @@
194195
files: [],
195196
pageNum: 0,
196197
inputDisable: false,
198+
pwd: localStorage.getItem('pwd') || '',
197199
uploadData: {
198200
style: '2',
199201
type: '1',
@@ -295,7 +297,8 @@
295297
} else {
296298
this.http('post', '/share', this.uploadData, {
297299
headers: {
298-
'Content-Type': 'multipart/form-data'
300+
'Content-Type': 'multipart/form-data',
301+
'pwd': this.pwd
299302
}
300303
}).then(res => {
301304
this.files.unshift(res.data);
@@ -306,7 +309,6 @@
306309
}
307310
},
308311
successUpload(response, file, fileList) {
309-
console.log(response)
310312
this.$message({
311313
message: response.detail,
312314
type: 'success'

0 commit comments

Comments
 (0)