mirror of
https://github.com/vastsa/FileCodeBox.git
synced 2026-11-21 06:16:59 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3da4fc0ea7 | ||
|
|
c7253ba874 | ||
|
|
2bb32bc59c | ||
|
|
c9785b92d7 | ||
|
|
455602d323 | ||
|
|
65fa3c9a7d | ||
|
|
c87e388ad3 | ||
|
|
77b50f950f | ||
|
|
46310bb4b8 | ||
|
|
34327f4a53 | ||
|
|
fbba00fda7 | ||
|
|
ea52327e49 | ||
|
|
7f44093c91 | ||
|
|
1bbe7f4d5d | ||
|
|
b2825cf088 | ||
|
|
e9c34a3710 | ||
|
|
3344f471e3 | ||
|
|
c8ac6bb76b | ||
|
|
e66e668616 | ||
|
|
c3022bff78 | ||
|
|
f070bdcece | ||
|
|
58e8407e7d | ||
|
|
5462584188 | ||
|
|
143d4794bc | ||
|
|
58c1d3d44b | ||
|
|
757e8ec16a | ||
|
|
2fc95ebc7e | ||
|
|
64f476e6db | ||
|
|
0d5e26f752 | ||
|
|
b33671a018 | ||
|
|
56cf08ccd1 | ||
|
|
f4089877ed | ||
|
|
248e6b8292 | ||
|
|
ab3971f911 | ||
|
|
6c07f9a5ab | ||
|
|
f94a918253 | ||
|
|
eec2ec6354 | ||
|
|
330b34953d | ||
|
|
0433507a9c | ||
|
|
63105579f7 | ||
|
|
255a2149b0 | ||
|
|
0b12aad4eb | ||
|
|
7767ade2f3 | ||
|
|
c15bf9563c | ||
|
|
99529b69ee | ||
|
|
d6029e4899 | ||
|
|
14b6f0e9a7 |
No files matched your search
@@ -0,0 +1,4 @@
|
||||
# These are supported funding model platforms
|
||||
|
||||
github: [vastsa]
|
||||
custom: [https://share.lanol.cn]
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
FROM python:3.9.5-slim-buster
|
||||
LABEL author="Lan"
|
||||
LABEL email="vast@tom.com"
|
||||
LABEL version="1.5.8"
|
||||
LABEL version="1.5.9.2"
|
||||
|
||||
|
||||
COPY . /app
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
import datetime
|
||||
from sqlalchemy import Boolean, Column, Integer, String, DateTime, JSON
|
||||
from sqlalchemy import Boolean, Column, Integer, String, DateTime, JSON, Text
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
from sqlalchemy.ext.asyncio import create_async_engine
|
||||
from sqlalchemy.ext.asyncio.session import AsyncSession
|
||||
@@ -35,7 +35,7 @@ class Codes(Base):
|
||||
name = Column(String(500))
|
||||
size = Column(Integer)
|
||||
type = Column(String(20))
|
||||
text = Column(String(500))
|
||||
text = Column(Text)
|
||||
used = Column(Boolean, default=False)
|
||||
count = Column(Integer, default=-1)
|
||||
use_time = Column(DateTime, default=datetime.datetime.now, onupdate=datetime.datetime.now)
|
||||
|
||||
+1
-4
@@ -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
|
||||
|
||||
|
||||
-33
@@ -1,33 +0,0 @@
|
||||
## 更新记录
|
||||
|
||||
### 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. 完善配置参数
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 33 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 57 KiB |
@@ -2,14 +2,25 @@ import datetime
|
||||
import uuid
|
||||
import asyncio
|
||||
from pathlib import Path
|
||||
import os
|
||||
|
||||
from fastapi import FastAPI, Depends, UploadFile, Form, File, HTTPException, BackgroundTasks
|
||||
from starlette.requests import Request
|
||||
from starlette.responses import HTMLResponse, FileResponse
|
||||
from starlette.staticfiles import StaticFiles
|
||||
|
||||
from sqlalchemy import select, update, func
|
||||
from sqlalchemy.ext.asyncio.session import AsyncSession
|
||||
try:
|
||||
import chardet
|
||||
from fastapi import FastAPI, Depends, UploadFile, Form, File, HTTPException, BackgroundTasks
|
||||
from starlette.requests import Request
|
||||
from starlette.responses import HTMLResponse, FileResponse
|
||||
from starlette.staticfiles import StaticFiles
|
||||
from sqlalchemy import select, update, func
|
||||
from sqlalchemy.ext.asyncio.session import AsyncSession
|
||||
except ImportError:
|
||||
os.system("pip install -r requirements.txt")
|
||||
import chardet
|
||||
from fastapi import FastAPI, Depends, UploadFile, Form, File, HTTPException, BackgroundTasks
|
||||
from starlette.requests import Request
|
||||
from starlette.responses import HTMLResponse, FileResponse
|
||||
from starlette.staticfiles import StaticFiles
|
||||
from sqlalchemy import select, update, func
|
||||
from sqlalchemy.ext.asyncio.session import AsyncSession
|
||||
|
||||
import settings
|
||||
from utils import delete_expire_files, storage, get_code, error_ip_limit, upload_ip_limit
|
||||
@@ -41,8 +52,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 +109,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 {'banners': []}}
|
||||
|
||||
|
||||
@app.get('/')
|
||||
@@ -106,19 +117,40 @@ async def index():
|
||||
return HTMLResponse(index_html)
|
||||
|
||||
|
||||
@app.post('/')
|
||||
async def index(code: str, ip: str = Depends(error_ip_limit), s: AsyncSession = Depends(get_session)):
|
||||
query = select(Codes).where(Codes.code == code)
|
||||
info = (await s.execute(query)).scalars().first()
|
||||
if not info:
|
||||
error_count = settings.ERROR_COUNT - error_ip_limit.add_ip(ip)
|
||||
raise HTTPException(status_code=404, detail=f"取件码错误,{error_count}次后将被禁止{settings.ERROR_MINUTE}分钟")
|
||||
if info.exp_time < datetime.datetime.now() or info.count == 0:
|
||||
raise HTTPException(status_code=404, detail="取件码已失效,请联系寄件人")
|
||||
await s.execute(update(Codes).where(Codes.id == info.id).values(count=info.count - 1))
|
||||
await s.commit()
|
||||
if info.type != 'text':
|
||||
info.text = f'/select?code={code}'
|
||||
return {
|
||||
'detail': f'取件成功,文件将在{settings.DELETE_EXPIRE_FILES_INTERVAL}分钟后删除',
|
||||
'data': {'type': info.type, 'text': info.text, 'name': info.name, 'code': info.code}
|
||||
}
|
||||
|
||||
|
||||
@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
|
||||
if config and config.value.get('banners'):
|
||||
return {
|
||||
'detail': '查询成功',
|
||||
'data': config.value['banners']
|
||||
'data': config.value['banners'],
|
||||
'enable': request.headers.get('pwd', '') == settings.ADMIN_PASSWORD or settings.ENABLE_UPLOAD,
|
||||
}
|
||||
# 如果不存在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',
|
||||
@@ -149,25 +181,6 @@ async def get_file(code: str, ip: str = Depends(error_ip_limit), s: AsyncSession
|
||||
return FileResponse(filepath, filename=info.name)
|
||||
|
||||
|
||||
@app.post('/')
|
||||
async def index(code: str, ip: str = Depends(error_ip_limit), s: AsyncSession = Depends(get_session)):
|
||||
query = select(Codes).where(Codes.code == code)
|
||||
info = (await s.execute(query)).scalars().first()
|
||||
if not info:
|
||||
error_count = settings.ERROR_COUNT - error_ip_limit.add_ip(ip)
|
||||
raise HTTPException(status_code=404, detail=f"取件码错误,{error_count}次后将被禁止{settings.ERROR_MINUTE}分钟")
|
||||
if info.exp_time < datetime.datetime.now() or info.count == 0:
|
||||
raise HTTPException(status_code=404, detail="取件码已失效,请联系寄件人")
|
||||
await s.execute(update(Codes).where(Codes.id == info.id).values(count=info.count - 1))
|
||||
await s.commit()
|
||||
if info.type != 'text':
|
||||
info.text = f'/select?code={code}'
|
||||
return {
|
||||
'detail': f'取件成功,文件将在{settings.DELETE_EXPIRE_FILES_INTERVAL}分钟后删除',
|
||||
'data': {'type': info.type, 'text': info.text, 'name': info.name, 'code': info.code}
|
||||
}
|
||||
|
||||
|
||||
@app.post('/share', dependencies=[Depends(admin_required)], description='分享文件')
|
||||
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),
|
||||
@@ -200,8 +213,8 @@ async def share(background_tasks: BackgroundTasks, text: str = Form(default=None
|
||||
await s.commit()
|
||||
upload_ip_limit.add_ip(ip)
|
||||
return {
|
||||
'detail': '分享成功,请点击取件码按钮查看上传列表',
|
||||
'data': {'code': code, 'key': key, 'name': name, 'text': _text}
|
||||
'detail': '分享成功,请点击我的文件按钮查看上传列表',
|
||||
'data': {'code': code, 'key': key, 'name': name}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<div style="text-align: center">
|
||||
<h1>文件快递柜-轻量</h1>
|
||||
<h2>FileCoxBox-Lite</h2>
|
||||
<h2>FileCodeBox-Lite</h2>
|
||||
<p><em>匿名口令分享文本,文件,像拿快递一样取文件</em></p>
|
||||
</div>
|
||||
|
||||
@@ -20,18 +20,41 @@
|
||||
- [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日
|
||||
|
||||
这个项目的灵感来源于丁丁快传,然后写了这么一个基于本机存储的快传系统,本系统主要是以轻量,单用户,离线环境(`私有化`
|
||||
)为主,因此也不需要加太多东西,所以其实这个项目到这基本功能已经完成了,剩下的就是维护和完善现有功能。
|
||||
|
||||
也不会再加入新的大功能了,如果有新的功能的话,那就是我们的Pro版本了,当然也是继续开源的,能和@veoco一起开源挺荣幸的,在他的代码中我学到了许多,此前我基本上是使用Django那一套,对Fastapi仅限于使用,他的许多写法让我受益匪浅,也让我对Fastapi有了更深的了解,所以我也会在Pro版本中使用Fastapi。
|
||||
|
||||
根据目前一些使用反馈来说,希望加入登录功能,还有多存储引擎等,欢迎各位继续提意见,加入我们共同开发。
|
||||
|
||||
如果你有更好的想法和建议欢迎提issue。
|
||||
也不会再加入新的大功能了,如果你有更好的想法和建议欢迎提issue。
|
||||
|
||||
## 预览
|
||||
|
||||
@@ -39,6 +62,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 +118,6 @@
|
||||
|
||||

|
||||
|
||||
## 部署方式
|
||||
|
||||
### 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`,然后重启容器即可。
|
||||
@@ -133,10 +160,76 @@ KEYWORDS=FileCodeBox,文件快递柜,口令传送箱,匿名口令分享文
|
||||
STORAGE_ENGINE=filesystem
|
||||
```
|
||||
|
||||
## 接口文档
|
||||
|
||||
前端比较简陋,可以使用接口进行二次开发
|
||||
|
||||
### 取件
|
||||
|
||||
#### PATH
|
||||
|
||||
`/`
|
||||
|
||||
#### METHOD
|
||||
|
||||
`POST`
|
||||
|
||||
#### PARAMS
|
||||
|
||||
code: 取件码
|
||||
|
||||
#### Response
|
||||
|
||||
```json
|
||||
{
|
||||
"detail": "msg",
|
||||
"data": {
|
||||
"type": "类型",
|
||||
"text": "文本",
|
||||
"name": "名称",
|
||||
"code": "取件码"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 寄件
|
||||
|
||||
#### PATH
|
||||
|
||||
`/share`
|
||||
|
||||
#### METHOD
|
||||
|
||||
`POST`
|
||||
|
||||
#### PARAMS
|
||||
|
||||
style: 1为次数,2为时间
|
||||
value: 次数或时间
|
||||
text: 取件码
|
||||
file: 文件
|
||||
|
||||
#### Response
|
||||
|
||||
```json
|
||||
{
|
||||
"detail": "msg",
|
||||
"data": {
|
||||
"code": "类型",
|
||||
"key": "唯一ID",
|
||||
"name": "名称"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 状态
|
||||
|
||||

|
||||
|
||||
## Star History
|
||||
|
||||
[](https://star-history.com/#vastsa/FileCodeBox&Date)
|
||||
|
||||
## 赞赏
|
||||
|
||||
<table style="width: 100%">
|
||||
@@ -152,6 +245,14 @@ STORAGE_ENGINE=filesystem
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
## 常见问题
|
||||
|
||||
1. 413 Request Entity Too Large
|
||||
Nginx限制:
|
||||
找到自己主机的nginx.conf配置文件,打开
|
||||
在http{}中加入 client_max_body_size 10m;
|
||||
然后重启nginx
|
||||
|
||||
## 免责声明
|
||||
|
||||
本项目开源仅供学习使用,不得用于任何违法用途,否则后果自负,与本人无关。使用请保留项目地址谢谢。
|
||||
+52
-13
@@ -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.
|
||||
|
||||

|
||||
|
||||
## 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
|
||||
|
||||

|
||||
|
||||
## Star History
|
||||
|
||||
[](https://star-history.com/#vastsa/FileCodeBox&Date)
|
||||
|
||||
## Appreciate
|
||||
|
||||
<table style="width: 100%">
|
||||
|
||||
+2
-1
@@ -4,4 +4,5 @@ SQLAlchemy==1.4.44
|
||||
python-multipart==0.0.5
|
||||
uvicorn==0.15.0
|
||||
greenlet==2.0.1
|
||||
starlette~=0.22.0
|
||||
starlette~=0.22.0
|
||||
chardet == 5.1.0
|
||||
+8
-1
@@ -1,7 +1,14 @@
|
||||
from starlette.config import Config
|
||||
import os
|
||||
import shutil
|
||||
|
||||
# 配置文件.env
|
||||
# 请将.env移动至data目录,方便docker部署
|
||||
# 判断根目录下是否存在.env文件
|
||||
if os.path.exists('.env'):
|
||||
# 将文件复制到data目录
|
||||
shutil.copy('.env', 'data/.env')
|
||||
|
||||
config = Config("data/.env")
|
||||
# 是否开启DEBUG模式
|
||||
DEBUG = config('DEBUG', cast=bool, default=False)
|
||||
@@ -16,7 +23,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
@@ -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
|
||||
|
||||
+1
-61
@@ -73,58 +73,7 @@
|
||||
</el-pagination>
|
||||
</el-col>
|
||||
<el-col v-if="activeIndex === '3'">
|
||||
<el-form ref="form" style="width: 50%;margin:2rem auto" :model="config" label-width="200px">
|
||||
<!--? <el-form-item label="错误限制">-->
|
||||
<!--? <div>-->
|
||||
<!--? 间隔:-->
|
||||
<!--? <el-input-number v-model="config.error_count" :min="1"></el-input-number>-->
|
||||
<!--? 分钟-->
|
||||
<!--? </div>-->
|
||||
<!--? <div>-->
|
||||
<!--? 数量:-->
|
||||
<!--? <el-input-number v-model="config.error_minute" :min="1"></el-input-number>-->
|
||||
<!--? 个-->
|
||||
<!--? </div>-->
|
||||
<!--? </el-form-item>-->
|
||||
<!--? <el-form-item label="上传限制">-->
|
||||
<!--? <div>-->
|
||||
<!--? 开启上传:-->
|
||||
<!--? <el-switch-->
|
||||
<!--? v-model="config.enable_upload"-->
|
||||
<!--? active-color="#13ce66"-->
|
||||
<!--? inactive-color="#ff4949">-->
|
||||
<!--? </el-switch>-->
|
||||
<!--? </div>-->
|
||||
<!--? <div>-->
|
||||
<!--? 间隔:-->
|
||||
<!--? <el-input-number v-model="config.upload_minute" :min="1"></el-input-number>-->
|
||||
<!--? 分钟-->
|
||||
<!--? </div>-->
|
||||
<!--? <div>-->
|
||||
<!--? 数量:-->
|
||||
<!--? <el-input-number v-model="config.upload_count" :min="1"></el-input-number>-->
|
||||
<!--? 个-->
|
||||
<!--? </div>-->
|
||||
<!--? <div>-->
|
||||
<!--? 最长:-->
|
||||
<!--? <el-input-number v-model="config.max_days" :min="1"></el-input-number>-->
|
||||
<!--? 天-->
|
||||
<!--? </div>-->
|
||||
<!--? <div>-->
|
||||
<!--? 大小:-->
|
||||
<!--? <el-input-number v-model="config.file_size_limit" :min="1"></el-input-number>-->
|
||||
<!--? MB-->
|
||||
<!--? </div>-->
|
||||
<!--? </el-form-item>-->
|
||||
<!--? <el-form-item label="删除间隔">-->
|
||||
<!--? 时长:-->
|
||||
<!--? <el-input-number v-model="config.delete_expire_files_interval"></el-input-number>-->
|
||||
<!--? 分钟-->
|
||||
<!--? </el-form-item>-->
|
||||
<!--? <el-form-item label="管理员密码">-->
|
||||
<!--? <el-input v-model="config.admin_password" type="password"></el-input>-->
|
||||
<!--? </el-form-item>-->
|
||||
<el-form-item v-for="(banner,index) in config.banners" :label="'Banner'+ (index+1)">
|
||||
<el-form ref="form" style="width: 50%;margin:2rem auto" :model="config" label-width="200px"><el-form-item v-for="(banner,index) in config.banners" :label="'Banner'+ (index+1)">
|
||||
<div style="width: 50%;display: inline-block">
|
||||
<el-input v-model="banner.text" placeholder="文本"></el-input>
|
||||
<el-input v-model="banner.url" placeholder="跳转链接"></el-input>
|
||||
@@ -162,15 +111,6 @@
|
||||
pwd: '',
|
||||
activeIndex: '2',
|
||||
config: {
|
||||
// enable_upload: true,
|
||||
// max_days: 7,
|
||||
// error_count: 3,
|
||||
// error_minute: 10,
|
||||
// upload_count: 10,
|
||||
// upload_minute: 10,
|
||||
// delete_expire_files_interval: 10,
|
||||
// admin_password: 'admin',
|
||||
// file_size_limit: 10,
|
||||
banners: []
|
||||
},
|
||||
files: [],
|
||||
|
||||
+109
-58
@@ -11,11 +11,7 @@
|
||||
<meta name="description" content="{{description}}"/>
|
||||
<meta name="keywords" content="{{keywords}}"/>
|
||||
<meta name="generator" content="FileCodeBox"/>
|
||||
<meta name="template" content="Lan-V1.5.8"/>
|
||||
<meta name="description" content="{{description}}"/>
|
||||
<meta name="keywords" content="{{keywords}}"/>
|
||||
<meta name="generator" content="FileCodeBox"/>
|
||||
<meta name="template" content="Lan-V1.5.8"/>
|
||||
<meta name="template" content="Lan-V1.5.9.2"/>
|
||||
<style>
|
||||
body {
|
||||
background: #f5f5f5;
|
||||
@@ -29,6 +25,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 +41,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);
|
||||
}
|
||||
|
||||
#app * {
|
||||
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 +125,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 +204,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,40 +219,39 @@
|
||||
</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">
|
||||
<a style="text-decoration: none;color: #606266" target="_blank" href="https://github.com/vastsa/FileCodeBox">FileCodeBox</a>
|
||||
<a style="text-decoration: none;color: #606266" target="_blank" href="https://github.com/vastsa/FileCodeBox">FileCodeBox
|
||||
V1.5.9.2</a>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
@@ -237,12 +266,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 +316,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 +357,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 +377,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 +393,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 +419,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 +439,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 +449,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);
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user