add:开关上传功能,关闭则仅允许管理员上传

This commit is contained in:
lan
2022-12-14 01:13:48 +08:00
parent 65ad220bb4
commit 12d28ec691
7 changed files with 94 additions and 167 deletions
-158
View File
@@ -1,158 +0,0 @@
# 文件快递柜
## 解决问题
很多时候,我们都想将一些文件或文本传送给别人,或者跨端传递一些信息,但是我们又不想为了分享,而去下载一些七里八里的软件,这时候,我们就可以使用口令传送箱,像拿快递一样取文件。
## 主要特色
- [x] 轻量简洁,Fastapi+sqlite3
- [x] 拖拽,复制粘贴上传
- [x] 文件口令传输,生成二维码
- [x] 分享文件:多种上传方式供你选择
- [x] 分享文本:直接复制粘贴直接上传
- [x] 防爆破:错误五次拉黑十分钟
- [x] 完全匿名:不记录任何信息,无需注册,无需登录
- [x] Sqlite3数据库:无需安装数据库
- [x] 管理面板:简单列表页删除违规文件
- [x] 口令使用次数,口令有效期,二维码分享
## 更新记录
### 2022年12月13日
- [x] 完善手机版上传文本
- [x] 优化Index.html首页
### 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. 完善配置参数
## 系统截图
1. 隐藏文件真实地址
### 取件
![取件](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)
## 部署教程
https://www.yuque.com/lxyo/work/zd0kvzy7fofx6w7v
## 部署方式
为持久化,不管怎么样,先第一步,建一个文件夹,然后再下载代码
```bash
mkdir /opt/FileCodeBox
cd /opt/FileCodeBox
```
新建一个`.env`文件
```bash
vi .env
```
将下列字段内容替换成你自己的
```dotenv
# 端口
PORT=12345
# Sqlite数据库文件
DATABASE_URL=sqlite+aiosqlite:///database.db
# 静态文件夹
DATA_ROOT=./static
# 静态文件夹URL
STATIC_URL=/static
# 错误次数
ERROR_COUNT=5
# 错误限制分钟数
ERROR_MINUTE=10
# 上传次数
UPLOAD_COUNT=60
# 上传限制分钟数
UPLOAD_MINUTE=1
# 管理地址
ADMIN_ADDRESS=admin
# 管理密码
ADMIN_PASSWORD=admin
# 文件大小限制,默认10MB
FILE_SIZE_LIMIT=10
# 网站标题
TITLE=文件快递柜
# 网站描述
DESCRIPTION=FileCodeBox,文件快递柜,口令传送箱,匿名口令分享文本,文件,图片,视频,音频,压缩包等文件
# 网站关键词
KEYWORDS=FileCodeBox,文件快递柜,口令传送箱,匿名口令分享文本,文件,图片,视频,音频,压缩包等文件
# 存储引擎
STORAGE_ENGINE=filesystem
```
### 服务端部署
1. 安装Python3
2. 拉取代码,解压缩
3. 安装依赖包:`pip install -r requirements.txt`
4. 运行` uvicorn main:app --host 0.0.0.0 --port 12345`
5. 然后你自己看怎么进程守护吧
### 宝塔部署
1. 安装宝塔Python Manager
2. 然后你自己看着填吧
### Docker部署
```bash
docker run -d --restart=always -p 12345:12345 -v /opt/FileCodeBox/.env:/app/data --name filecodebox lanol/filecodebox:latest
```
### Docker自己构建部署
```bash
mkdir "/opt/FileCodeBox"
cd "/opt/FileCodeBox"
wget https://github.com/vastsa/FileCodeBox/releases/download/Main/code.zip
unzip code.zip
docker build --file Dockerfile --tag filecodebox .
docker run -d -p 12345:12345 --name filecodebox --volume /opt/FileCodeBox:/app filecodebox
```
## 状态
![Alt](https://repobeats.axiom.co/api/embed/7a6c92f1d96ee57e6fb67f0df371528397b0c9ac.svg "Repobeats analytics image")
## 免责声明
本项目开源仅供学习使用,不得用于商业用途以及任何违法用途,否则后果自负,与本人无关。使用请保留项目地址谢谢。
+33
View File
@@ -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. 完善配置参数
+6 -4
View File
@@ -3,7 +3,7 @@ import uuid
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
@@ -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:
+21 -1
View File
@@ -1,5 +1,5 @@
<div style="text-align: center">
<h1>文件快递柜</h1>
<h1>文件快递柜-Lite</h1>
<p><em>匿名口令分享文本,文件,像拿快递一样取文件</em></p>
</div>
@@ -19,6 +19,18 @@
- [x] 管理面板:查看所有文件,删除文件
- [x] 一键部署:docker一键部署
## 未来规划
2022年12月14日
这个项目主要是以轻量为主,主要是单用户,离线环境,因此也不需要加太多东西,所以其实这个项目到这基本功能已经完成了,剩下的就是维护和完善现有功能。
也不会再加入新的大功能了,如果有新的功能的话,那就是我们的Pro版本了,当然也是继续开源的,能和@veoco一起开源挺荣幸的,在他的代码中我学到了许多,此前我基本上是使用Django那一套,对Fastapi仅限于使用,他的许多写法让我受益匪浅,也让我对Fastapi有了更深的了解,所以我也会在Pro版本中使用Fastapi。
根据目前一些使用反馈来说,希望加入多用户功能,还有多存储引擎等,欢迎各位继续提意见,加入我们共同开发。
如果你有更好的想法和建议欢迎提issue。
## 预览
### 寄件
@@ -111,3 +123,11 @@ KEYWORDS=FileCodeBox,文件快递柜,口令传送箱,匿名口令分享文
# 存储引擎
STORAGE_ENGINE=filesystem
```
## 状态
![Alt](https://repobeats.axiom.co/api/embed/7a6c92f1d96ee57e6fb67f0df371528397b0c9ac.svg "Repobeats analytics image")
## 免责声明
本项目开源仅供学习使用,不得用于任何违法用途,否则后果自负,与本人无关。使用请保留项目地址谢谢。
+27 -1
View File
@@ -5,7 +5,7 @@
---
[English](./README_EN.md) | [简体中文](./README.md)
[简体中文](./readme.md) | [English](./readme_en.md)
## Main features
@@ -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
@@ -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
View File
@@ -15,6 +15,8 @@ DATABASE_URL = config('DATABASE_URL', cast=str, default=f"sqlite+aiosqlite:///{D
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)
# 错误限制分钟数
+5 -3
View File
@@ -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;
@@ -102,6 +102,7 @@
multiple
style="margin: 1rem 0;"
:data="uploadData"
:headers="{'pwd':pwd}"
:on-success="successUpload"
:on-error="errorUpload"
>
@@ -194,6 +195,7 @@
files: [],
pageNum: 0,
inputDisable: false,
pwd: localStorage.getItem('pwd') || '',
uploadData: {
style: '2',
type: '1',
@@ -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);
@@ -306,7 +309,6 @@
}
},
successUpload(response, file, fileList) {
console.log(response)
this.$message({
message: response.detail,
type: 'success'