test/custom-admin-ui #3

Merged
orion merged 673 commits from test/custom-admin-ui into master 2026-06-05 17:20:58 +08:00
4 changed files with 43 additions and 20 deletions
Showing only changes of commit 257cbf6685 - Show all commits
-1
View File
@@ -1,4 +1,3 @@
import asyncio
import datetime
from sqlalchemy import Boolean, Column, Integer, String, DateTime
+6 -11
View File
@@ -30,9 +30,9 @@ app.mount(STATIC_URL, StaticFiles(directory=DATA_ROOT), name="static")
@app.on_event('startup')
async def startup():
await init_models()
asyncio.create_task(delete_expire_files())
index_html = open('templates/index.html', 'r', encoding='utf-8').read() \
.replace('{{title}}', settings.TITLE) \
.replace('{{description}}', settings.DESCRIPTION) \
@@ -57,12 +57,10 @@ async def delete_expire_files():
query = select(Codes).where(or_(Codes.exp_time < datetime.datetime.now(), Codes.count == 0))
exps = (await s.execute(query)).scalars().all()
await asyncio.to_thread(delete_file, [{'type': old.type, 'text': old.text} for old in exps])
exps_ids = [exp.id for exp in exps]
query = delete(Codes).where(Codes.id.in_(exps_ids))
await s.execute(query)
await s.commit()
await asyncio.sleep(random.randint(60, 300))
@@ -73,12 +71,8 @@ async def get_code(s: AsyncSession):
return str(code)
def get_file_name(key, ext, file):
def get_file_name(key, ext, file, file_bytes):
now = datetime.datetime.now()
file_bytes = file.file.read()
size = len(file_bytes)
if size > settings.FILE_SIZE_LIMIT:
return size, '', '', ''
path = DATA_ROOT / f"upload/{now.year}/{now.month}/{now.day}/"
name = f'{key}.{ext}'
if not path.exists():
@@ -86,7 +80,7 @@ def get_file_name(key, ext, file):
filepath = path / name
with open(filepath, 'wb') as f:
f.write(file_bytes)
return size, f"{STATIC_URL}/{filepath.relative_to(DATA_ROOT)}", file.content_type, file.filename
return f"{STATIC_URL}/{filepath.relative_to(DATA_ROOT)}", file.content_type, file.filename
@app.get(f'/{settings.ADMIN_ADDRESS}')
@@ -173,7 +167,6 @@ async def index(request: Request, code: str, s: AsyncSession = Depends(get_sessi
await s.commit()
if info.type != 'text':
info.text = f'/select?code={code}'
return {
'code': 200,
'msg': '取件成功,请点击""查看',
@@ -200,9 +193,11 @@ async def share(text: str = Form(default=None), style: str = Form(default='2'),
exp_count = -1
key = uuid.uuid4().hex
if file:
size, _text, _type, name = get_file_name(key, file.filename.split('.')[-1], file)
file_bytes = file.file.read()
size = len(file_bytes)
if size > settings.FILE_SIZE_LIMIT:
return {'code': 404, 'msg': '文件过大'}
_text, _type, name = get_file_name(key, file.filename.split('.')[-1], file, file_bytes)
else:
size, _text, _type, name = len(text), text, 'text', '文本分享'
info = Codes(
+32 -2
View File
@@ -65,7 +65,33 @@ https://www.yuque.com/lxyo/work/zd0kvzy7fofx6w7v
## 部署方式
先拉取代码,然后修改main.py文件,将里面写了注释的可以根据需求改一下
为持久化,不管怎么样,先第一步,建一个文件夹,然后再下载代码
```bash
mkdir /opt/FileCodeBox
cd /opt/FileCodeBox
```
新建一个`.env`文件
```bash
vi .env
```
将下列字段内容替换成你自己的
```dotenv
DEBUG=False
DATABASE_URL=sqlite+aiosqlite:///database.db
DATA_ROOT=./static
STATIC_URL=/static
ERROR_COUNT=5
ERROR_MINUTE=10
ADMIN_ADDRESS=admin
FILE_SIZE_LIMIT=10
TITLE=文件快递柜
DESCRIPTION=FileCodeBox,文件快递柜,口令传送箱,匿名口令分享文本,文件,图片,视频,音频,压缩包等文件
KEYWORDS=FileCodeBox,文件快递柜,口令传送箱,匿名口令分享文本,文件,图片,视频,音频,压缩包等文件
```
### 服务端部署
@@ -83,8 +109,12 @@ https://www.yuque.com/lxyo/work/zd0kvzy7fofx6w7v
### 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 filecodebox
docker run -d -p 12345:12345 --name filecodebox --volume /opt/FileCodeBox:/app filecodebox
```
## 状态
+3 -4
View File
@@ -1,6 +1,5 @@
from starlette.config import Config
config = Config(".env")
DEBUG = config('DEBUG', cast=bool, default=False)
@@ -19,10 +18,10 @@ ADMIN_ADDRESS = config('ADMIN_ADDRESS', cast=str, default="admin")
ADMIN_PASSWORD = config('ADMIN_ADDRESS', cast=str, default="admin")
FILE_SIZE_LIMIT = config('FILE_SIZE_LIMIT', cast=int, default=1024 * 1024 * 10)
FILE_SIZE_LIMIT = config('FILE_SIZE_LIMIT', cast=int, default=10) * 1024 * 1024
TITLE = config('TITLE', cast=str, default="文件快递柜")
DESCRIPTION = config('DESCRIPTION', cast=str, default="FileCodeBox,文件快递柜,口令传送箱,匿名口令分享文本,文件,图片,视频,音频,压缩包等文件")
DESCRIPTION = config('DESCRIPTION', cast=str, default="FileCodeBox,文件快递柜,口令传送箱,匿名口令分享文本,文件等文件")
KEYWORDS = config('TITLE', cast=str, default="FileCodeBox,文件快递柜,口令传送箱,匿名口令分享文本,文件,图片,视频,音频,压缩包等文件")
KEYWORDS = config('KEYWORDS', cast=str, default="FileCodeBox,文件快递柜,口令传送箱,匿名口令分享文本,文件等文件")