Skip to content

Commit

Permalink
add:开关上传功能,关闭则仅允许管理员上传
Browse files Browse the repository at this point in the history
  • Loading branch information
vastsa committed Dec 13, 2022
1 parent 65ad220 commit 12d28ec
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 167 deletions.
158 changes: 0 additions & 158 deletions a.md

This file was deleted.

33 changes: 33 additions & 0 deletions history.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
## 更新记录

### 2022年12月13日

- [x] 完善手机版上传文本
- [x] 优化Index.html首页
- [x] 填补了由于上面修改带来的坑
- [x] 更新了

### 2022年12月12日

- [x] 重写用户登录和 IP 检查并重定义状态码
- [x] 新增存储引擎统一文件读写
- [x] 设置PORT

### 2022年12月11日

1. 修复取件不显示码的问题
2. 修复文件次数为1时,文件被删除的问题
3. 使用 aiosqlite 驱动异步化数据库操作
4. 增加定时清理过期文件
5. 优化部署方式,Docker映射,后续更新直接覆盖代码重启
6. 优化配置文件,增加配置项
7. 发布V1.4.5稳定版

### 2022年12月10日

1. 管理面板已新增,一如既往的极简,只有删除
2. 二维码图片(调用的网络接口,如果离线环境将无法使用,一切为了极简)
3. 取件码有效期,取件码使用次数
4. 优化代码逻辑
5. 限制上传文件大小
6. 完善配置参数
10 changes: 6 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import asyncio
from pathlib import Path

from fastapi import FastAPI, Depends, UploadFile, Form, File, HTTPException, BackgroundTasks
from fastapi import FastAPI, Depends, UploadFile, Form, File, HTTPException, BackgroundTasks, Header
from starlette.responses import HTMLResponse, FileResponse
from starlette.staticfiles import StaticFiles

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


@app.post('/share')
async def share(background_tasks: BackgroundTasks, text: str = Form(default=None), style: str = Form(default='2'),
value: int = Form(default=1), file: UploadFile = File(default=None), ip: str = Depends(upload_ip_limit),
s: AsyncSession = Depends(get_session)):
async def share(background_tasks: BackgroundTasks, pwd: str = Header(default=None), text: str = Form(default=None),
style: str = Form(default='2'), value: int = Form(default=1), file: UploadFile = File(default=None),
ip: str = Depends(upload_ip_limit), s: AsyncSession = Depends(get_session)):
if not settings.ENABLE_UPLOAD and pwd != settings.ADMIN_PASSWORD:
raise HTTPException(status_code=403, detail="上传功能已关闭")
code = await get_code(s)
if style == '2':
if value > 7:
Expand Down
22 changes: 21 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div style="text-align: center">
<h1>文件快递柜</h1>
<h1>文件快递柜-Lite</h1>
<p><em>匿名口令分享文本,文件,像拿快递一样取文件</em></p>
</div>

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

## 未来规划

2022年12月14日

这个项目主要是以轻量为主,主要是单用户,离线环境,因此也不需要加太多东西,所以其实这个项目到这基本功能已经完成了,剩下的就是维护和完善现有功能。

也不会再加入新的大功能了,如果有新的功能的话,那就是我们的Pro版本了,当然也是继续开源的,能和@veoco一起开源挺荣幸的,在他的代码中我学到了许多,此前我基本上是使用Django那一套,对Fastapi仅限于使用,他的许多写法让我受益匪浅,也让我对Fastapi有了更深的了解,所以我也会在Pro版本中使用Fastapi。

根据目前一些使用反馈来说,希望加入多用户功能,还有多存储引擎等,欢迎各位继续提意见,加入我们共同开发。

如果你有更好的想法和建议欢迎提issue。

## 预览

### 寄件
Expand Down Expand Up @@ -111,3 +123,11 @@ KEYWORDS=FileCodeBox,文件快递柜,口令传送箱,匿名口令分享文
# 存储引擎
STORAGE_ENGINE=filesystem
```

## 状态

![Alt](https://repobeats.axiom.co/api/embed/7a6c92f1d96ee57e6fb67f0df371528397b0c9ac.svg "Repobeats analytics image")

## 免责声明

本项目开源仅供学习使用,不得用于任何违法用途,否则后果自负,与本人无关。使用请保留项目地址谢谢。
28 changes: 27 additions & 1 deletion readme_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

---

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

## Main features

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

## Future Plan

December 14, 2022
This project is mainly light-weight, mainly single-user, offline environment, so there is no need to add too many
things, so in fact, the basic functions of this project have been completed, and the rest is to maintain and improve the
existing functions.

No new major functions will be added. If there are new functions, it will be our Pro version. Of course, it will
continue to be open source. It is an honor to be open source with @veoco. I learned from his code Many, I basically used
the Django set before, and only used Fastapi. Many of his writing methods have benefited me a lot, and I have a deeper
understanding of Fastapi, so I will also use Fastapi in the Pro version .

According to some current feedback, I hope to add multi-user functions and multi-storage engines, etc. Welcome to
continue to give comments and join us in joint development.

If you have better ideas and suggestions, welcome to file an issue.

## Preview

### Send
Expand Down Expand Up @@ -113,3 +130,12 @@ KEYWORDS=FileCodeBox,文件快递柜,口令传送箱,匿名口令分享文
# 存储引擎
STORAGE_ENGINE=filesystem
```

## Status

![Alt](https://repobeats.axiom.co/api/embed/7a6c92f1d96ee57e6fb67f0df371528397b0c9ac.svg "Repobeats analytics image")

## Disclaimer

this project is open source for learning only and cannot be used for any illegal purposes. Otherwise, you will be
responsible for the consequences and have nothing to do with yourself. Please keep the project address. Thank you.
2 changes: 2 additions & 0 deletions settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
DATA_ROOT = './data/' + config('DATA_ROOT', cast=str, default=f"static")
# 静态文件夹URL
STATIC_URL = config('STATIC_URL', cast=str, default="/static")
# 开启上传
ENABLE_UPLOAD = config('ENABLE_UPLOAD', cast=bool, default=False)
# 错误次数
ERROR_COUNT = config('ERROR_COUNT', cast=int, default=5)
# 错误限制分钟数
Expand Down
8 changes: 5 additions & 3 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<meta name="description" content="{{description}}"/>
<meta name="keywords" content="{{keywords}}"/>
<meta name="generator" content="FileCodeBox"/>
<meta name="template" content="Lan-V1.5.1"/>
<meta name="template" content="Lan-V1.5.4"/>
<style>
.qu .el-button {
width: 100px;
Expand Down Expand Up @@ -102,6 +102,7 @@
multiple
style="margin: 1rem 0;"
:data="uploadData"
:headers="{'pwd':pwd}"
:on-success="successUpload"
:on-error="errorUpload"
>
Expand Down Expand Up @@ -194,6 +195,7 @@
files: [],
pageNum: 0,
inputDisable: false,
pwd: localStorage.getItem('pwd') || '',
uploadData: {
style: '2',
type: '1',
Expand Down Expand Up @@ -295,7 +297,8 @@
} else {
this.http('post', '/share', this.uploadData, {
headers: {
'Content-Type': 'multipart/form-data'
'Content-Type': 'multipart/form-data',
'pwd': this.pwd
}
}).then(res => {
this.files.unshift(res.data);
Expand All @@ -306,7 +309,6 @@
}
},
successUpload(response, file, fileList) {
console.log(response)
this.$message({
message: response.detail,
type: 'success'
Expand Down

0 comments on commit 12d28ec

Please sign in to comment.