Compare commits

..
31 Commits
Author SHA1 Message Date
lan 3344f471e3 update:删除过期文件夹的方式 2022-12-27 22:45:44 +08:00
lan c8ac6bb76b fix:游客上传 2022-12-27 20:28:52 +08:00
lan e66e668616 fix:上传前检测+上传次数限制 2022-12-27 13:29:54 +08:00
lan c3022bff78 fix:上传前检测+上传次数限制 2022-12-27 13:27:23 +08:00
lan f070bdcece add:输入框清空按钮 2022-12-27 10:01:10 +08:00
vastsa 58e8407e7d Merge pull request #20 from ZHYCarge/master
fix: 修改文件存放路径的拼接方式
2022-12-27 07:15:51 +08:00
ZHYCarge 5462584188 fix: 修改文件存放路径的拼接方式
fix: 修改文件存放路径的拼接方式
2022-12-26 21:12:45 +08:00
vastsa 143d4794bc Merge pull request #19 from ZHYCarge/master
add:当最后一个文件被删除时,删除整个存放目录
2022-12-24 16:11:40 +08:00
ZHYCarge 58c1d3d44b add:当最后一个文件被删除时,删除整个存放目录 2022-12-23 18:09:22 +08:00
lan 757e8ec16a add:上传前进行检测 2022-12-23 12:32:18 +08:00
lan 2fc95ebc7e update:some change 2022-12-23 12:07:46 +08:00
lan 64f476e6db fix:文件不存在删除报错 2022-12-22 20:15:04 +08:00
lan 0d5e26f752 update:开启默认上传 2022-12-22 13:00:44 +08:00
lan b33671a018 update:分开寄取文件箱 2022-12-22 12:15:42 +08:00
lan 56cf08ccd1 update:分开寄取文件箱 2022-12-22 12:14:41 +08:00
lan f4089877ed update:分开寄取文件箱 2022-12-22 12:11:32 +08:00
lan 248e6b8292 update:index.html 2022-12-22 08:47:04 +08:00
lan ab3971f911 update:arm docker 2022-12-21 22:18:44 +08:00
lan 6c07f9a5ab update:arm docker 2022-12-21 22:12:14 +08:00
vastsa f94a918253 Update readme.md 2022-12-21 22:09:37 +08:00
lan eec2ec6354 update:arm docker 2022-12-21 22:05:53 +08:00
lan 330b34953d update:dark theme 2022-12-21 19:43:54 +08:00
lan 0433507a9c update:dark theme 2022-12-21 19:32:39 +08:00
lan 63105579f7 update:dark theme 2022-12-21 19:19:42 +08:00
lan 255a2149b0 update:dark theme 2022-12-21 19:10:51 +08:00
lan 0b12aad4eb update:dark theme 2022-12-21 18:55:30 +08:00
lan 7767ade2f3 update:readme 2022-12-21 17:01:27 +08:00
lan c15bf9563c fix:复制提示词 2022-12-21 14:33:26 +08:00
lan 99529b69ee Merge remote-tracking branch 'origin/master' 2022-12-20 12:09:33 +08:00
lan d6029e4899 fix:max-width 2022-12-20 11:46:48 +08:00
lan 14b6f0e9a7 fix:admin error 2022-12-19 22:26:30 +08:00
9 changed files with 236 additions and 89 deletions

No files matched your search

+1 -4
View File
@@ -16,11 +16,8 @@ async def admin_required(pwd: Union[str, None] = Header(default=None), request:
class IPRateLimit:
ips = {}
count = 0
minutes = 0
def __init__(self, count, minutes):
self.ips = {}
self.count = count
self.minutes = minutes
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 57 KiB

+6 -5
View File
@@ -41,8 +41,8 @@ index_html = open('templates/index.html', 'r', encoding='utf-8').read() \
.replace('{{title}}', settings.TITLE) \
.replace('{{description}}', settings.DESCRIPTION) \
.replace('{{keywords}}', settings.KEYWORDS) \
.replace("'{{fileSizeLimit}}'", str(settings.FILE_SIZE_LIMIT))
# 管理页面
.replace("'{{fileSizeLimit}}'", str(settings.FILE_SIZE_LIMIT)) \
# 管理页面
admin_html = open('templates/admin.html', 'r', encoding='utf-8').read() \
.replace('{{title}}', settings.TITLE) \
.replace('{{description}}', settings.DESCRIPTION) \
@@ -98,7 +98,7 @@ async def admin_delete(code: str, s: AsyncSession = Depends(get_session)):
async def config(s: AsyncSession = Depends(get_session)):
# 从数据库获取系统配置
data = (await s.execute(select(Values).filter(Values.key == 'config'))).scalar_one_or_none()
return {'detail': '获取成功', 'data': data.value}
return {'detail': '获取成功', 'data': data.value if data else {}}
@app.get('/')
@@ -107,7 +107,7 @@ async def index():
@app.get('/banner')
async def banner(s: AsyncSession = Depends(get_session)):
async def banner(request: Request, s: AsyncSession = Depends(get_session)):
# 数据库查询config
config = (await s.execute(select(Values).filter(Values.key == 'config'))).scalar_one_or_none()
# 如果存在config,就返回config的value
@@ -119,6 +119,7 @@ async def banner(s: AsyncSession = Depends(get_session)):
# 如果不存在config,就返回默认的banner
return {
'detail': 'banner',
'enable': request.headers.get('pwd', '') == settings.ADMIN_PASSWORD or settings.ENABLE_UPLOAD,
'data': [{
'text': 'FileCodeBox',
'url': 'https://github.com/vastsa/FileCodeBox',
@@ -201,7 +202,7 @@ async def share(background_tasks: BackgroundTasks, text: str = Form(default=None
upload_ip_limit.add_ip(ip)
return {
'detail': '分享成功,请点击取件码按钮查看上传列表',
'data': {'code': code, 'key': key, 'name': name, 'text': _text}
'data': {'code': code, 'key': key, 'name': name}
}
+58 -13
View File
@@ -20,7 +20,36 @@
- [x] 管理面板:查看所有文件,删除文件
- [x] 一键部署:docker一键部署
## 未来规划
## 部署方式
### Docker一键部署
#### AMD
```bash
docker run -d --restart=always -p 12345:12345 -v /opt/FileCodeBox/:/app/data --name filecodebox lanol/filecodebox:latest
```
#### ARM
```bash
docker run -d --restart=always -p 12345:12345 -v /opt/FileCodeBox/:/app/data --name filecodebox lanol/filecodebox:arm
```
### 更新方式
```bash
// 停止容器并删除
docker stop filecodebox && docker rm filecodebox
// 重新运行容器
docker run -d --restart=always -p 12345:12345 -v /opt/FileCodeBox/:/app/data --name filecodebox lanol/filecodebox:latest
```
### 其他方式
仅供参考,历史版本->[部署文档](https://www.yuque.com/lxyo/work/zd0kvzy7fofx6w7v)
## 项目规划
2022年12月14日
@@ -39,6 +68,22 @@
[https://share.lanol.cn](https://share.lanol.cn)
### 暗黑模式
<table style="width:100%">
<tr style="width: 100%">
<td style="width: 50%">
<img src="https://raw.githubusercontent.com/vastsa/FileCodeBox/master/images/img_10.png" alt="寄文件">
</td>
<td style="width: 50%">
<img src="https://raw.githubusercontent.com/vastsa/FileCodeBox/master/images/img_11.png" alt="寄文件">
</td>
</tr>
</table>
### 寄件
<table style="width: 100%">
@@ -79,18 +124,6 @@
![管理](https://raw.githubusercontent.com/vastsa/FileCodeBox/master/images/img_7.png)
## 部署方式
### Docker一键部署
```bash
docker run -d --restart=always -p 12345:12345 -v /opt/FileCodeBox/:/app/data --name filecodebox lanol/filecodebox:latest
```
### 其他方式
仅供参考,历史版本->[部署文档](https://www.yuque.com/lxyo/work/zd0kvzy7fofx6w7v)
## 配置文件
如果需要修改配置,可以将该文件放在`/opt/FileCodeBox/`目录下,并命名为`.env`,然后重启容器即可。
@@ -137,6 +170,10 @@ STORAGE_ENGINE=filesystem
![Alt](https://repobeats.axiom.co/api/embed/7a6c92f1d96ee57e6fb67f0df371528397b0c9ac.svg "Repobeats analytics image")
## Star History
[![Star History Chart](https://api.star-history.com/svg?repos=vastsa/FileCodeBox&type=Date)](https://star-history.com/#vastsa/FileCodeBox&Date)
## 赞赏
<table style="width: 100%">
@@ -152,6 +189,14 @@ STORAGE_ENGINE=filesystem
</tr>
</table>
## 常见问题
1. 413 Request Entity Too Large
Nginx限制:
找到自己主机的nginx.conf配置文件,打开
在http{}中加入 client_max_body_size 10m;
然后重启nginx
## 免责声明
本项目开源仅供学习使用,不得用于任何违法用途,否则后果自负,与本人无关。使用请保留项目地址谢谢。
+52 -13
View File
@@ -20,7 +20,38 @@
- [x] management Panel: View all files and delete them
- [x] one-click deployment: docker one-click deployment
## Future Plan
## Deployment method
### One-click Docker deployment
#### AMD
```bash
docker run -d --restart=always -p 12345:12345 -v /opt/FileCodeBox/:/app/data --name filecodebox lanol/filecodebox:latest
```
#### ARM
```bash
docker run -d --restart=always -p 12345:12345 -v /Users/lan/soft/FileCodeBox/:/app/data --name filecodebox lanol/filecodebox:arm
```
### Update
```bash
// 找到容器ID
docker ps -a
// 停止容器并删除
docker stop 容器ID && docker rm 容器ID
// 重新运行容器
docker run -d --restart=always -p 12345:12345 -v /opt/FileCodeBox/:/app/data --name filecodebox lanol/filecodebox:latest
```
### Other methods
For reference only, historical version->[部署文档](https://www.yuque.com/lxyo/work/zd0kvzy7fofx6w7v)
## Project Plan
December 14, 2022
This project is mainly light-weight, mainly single-user, offline environment, so there is no need to add too many
@@ -43,6 +74,22 @@ If you have better ideas and suggestions, welcome to file an issue.
[https://share.lanol.cn](https://share.lanol.cn)
### Dark Theme
<table style="width:100%">
<tr style="width: 100%">
<td style="width: 50%">
<img src="https://raw.githubusercontent.com/vastsa/FileCodeBox/master/images/img_10.png" alt="寄文件">
</td>
<td style="width: 50%">
<img src="https://raw.githubusercontent.com/vastsa/FileCodeBox/master/images/img_11.png" alt="寄文件">
</td>
</tr>
</table>
### Send
<table style="width: 100%">
@@ -83,18 +130,6 @@ If you have better ideas and suggestions, welcome to file an issue.
![管理](https://raw.githubusercontent.com/vastsa/FileCodeBox/master/images/img_7.png)
## Deployment method
### One-click Docker deployment
```bash
docker run -d --restart=always -p 12345:12345 -v /opt/FileCodeBox/:/app/data --name filecodebox lanol/filecodebox:latest
```
### Other methods
For reference only, historical version->[部署文档](https://www.yuque.com/lxyo/work/zd0kvzy7fofx6w7v)
## Configuration file
if you need to modify the configuration, you can put the file in `/opt/FileCodeBox/` directory and name it `.env` , and
@@ -143,6 +178,10 @@ STORAGE_ENGINE=filesystem
![Alt](https://repobeats.axiom.co/api/embed/7a6c92f1d96ee57e6fb67f0df371528397b0c9ac.svg "Repobeats analytics image")
## Star History
[![Star History Chart](https://api.star-history.com/svg?repos=vastsa/FileCodeBox&type=Date)](https://star-history.com/#vastsa/FileCodeBox&Date)
## Appreciate
<table style="width: 100%">
+1 -1
View File
@@ -16,7 +16,7 @@ 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)
ENABLE_UPLOAD = config('ENABLE_UPLOAD', cast=bool, default=True)
# 最长天数
MAX_DAYS = config('MAX_DAYS', cast=int, default=7)
# 错误次数
+12 -1
View File
@@ -49,12 +49,23 @@ class FileSystemStorage:
async def delete_file(self, text: str):
filepath = await self.get_filepath(text)
await asyncio.to_thread(os.remove, filepath)
if filepath.exists():
await asyncio.to_thread(os.remove, filepath)
await asyncio.to_thread(self.judge_delete_folder, filepath)
async def delete_files(self, texts):
tasks = [self.delete_file(text) for text in texts]
await asyncio.gather(*tasks)
def judge_delete_folder(self, filepath):
current = filepath.parent
while current != self.DATA_ROOT:
if not list(current.iterdir()):
os.rmdir(current)
current = current.parent
else:
break
STORAGE_ENGINE = {
"filesystem": FileSystemStorage
+106 -52
View File
@@ -29,6 +29,11 @@
font-weight: bold;
}
.el-icon-circle-close::before {
font-size: 26px !important;
line-height: 128px;
}
.qu .el-input__inner {
height: 100px;
margin: 1rem 0;
@@ -40,14 +45,43 @@
.el-card {
border-radius: 20px;
}
@media (prefers-color-scheme: dark) {
body {
background-color: #18181c;
}
.el-card, .el-textarea__inner, .el-upload-dragger {
border-radius: 20px;
border: 1px solid transparent;
background-color: rgba(255, 255, 255, 0.1);
box-shadow: 5px 5px 0 0 rgba(0, 0, 0, 0.2);
}
* {
color: #ccc !important;
}
.el-input-group__prepend, .el-input__inner, .el-input-group__append, .el-empty__description, .el-select-dropdown, .el-button {
border: 1px solid transparent;
background-color: rgba(0, 0, 0, 0.2);
}
.el-drawer, #el-drawer__title, .el-drawer__body, .el-drawer__wrapper {
background-color: rgba(0, 0, 0, 0.5);
border: 1px solid transparent;
}
}
</style>
<script src="/static/asserts/vue.min.js"></script>
<script src="/static/asserts/index.js"></script>
</head>
<body>
<div id="app" style="text-align: center">
<el-row v-if="pageNum === 0" class="qu" style="width:400px;height: 596px;margin: 6vh auto 0 auto">
<el-card style="padding-bottom: 1rem">
<el-row v-if="pageNum === 0" class="qu" style="max-width:400px;margin: 4rem auto 0 auto">
<el-card class="glass" style="padding-bottom: 1rem">
<el-col :span="24">
<el-input round autofocus @change="changeInput" clearable v-model:value="code" maxlength="5"
:disabled="inputDisable" placeholder="请输入五位取件码">
@@ -95,7 +129,7 @@
</el-col>
</el-card>
</el-row>
<el-row v-else style="width:400px;margin: 6vh auto 0 auto">
<el-row v-else style="max-width:400px;margin: 4rem auto 0 auto">
<el-col :span="24">
<el-card :body-style="{ padding: '0px 0px 20px 0px' }">
<div class="block" style="margin-bottom: 1rem">
@@ -174,7 +208,7 @@
:direction="direction"
size="50%"
>
<el-card v-for="(file,index) in files" :key="index" class="box-card">
<el-card v-for="(file,index) in quFiles" :key="index" class="box-card">
<div style="cursor: pointer;text-align: left;margin-left: 2rem">
<div>取件码:${ file.code }</div>
<div>文件名:${ file.name }</div>
@@ -189,36 +223,34 @@
</div>
</div>
</el-card>
<el-empty v-if="files.length===0" description="请输入取件码,收取文件"></el-empty>
<el-empty v-if="quFiles.length===0" description="请输入取件码,收取文件"></el-empty>
</el-drawer>
<el-drawer
title="文件箱"
:visible.sync="jiDrawer"
:direction="direction"
size="50%">
<el-card>
<el-empty v-if="files.length===0" description="请上传文件"></el-empty>
<el-card style="margin-top: 0.2rem" v-for="(file,index) in files" :key="index">
<el-row>
<el-col :span="15">
<el-row>
<el-col :span="24" style="line-height: 45px">
${ file.name }
</el-col>
<el-col :span="24">
取件码:
<h1 @click="copyText(file.code,0)" style="margin: 0;display: inline;cursor: pointer">
${ file.code }
</h1>
</el-col>
</el-row>
</el-col>
<el-col :span="4">
<img style="width: 80px;height: 80px;"
:src="qrcodeUrl(file)" alt="二维码" :alt="file.code">
</el-col>
</el-row>
</el-card>
<el-empty v-if="jiFiles.length===0" description="请上传文件"></el-empty>
<el-card style="margin-top: 0.2rem" v-for="(file,index) in jiFiles" :key="index">
<el-row>
<el-col :span="15">
<el-row>
<el-col :span="24" style="line-height: 45px">
${ file.name }
</el-col>
<el-col :span="24">
取件码:
<h1 @click="copyText(file.code,0)" style="margin: 0;display: inline;cursor: pointer">
${ file.code }
</h1>
</el-col>
</el-row>
</el-col>
<el-col :span="4">
<img style="width: 80px;height: 80px;"
:src="qrcodeUrl(file)" alt="二维码" :alt="file.code">
</el-col>
</el-row>
</el-card>
</el-drawer>
<div style="text-align: center; margin-top: 1rem;color: #606266">
@@ -237,12 +269,14 @@
quDrawer: false,
jiDrawer: false,
direction: 'btt',
files: [],
quFiles: [],
jiFiles: [],
pageNum: 0,
inputDisable: false,
fileSizeLimit: '{{fileSizeLimit}}',
pwd: localStorage.getItem('pwd') || '',
banners: [],
enableUpload: false,
uploadData: {
style: '2',
type: '1',
@@ -285,7 +319,12 @@
}
});
// 获取Banner
axios.get('/banner').then(res => {
axios.get('/banner', {
headers: {
pwd: localStorage.getItem('pwd')
}
}).then(res => {
this.enableUpload = res.data.enable
this.banners = res.data.data
})
},
@@ -321,7 +360,7 @@
},
copyText: function (value, style = 1) {
if (style === 0) {
value = `我在分享了给你文件,取件码:${value},${window.location.href}?code=${value}`;
value = `我给你分享了文件,取件码:${value},${window.location.href}?code=${value}`;
}
const input = document.createElement('input');
input.setAttribute('readonly', 'readonly');
@@ -341,13 +380,13 @@
const that = this;
this.http('post', `?code=${that.code}`).then(res => {
that.quDrawer = true;
that.files.unshift(res.data);
that.quFiles.unshift(res.data);
})
that.code = '';
that.input_disable = false
},
qrcodeUrl(file) {
return 'https://api.qrserver.com/v1/create-qr-code/?data=' + window.location.origin + '/?code=' + file.code
return 'https://api.qrserver.com/v1/create-qr-code/?data=' + window.location.href + '/?code=' + file.code
},
listenInput: function (value) {
if (this.code.length < 5) {
@@ -357,6 +396,25 @@
changeInput: function (value) {
this.code = value;
},
checkFile: function (file) {
if (!this.enableUpload) {
this.$message({
message: '上传功能已关闭',
type: 'error'
});
return false
}
if (file != null) {
if (file.size > this.fileSizeLimit) {
this.$message({
message: `文件大小不能超过${this.fileSizeLimit/1024/1024}MB`,
type: 'error'
});
return false;
}
}
return true;
},
toUploadData: function () {
if (this.uploadData.text === '' && this.uploadData.file === null) {
this.$message({
@@ -364,17 +422,19 @@
type: 'error'
});
} else {
this.http('post', '/share', this.uploadData, {
headers: {
'Content-Type': 'multipart/form-data',
'pwd': this.pwd
}
}).then(res => {
this.files.unshift(res.data);
this.jiDrawer = true;
this.uploadData.text = '';
this.uploadData.file = null;
});
if (this.checkFile(this.uploadData.file)) {
this.http('post', '/share', this.uploadData, {
headers: {
'Content-Type': 'multipart/form-data',
'pwd': this.pwd
}
}).then(res => {
this.jiFiles.unshift(res.data);
this.jiDrawer = true;
this.uploadData.text = '';
this.uploadData.file = null;
});
}
}
},
successUpload(response, file, fileList) {
@@ -382,7 +442,7 @@
message: response.detail,
type: 'success'
});
this.files.unshift(response.data);
this.jiFiles.unshift(response.data);
},
errorUpload(error, file, fileList) {
error = JSON.parse(error.message)
@@ -392,13 +452,7 @@
});
},
beforeUpload: function (file) {
if (file.size > this.fileSizeLimit) {
this.$message({
message: `文件大小不能超过${this.fileSizeLimit/1024/1024}MB`,
type: 'error'
});
return false
}
return this.checkFile(file);
}
}
})