Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4c507fc3cb | ||
|
|
fce5194e04 | ||
|
|
517b7b8a3a | ||
|
|
8b952eddbf | ||
|
|
75a94311e4 | ||
|
|
ce828ebb89 | ||
|
|
e593fd8d51 | ||
|
|
3b44b2273c | ||
|
|
a21c3a1f6e | ||
|
|
de1096acc4 | ||
|
|
3864335fca | ||
|
|
8f3fa8af74 | ||
|
|
7ed8b68ee8 | ||
|
|
b6c0bc04fa | ||
|
|
ef4175f191 | ||
|
|
a8052c647d | ||
|
|
68dd33043e | ||
|
|
511bfa1632 | ||
|
|
f87d61b793 | ||
|
|
1fb758a201 | ||
|
|
9473cb35af | ||
|
|
ef2a6551b9 | ||
|
|
ee5beb2261 | ||
|
|
c19da62941 | ||
|
|
487895af7e | ||
|
|
1b26b03758 | ||
|
|
cfa865c6cd | ||
|
|
fb932f08e4 | ||
|
|
8f404fbfed | ||
|
|
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 | ||
|
|
f80d50981c | ||
|
|
dfb7367100 | ||
|
|
d764cb48e3 | ||
|
|
14b6f0e9a7 | ||
|
|
f01d39c1c9 | ||
|
|
59805273bf |
No files matched your search
@@ -0,0 +1,4 @@
|
||||
# These are supported funding model platforms
|
||||
|
||||
github: [ vastsa ]
|
||||
custom: [ https://share.lanol.cn ]
|
||||
@@ -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="6"
|
||||
|
||||
|
||||
COPY . /app
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
import datetime
|
||||
|
||||
from sqlalchemy import Boolean, Column, Integer, String, DateTime, JSON, Text, select, insert, delete
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
from sqlalchemy.ext.asyncio import create_async_engine
|
||||
from sqlalchemy.ext.asyncio.session import AsyncSession
|
||||
|
||||
from settings import settings
|
||||
|
||||
engine = create_async_engine(settings.DATABASE_URL)
|
||||
Base = declarative_base()
|
||||
|
||||
|
||||
class Options(Base):
|
||||
__tablename__ = 'options'
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
key = Column(String, unique=True, index=True)
|
||||
value = Column(JSON)
|
||||
|
||||
|
||||
class Codes(Base):
|
||||
__tablename__ = "codes"
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
code = Column(String(10), unique=True, index=True)
|
||||
key = Column(String(30), unique=True)
|
||||
name = Column(String(500))
|
||||
size = Column(Integer)
|
||||
type = Column(String(20))
|
||||
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)
|
||||
exp_time = Column(DateTime, nullable=True)
|
||||
|
||||
|
||||
async def init_models(s):
|
||||
async with engine.begin() as conn:
|
||||
await conn.run_sync(Base.metadata.create_all)
|
||||
if await conn.scalar(select(Options).filter(Options.key == 'INSTALL')) is None:
|
||||
# 如果没有存在install,则清空表,并插入默认数据
|
||||
await conn.execute(delete(table=Options))
|
||||
await conn.execute(insert(table=Options, values=[
|
||||
{'key': 'INSTALL', 'value': settings.VERSION},
|
||||
{'key': 'DEBUG', 'value': settings.DEBUG},
|
||||
{'key': 'DATABASE_FILE', 'value': settings.DATABASE_FILE},
|
||||
{'key': 'PORT', 'value': settings.PORT},
|
||||
{'key': 'DATA_ROOT', 'value': settings.DATA_ROOT},
|
||||
{'key': 'LOCAL_ROOT', 'value': settings.LOCAL_ROOT},
|
||||
{'key': 'STATIC_URL', 'value': settings.STATIC_URL},
|
||||
{'key': 'BANNERS', 'value': settings.BANNERS},
|
||||
{'key': 'ENABLE_UPLOAD', 'value': settings.ENABLE_UPLOAD},
|
||||
{'key': 'MAX_DAYS', 'value': settings.MAX_DAYS},
|
||||
{'key': 'ERROR_COUNT', 'value': settings.ERROR_COUNT},
|
||||
{'key': 'ERROR_MINUTE', 'value': settings.ERROR_COUNT},
|
||||
{'key': 'UPLOAD_COUNT', 'value': settings.UPLOAD_COUNT},
|
||||
{'key': 'UPLOAD_MINUTE', 'value': settings.UPLOAD_MINUTE},
|
||||
{'key': 'DELETE_EXPIRE_FILES_INTERVAL', 'value': settings.DELETE_EXPIRE_FILES_INTERVAL},
|
||||
{'key': 'ADMIN_ADDRESS', 'value': settings.ADMIN_ADDRESS},
|
||||
{'key': 'ADMIN_PASSWORD', 'value': settings.ADMIN_PASSWORD},
|
||||
{'key': 'FILE_SIZE_LIMIT', 'value': settings.FILE_SIZE_LIMIT},
|
||||
{'key': 'TITLE', 'value': settings.TITLE},
|
||||
{'key': 'DESCRIPTION', 'value': settings.DESCRIPTION},
|
||||
{'key': 'KEYWORDS', 'value': settings.KEYWORDS},
|
||||
{'key': 'STORAGE_ENGINE', 'value': settings.STORAGE_ENGINE},
|
||||
{'key': 'STORAGE_CONFIG', 'value': {}},
|
||||
]))
|
||||
print(
|
||||
f'初始化数据库成功!\n'
|
||||
f'如您未配置.env文件,将为您随机生成信息\n'
|
||||
f'您的后台地址为:/{settings.ADMIN_ADDRESS}\n'
|
||||
f'您的管理员密码为:{settings.ADMIN_PASSWORD}\n'
|
||||
f'请尽快修改后台信息!\n'
|
||||
f'FileCodeBox https://github.com/vastsa/FileCodeBox'
|
||||
)
|
||||
await settings.updates(await conn.execute(select(Options).filter()))
|
||||
|
||||
|
||||
async def get_config(key):
|
||||
async with engine.begin() as conn:
|
||||
return await conn.scalar(select(Options.value).filter(Options.key == key))
|
||||
|
||||
|
||||
async def get_session():
|
||||
async with AsyncSession(engine, expire_on_commit=False) as s:
|
||||
yield s
|
||||
@@ -3,7 +3,7 @@ from datetime import datetime, timedelta
|
||||
|
||||
from fastapi import Header, HTTPException, Request
|
||||
|
||||
import settings
|
||||
from settings import settings
|
||||
|
||||
|
||||
async def admin_required(pwd: Union[str, None] = Header(default=None), request: Request = None):
|
||||
@@ -11,16 +11,15 @@ async def admin_required(pwd: Union[str, None] = Header(default=None), request:
|
||||
if pwd != settings.ADMIN_PASSWORD and not settings.ENABLE_UPLOAD:
|
||||
raise HTTPException(status_code=403, detail='本站上传功能已关闭,仅管理员可用')
|
||||
else:
|
||||
if settings.ADMIN_PASSWORD is None:
|
||||
raise HTTPException(status_code=404, detail='您未设置管理员密码,无法使用此功能,请更新配置文件后,重启系统')
|
||||
if not pwd or pwd != settings.ADMIN_PASSWORD:
|
||||
raise HTTPException(status_code=401, detail="密码错误,请重新登录")
|
||||
|
||||
|
||||
class IPRateLimit:
|
||||
ips = {}
|
||||
count = 0
|
||||
minutes = 0
|
||||
|
||||
def __init__(self, count, minutes):
|
||||
self.ips = {}
|
||||
self.count = count
|
||||
self.minutes = minutes
|
||||
|
||||
@@ -37,6 +36,7 @@ class IPRateLimit:
|
||||
def add_ip(self, ip):
|
||||
ip_info = self.ips.get(ip, {'count': 0, 'time': datetime.now()})
|
||||
ip_info['count'] += 1
|
||||
ip_info['time'] = datetime.now()
|
||||
self.ips[ip] = ip_info
|
||||
return ip_info['count']
|
||||
|
||||
@@ -0,0 +1,140 @@
|
||||
import os
|
||||
import asyncio
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
from typing import BinaryIO
|
||||
from fastapi import UploadFile
|
||||
|
||||
from core.database import Codes
|
||||
from settings import settings
|
||||
|
||||
if settings.STORAGE_ENGINE == 'aliyunsystem':
|
||||
try:
|
||||
import oss2
|
||||
except ImportError:
|
||||
os.system('pip install oss2')
|
||||
import oss2
|
||||
|
||||
|
||||
class AliyunFileStorage:
|
||||
def __init__(self):
|
||||
auth = oss2.Auth(settings.KeyId, settings.KeySecret)
|
||||
self.bucket = oss2.Bucket(auth, settings.OSS_ENDPOINT, settings.BUCKET_NAME)
|
||||
|
||||
def upload_file(self, upload_filepath, remote_filepath):
|
||||
self.bucket.put_object_from_file(remote_filepath, upload_filepath)
|
||||
|
||||
async def get_text(self, file: UploadFile, key: str):
|
||||
ext = file.filename.split('.')[-1]
|
||||
now = datetime.now()
|
||||
path = f"FileCodeBox/upload/{now.year}/{now.month}/{now.day}"
|
||||
text = f"{path}/{f'{key}.{ext}'}"
|
||||
return f"https://{settings.BUCKET_NAME}.{settings.OSS_ENDPOINT}/{text}"
|
||||
|
||||
async def get_url(self, info: Codes):
|
||||
text = info.text.strip(f"https://{settings.BUCKET_NAME}.{settings.OSS_ENDPOINT}/")
|
||||
url = self.bucket.sign_url('GET', text, settings.ACCESSTIME, slash_safe=True)
|
||||
return url
|
||||
|
||||
@staticmethod
|
||||
async def get_size(file: UploadFile):
|
||||
f = file.file
|
||||
f.seek(0, os.SEEK_END)
|
||||
size = f.tell()
|
||||
f.seek(0, os.SEEK_SET)
|
||||
return size
|
||||
|
||||
@staticmethod
|
||||
def _save(filepath, file: BinaryIO):
|
||||
with open(filepath, 'wb') as f:
|
||||
chunk_size = 256 * 1024
|
||||
chunk = file.read(chunk_size)
|
||||
while chunk:
|
||||
f.write(chunk)
|
||||
chunk = file.read(chunk_size)
|
||||
|
||||
async def save_file(self, file: UploadFile, remote_filepath: str):
|
||||
now = int(datetime.now().timestamp())
|
||||
upload_filepath = settings.DATA_ROOT + str(now)
|
||||
await asyncio.to_thread(self._save, upload_filepath, file.file)
|
||||
self.upload_file(upload_filepath, remote_filepath)
|
||||
remote_filepath = remote_filepath.strip(f"https://{settings.BUCKET_NAME}.{settings.OSS_ENDPOINT}/")
|
||||
self.upload_file(upload_filepath, remote_filepath)
|
||||
await asyncio.to_thread(os.remove, upload_filepath)
|
||||
|
||||
async def delete_files(self, texts):
|
||||
tasks = [self.delete_file(text) for text in texts]
|
||||
await asyncio.gather(*tasks)
|
||||
|
||||
async def delete_file(self, text: str):
|
||||
text = text.strip(f"https://{settings.BUCKET_NAME}.{settings.OSS_ENDPOINT}/")
|
||||
self.bucket.delete_object(text)
|
||||
|
||||
|
||||
class FileSystemStorage:
|
||||
def __init__(self):
|
||||
self.DATA_ROOT = Path(settings.DATA_ROOT)
|
||||
self.STATIC_URL = settings.STATIC_URL
|
||||
self.NAME = "filesystem"
|
||||
self.DOWN_PATH = '/select'
|
||||
|
||||
async def get_filepath(self, text: str):
|
||||
return self.DATA_ROOT / text.lstrip(self.STATIC_URL + '/')
|
||||
|
||||
async def get_url(self, info: Codes):
|
||||
return f'{self.DOWN_PATH}?code={info.code}'
|
||||
|
||||
async def get_text(self, file: UploadFile, key: str):
|
||||
ext = file.filename.split('.')[-1]
|
||||
now = datetime.now()
|
||||
path = self.DATA_ROOT / f"upload/{now.year}/{now.month}/{now.day}/"
|
||||
if not path.exists():
|
||||
path.mkdir(parents=True)
|
||||
text = f"{self.STATIC_URL}/{(path / f'{key}.{ext}').relative_to(self.DATA_ROOT)}"
|
||||
return text
|
||||
|
||||
@staticmethod
|
||||
async def get_size(file: UploadFile):
|
||||
f = file.file
|
||||
f.seek(0, os.SEEK_END)
|
||||
size = f.tell()
|
||||
f.seek(0, os.SEEK_SET)
|
||||
return size
|
||||
|
||||
@staticmethod
|
||||
def _save(filepath, file: BinaryIO):
|
||||
with open(filepath, 'wb') as f:
|
||||
chunk_size = 256 * 1024
|
||||
chunk = file.read(chunk_size)
|
||||
while chunk:
|
||||
f.write(chunk)
|
||||
chunk = file.read(chunk_size)
|
||||
|
||||
async def save_file(self, file: UploadFile, text: str):
|
||||
filepath = await self.get_filepath(text)
|
||||
await asyncio.to_thread(self._save, filepath, file.file)
|
||||
|
||||
async def delete_file(self, text: str):
|
||||
filepath = await self.get_filepath(text)
|
||||
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,
|
||||
"aliyunsystem": AliyunFileStorage
|
||||
}
|
||||
@@ -3,10 +3,10 @@ import random
|
||||
import asyncio
|
||||
from sqlalchemy import or_, select, delete
|
||||
from sqlalchemy.ext.asyncio.session import AsyncSession
|
||||
import settings
|
||||
from database import Codes, engine
|
||||
from depends import IPRateLimit
|
||||
from storage import STORAGE_ENGINE
|
||||
from .database import Codes, engine
|
||||
from .depends import IPRateLimit
|
||||
from .storage import STORAGE_ENGINE
|
||||
from settings import settings
|
||||
|
||||
storage = STORAGE_ENGINE[settings.STORAGE_ENGINE]()
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
import datetime
|
||||
from sqlalchemy import Boolean, Column, Integer, String, DateTime, JSON
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
from sqlalchemy.ext.asyncio import create_async_engine
|
||||
from sqlalchemy.ext.asyncio.session import AsyncSession
|
||||
import settings
|
||||
|
||||
engine = create_async_engine(settings.DATABASE_URL)
|
||||
|
||||
Base = declarative_base()
|
||||
|
||||
|
||||
async def init_models():
|
||||
async with engine.begin() as conn:
|
||||
await conn.run_sync(Base.metadata.create_all)
|
||||
|
||||
|
||||
async def get_session():
|
||||
async with AsyncSession(engine, expire_on_commit=False) as s:
|
||||
yield s
|
||||
|
||||
|
||||
class Values(Base):
|
||||
__tablename__ = 'values'
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
key = Column(String, unique=True)
|
||||
value = Column(JSON)
|
||||
|
||||
|
||||
class Codes(Base):
|
||||
__tablename__ = "codes"
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
code = Column(String(10), unique=True, index=True)
|
||||
key = Column(String(30), unique=True, index=True)
|
||||
name = Column(String(500))
|
||||
size = Column(Integer)
|
||||
type = Column(String(20))
|
||||
text = Column(String(500))
|
||||
used = Column(Boolean, default=False)
|
||||
count = Column(Integer, default=-1)
|
||||
use_time = Column(DateTime, default=datetime.datetime.now, onupdate=datetime.datetime.now)
|
||||
exp_time = Column(DateTime, nullable=True)
|
||||
@@ -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. 完善配置参数
|
||||
|
After Width: | Height: | Size: 33 KiB |
|
After Width: | Height: | Size: 57 KiB |
|
After Width: | Height: | Size: 31 KiB |
|
After Width: | Height: | Size: 79 KiB |
|
Before Width: | Height: | Size: 174 KiB After Width: | Height: | Size: 56 KiB |
@@ -1,81 +1,118 @@
|
||||
import asyncio
|
||||
import datetime
|
||||
import uuid
|
||||
import asyncio
|
||||
from pathlib import Path
|
||||
|
||||
from fastapi import FastAPI, Depends, UploadFile, Form, File, HTTPException, BackgroundTasks
|
||||
from sqlalchemy import select, func, update
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
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
|
||||
from database import get_session, Codes, init_models, Values
|
||||
from depends import admin_required
|
||||
import os
|
||||
import shutil
|
||||
from core.utils import error_ip_limit, upload_ip_limit, get_code, storage, delete_expire_files
|
||||
from core.depends import admin_required
|
||||
from fastapi import FastAPI, Depends, UploadFile, Form, File, HTTPException, BackgroundTasks
|
||||
from core.database import init_models, Options, Codes, get_session
|
||||
from settings import settings
|
||||
|
||||
# 实例化FastAPI
|
||||
app = FastAPI(debug=settings.DEBUG, docs_url=None, redoc_url=None)
|
||||
app = FastAPI(debug=settings.DEBUG, redoc_url=None, docs_url=None, openapi_url=None)
|
||||
|
||||
|
||||
@app.on_event('startup')
|
||||
async def startup(s: AsyncSession = Depends(get_session)):
|
||||
# 初始化数据库
|
||||
await init_models(s)
|
||||
# 启动后台任务,不定时删除过期文件
|
||||
asyncio.create_task(delete_expire_files())
|
||||
|
||||
|
||||
# 数据存储文件夹
|
||||
DATA_ROOT = Path(settings.DATA_ROOT)
|
||||
if not DATA_ROOT.exists():
|
||||
DATA_ROOT.mkdir(parents=True)
|
||||
# 本地文件文件夹
|
||||
LOCAL_ROOT = Path(settings.LOCAL_ROOT)
|
||||
if not LOCAL_ROOT.exists():
|
||||
LOCAL_ROOT.mkdir(parents=True)
|
||||
|
||||
# 静态文件夹,这个固定就行了,静态资源都放在这里
|
||||
app.mount(settings.STATIC_URL, StaticFiles(directory='./static'), name="static")
|
||||
|
||||
|
||||
@app.on_event('startup')
|
||||
async def startup():
|
||||
# 初始化数据库
|
||||
await init_models()
|
||||
# 启动后台任务,不定时删除过期文件
|
||||
asyncio.create_task(delete_expire_files())
|
||||
|
||||
app.mount('/static', StaticFiles(directory='./static'), name="static")
|
||||
|
||||
# 首页页面
|
||||
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))
|
||||
index_html = open('templates/index.html', 'r', encoding='utf-8').read()
|
||||
# 管理页面
|
||||
admin_html = open('templates/admin.html', 'r', encoding='utf-8').read() \
|
||||
.replace('{{title}}', settings.TITLE) \
|
||||
.replace('{{description}}', settings.DESCRIPTION) \
|
||||
.replace('{{keywords}}', settings.KEYWORDS)
|
||||
admin_html = open('templates/admin.html', 'r', encoding='utf-8').read()
|
||||
|
||||
|
||||
@app.get('/')
|
||||
async def index():
|
||||
return HTMLResponse(
|
||||
index_html.replace('{{title}}', settings.TITLE).replace('{{description}}', settings.DESCRIPTION).replace(
|
||||
'{{keywords}}', settings.KEYWORDS).replace("'{{fileSizeLimit}}'", str(settings.FILE_SIZE_LIMIT))
|
||||
)
|
||||
|
||||
|
||||
@app.get(f'/{settings.ADMIN_ADDRESS}', description='管理页面')
|
||||
async def admin():
|
||||
return HTMLResponse(admin_html)
|
||||
return HTMLResponse(
|
||||
admin_html.replace('{{title}}', settings.TITLE).replace('{{description}}', settings.DESCRIPTION).replace(
|
||||
'{{admin_address}}', settings.ADMIN_ADDRESS).replace('{{keywords}}', settings.KEYWORDS)
|
||||
)
|
||||
|
||||
|
||||
@app.get(f'/{settings.ADMIN_ADDRESS}/files', dependencies=[Depends(admin_required)])
|
||||
async def get_files():
|
||||
files = []
|
||||
for i, j, k in os.walk(f'{LOCAL_ROOT}'):
|
||||
files.extend([{'name': _.split('/')[-1], 'path': i} for _ in k])
|
||||
return {'data': files}
|
||||
|
||||
|
||||
@app.post(f'/{settings.ADMIN_ADDRESS}/files', dependencies=[Depends(admin_required)])
|
||||
async def share_file(name=Form(...), path=File(...), s: AsyncSession = Depends(get_session)):
|
||||
file_path = path + f'/{name}'
|
||||
key = uuid.uuid4().hex
|
||||
code = await get_code(s)
|
||||
now = datetime.datetime.now()
|
||||
path = f"{settings.LOCAL_ROOT}/upload/{now.year}/{now.month}/{now.day}/"
|
||||
if not os.path.exists(path):
|
||||
os.makedirs(path)
|
||||
text = f"{path}/{f'{key}{name}'}"
|
||||
exp_time = datetime.datetime.now() + datetime.timedelta(days=1)
|
||||
s.add(Codes(code=code, text=text.replace(f'{settings.LOCAL_ROOT}/', ''), type='file', name=name, count=-1,
|
||||
exp_time=exp_time, key=key))
|
||||
await s.commit()
|
||||
shutil.move(file_path, text)
|
||||
return {
|
||||
'detail': '分享成功!请在24小时内使用分享使用!',
|
||||
'data': {
|
||||
'code': code,
|
||||
'text': text,
|
||||
'name': name,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@app.post(f'/{settings.ADMIN_ADDRESS}', dependencies=[Depends(admin_required)], description='查询数据库列表')
|
||||
async def admin_post(page: int = Form(default=1), size: int = Form(default=10), s: AsyncSession = Depends(get_session)):
|
||||
codes = (await s.execute(select(Codes).offset((page - 1) * size).limit(size))).scalars().all()
|
||||
total = (await s.execute(select(func.count(Codes.id)))).scalar()
|
||||
return {'detail': '查询成功', 'data': codes, 'paginate': {
|
||||
'page': page,
|
||||
'size': size,
|
||||
'total': total
|
||||
}}
|
||||
|
||||
|
||||
@app.patch(f'/{settings.ADMIN_ADDRESS}', dependencies=[Depends(admin_required)], description='修改数据库数据')
|
||||
async def admin_patch(request: Request, s: AsyncSession = Depends(get_session)):
|
||||
# 从数据库获取系统配置
|
||||
# 如果不存在config这个key,就创建一个
|
||||
config = (await s.execute(select(Values).filter(Values.key == 'config'))).scalar_one_or_none()
|
||||
if not config:
|
||||
s.add(Values(key='config', value=await request.json()))
|
||||
else:
|
||||
await s.execute(update(Values).where(Values.key == 'config').values(value=await request.json()))
|
||||
await s.commit()
|
||||
return {'detail': '修改成功'}
|
||||
infos = (await s.execute(select(Codes).offset((page - 1) * size).limit(size))).scalars().all()
|
||||
data = [{
|
||||
'id': info.id,
|
||||
'code': info.code,
|
||||
'name': info.name,
|
||||
'exp_time': info.exp_time,
|
||||
'count': info.count,
|
||||
'text': info.text if info.type == 'text' else await storage.get_url(info),
|
||||
} for info in infos]
|
||||
return {
|
||||
'detail': '查询成功',
|
||||
'data': data,
|
||||
'paginate': {
|
||||
'page': page,
|
||||
'size': size,
|
||||
'total': (await s.execute(select(func.count(Codes.id)))).scalar()
|
||||
}}
|
||||
|
||||
|
||||
@app.delete(f'/{settings.ADMIN_ADDRESS}', dependencies=[Depends(admin_required)], description='删除数据库记录')
|
||||
@@ -94,40 +131,58 @@ async def admin_delete(code: str, s: AsyncSession = Depends(get_session)):
|
||||
return {'detail': '删除成功'}
|
||||
|
||||
|
||||
@app.get('/config', description='获取系统配置', dependencies=[Depends(admin_required)])
|
||||
@app.get(f'/{settings.ADMIN_ADDRESS}/config', description='获取系统配置', dependencies=[Depends(admin_required)])
|
||||
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}
|
||||
# 查询数据库
|
||||
data = {}
|
||||
for i in (await s.execute(select(Options))).scalars().all():
|
||||
data[i.key] = i.value
|
||||
return {'detail': '获取成功', 'data': data, 'menus': [
|
||||
{'key': 'INSTALL', 'name': '版本信息'},
|
||||
{'key': 'WEBSITE', 'name': '网站设置'},
|
||||
{'key': 'SHARE', 'name': '分享设置'},
|
||||
{'key': 'BANNERS', 'name': 'Banner'},
|
||||
]}
|
||||
|
||||
|
||||
@app.get('/')
|
||||
async def index():
|
||||
return HTMLResponse(index_html)
|
||||
@app.patch(f'/{settings.ADMIN_ADDRESS}', dependencies=[Depends(admin_required)], description='修改数据库数据')
|
||||
async def admin_patch(request: Request, s: AsyncSession = Depends(get_session)):
|
||||
data = await request.json()
|
||||
data.pop('INSTALL')
|
||||
for key, value in data.items():
|
||||
await s.execute(update(Options).where(Options.key == key).values(value=value))
|
||||
await settings.update(key, value)
|
||||
await s.commit()
|
||||
await settings.updates([[i.id, i.key, i.value] for i in (await s.execute(select(Options))).scalars().all()])
|
||||
return {'detail': '修改成功'}
|
||||
|
||||
|
||||
@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 = await storage.get_url(info)
|
||||
return {
|
||||
'detail': f'取件成功,请立即下载,避免失效!',
|
||||
'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):
|
||||
# 数据库查询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']
|
||||
}
|
||||
# 如果不存在config,就返回默认的banner
|
||||
return {
|
||||
'detail': 'banner',
|
||||
'data': [{
|
||||
'text': 'FileCodeBox',
|
||||
'url': 'https://github.com/vastsa/FileCodeBox',
|
||||
'src': '/static/banners/img_1.png'
|
||||
}, {
|
||||
'text': 'FileCodeBox',
|
||||
'url': 'https://www.lanol.cn',
|
||||
'src': '/static/banners/img_2.png'
|
||||
}]
|
||||
'detail': '查询成功',
|
||||
'data': settings.BANNERS,
|
||||
'enable': request.headers.get('pwd', '') == settings.ADMIN_PASSWORD or settings.ENABLE_UPLOAD,
|
||||
}
|
||||
|
||||
|
||||
@@ -149,25 +204,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),
|
||||
@@ -195,13 +231,12 @@ async def share(background_tasks: BackgroundTasks, text: str = Form(default=None
|
||||
background_tasks.add_task(storage.save_file, file, _text)
|
||||
else:
|
||||
size, _text, _type, name = len(text), text, 'text', '文本分享'
|
||||
info = Codes(code=code, text=_text, size=size, type=_type, name=name, count=exp_count, exp_time=exp_time, key=key)
|
||||
s.add(info)
|
||||
s.add(Codes(code=code, text=_text, size=size, type=_type, name=name, count=exp_count, exp_time=exp_time, key=key))
|
||||
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,9 +1,11 @@
|
||||
<div style="text-align: center">
|
||||
<div align="center">
|
||||
<h1>文件快递柜-轻量</h1>
|
||||
<h2>FileCoxBox-Lite</h2>
|
||||
<h2>FileCodeBox-Lite</h2>
|
||||
<p><em>匿名口令分享文本,文件,像拿快递一样取文件</em></p>
|
||||
</div>
|
||||
|
||||

|
||||
|
||||
---
|
||||
|
||||
[简体中文](./readme.md) | [English](./readme_en.md)
|
||||
@@ -19,19 +21,54 @@
|
||||
- [x] 匿名分享:无需注册,无需登录
|
||||
- [x] 管理面板:查看所有文件,删除文件
|
||||
- [x] 一键部署:docker一键部署
|
||||
- [x] 多种存储方式:阿里云OSS、本地文件流
|
||||
|
||||
## 未来规划
|
||||
## 部署方式
|
||||
|
||||
### 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
|
||||
```
|
||||
|
||||
### 1.6版本注意
|
||||
|
||||
这一版改变比较大,如果出现问题可以尝试清空/opt/FileCodeBox目录,有问题欢迎反馈留言
|
||||
注意,如果是第一次安装,请查看docker日志获取初始密码和后台地址,参考指令
|
||||
后台本地文件列表,需要将服务器文件移动至目录/opt/FileCodeBox/data/locals,这样就可以显示了。
|
||||
|
||||
```bash
|
||||
docker logs filecodebox
|
||||
|
||||
```
|
||||
|
||||
### 其他方式
|
||||
|
||||
仅供参考,历史版本->[部署文档](https://www.yuque.com/lxyo/work/zd0kvzy7fofx6w7v)
|
||||
|
||||
## 项目规划
|
||||
|
||||
2022年12月14日
|
||||
|
||||
这个项目的灵感来源于丁丁快传,然后写了这么一个基于本机存储的快传系统,本系统主要是以轻量,单用户,离线环境(`私有化`
|
||||
)为主,因此也不需要加太多东西,所以其实这个项目到这基本功能已经完成了,剩下的就是维护和完善现有功能。
|
||||
|
||||
也不会再加入新的大功能了,如果有新的功能的话,那就是我们的Pro版本了,当然也是继续开源的,能和@veoco一起开源挺荣幸的,在他的代码中我学到了许多,此前我基本上是使用Django那一套,对Fastapi仅限于使用,他的许多写法让我受益匪浅,也让我对Fastapi有了更深的了解,所以我也会在Pro版本中使用Fastapi。
|
||||
|
||||
根据目前一些使用反馈来说,希望加入登录功能,还有多存储引擎等,欢迎各位继续提意见,加入我们共同开发。
|
||||
|
||||
如果你有更好的想法和建议欢迎提issue。
|
||||
也不会再加入新的大功能了,如果你有更好的想法和建议欢迎提issue。
|
||||
|
||||
## 预览
|
||||
|
||||
@@ -39,20 +76,36 @@
|
||||
|
||||
[https://share.lanol.cn](https://share.lanol.cn)
|
||||
|
||||
### 暗黑模式
|
||||
|
||||
<table style="width:100%">
|
||||
|
||||
<tr style="width: 100%">
|
||||
<td style="width: 50%">
|
||||
<img src="https://fastly.jsdelivr.net/gh/vastsa/FileCodeBox@V1.6/images/img_10.png" alt="寄文件">
|
||||
|
||||
</td>
|
||||
<td style="width: 50%">
|
||||
<img src="https://fastly.jsdelivr.net/gh/vastsa/FileCodeBox@V1.6/images/img_11.png" alt="寄文件">
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
### 寄件
|
||||
|
||||
<table style="width: 100%">
|
||||
<tr style="width: 100%">
|
||||
<td style="width: 50%">
|
||||
<img src="https://raw.githubusercontent.com/vastsa/FileCodeBox/master/images/img_1.png" alt="寄文件">
|
||||
<img src="https://fastly.jsdelivr.net/gh/vastsa/FileCodeBox@V1.6/images/img_1.png" alt="寄文件">
|
||||
</td>
|
||||
<td style="width: 50%">
|
||||
<img src="https://raw.githubusercontent.com/vastsa/FileCodeBox/master/images/img_2.png" alt="寄文本">
|
||||
<img src="https://fastly.jsdelivr.net/gh/vastsa/FileCodeBox@V1.6/images/img_2.png" alt="寄文本">
|
||||
</td>
|
||||
</tr>
|
||||
<tr style="width: 100%;">
|
||||
<td colspan="2" style="width: 100%;">
|
||||
<img src="https://raw.githubusercontent.com/vastsa/FileCodeBox/master/images/img_3.png" alt="寄文本">
|
||||
<img src="https://fastly.jsdelivr.net/gh/vastsa/FileCodeBox@V1.6/images/img_3.png" alt="寄文本">
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
@@ -62,34 +115,36 @@
|
||||
<table style="width: 100%">
|
||||
<tr style="width: 100%">
|
||||
<td style="width: 50%">
|
||||
<img src="https://raw.githubusercontent.com/vastsa/FileCodeBox/master/images/img_6.png" alt="取件">
|
||||
<img src="https://fastly.jsdelivr.net/gh/vastsa/FileCodeBox@V1.6/images/img_6.png" alt="取件">
|
||||
</td>
|
||||
<td style="width: 50%">
|
||||
<img src="https://raw.githubusercontent.com/vastsa/FileCodeBox/master/images/img_5.png" alt="取件码错误">
|
||||
<img src="https://fastly.jsdelivr.net/gh/vastsa/FileCodeBox@V1.6/images/img_5.png" alt="取件码错误">
|
||||
</td>
|
||||
</tr>
|
||||
<tr style="width: 100%;">
|
||||
<td colspan="2" style="width: 100%;">
|
||||
<img src="https://raw.githubusercontent.com/vastsa/FileCodeBox/master/images/img_4.png" alt="取文件">
|
||||
<img src="https://fastly.jsdelivr.net/gh/vastsa/FileCodeBox@V1.6/images/img_4.png" alt="取文件">
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
### 管理
|
||||
|
||||

|
||||
|
||||
## 部署方式
|
||||
|
||||
### 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)
|
||||
<table style="width: 100%">
|
||||
<tr style="width: 100%">
|
||||
<td style="width: 50%">
|
||||
<img src="https://fastly.jsdelivr.net/gh/vastsa/FileCodeBox@V1.6/images/img_7.png" alt="admin">
|
||||
</td>
|
||||
<td style="width: 50%">
|
||||
<img src="https://fastly.jsdelivr.net/gh/vastsa/FileCodeBox@V1.6/images/img_12.png" alt="admin">
|
||||
</td>
|
||||
</tr>
|
||||
<tr style="width: 100%;">
|
||||
<td colspan="2" style="width: 100%;">
|
||||
<img src="https://fastly.jsdelivr.net/gh/vastsa/FileCodeBox@V1.6/images/img_13.png" alt="admin">
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
## 配置文件
|
||||
|
||||
@@ -131,27 +186,110 @@ DESCRIPTION=FileCodeBox,文件快递柜,口令传送箱,匿名口令分享
|
||||
KEYWORDS=FileCodeBox,文件快递柜,口令传送箱,匿名口令分享文本,文件,图片,视频,音频,压缩包等文件
|
||||
# 存储引擎
|
||||
STORAGE_ENGINE=filesystem
|
||||
# 如果使用阿里云OSS服务的话需要额外创建如下参数:
|
||||
# 阿里云账号AccessKey
|
||||
KeyId=阿里云账号AccessKey
|
||||
# 阿里云账号AccessKeySecret
|
||||
KeySecret=阿里云账号AccessKeySecret
|
||||
# 阿里云OSS Bucket的地域节点
|
||||
OSS_ENDPOINT=阿里云OSS Bucket的地域节点
|
||||
# 阿里云OSS Bucket的BucketName
|
||||
BUCKET_NAME=阿里云OSS Bucket的BucketName
|
||||
```
|
||||
|
||||
## 接口文档
|
||||
|
||||
前端比较简陋,可以使用接口进行二次开发
|
||||
|
||||
### 取件
|
||||
|
||||
#### 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%">
|
||||
<tr style="width: 100%">
|
||||
<td style="width: 50%;text-align: center;">
|
||||
支付宝
|
||||
<img src="https://raw.githubusercontent.com/vastsa/FileCodeBox/master/images/img_9.png" alt="支付宝">
|
||||
<img src="https://fastly.jsdelivr.net/gh/vastsa/FileCodeBox@V1.6/images/img_9.png" alt="支付宝">
|
||||
</td>
|
||||
<td style="width: 50%;text-align: center">
|
||||
微信
|
||||
<img src="https://raw.githubusercontent.com/vastsa/FileCodeBox/master/images/img_8.png" alt="微信">
|
||||
<img src="https://fastly.jsdelivr.net/gh/vastsa/FileCodeBox@V1.6/images/img_8.png" alt="微信">
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
## 常见问题
|
||||
|
||||
1. 413 Request Entity Too Large
|
||||
Nginx限制:
|
||||
找到自己主机的nginx.conf配置文件,打开
|
||||
在http{}中加入 client_max_body_size 10m;
|
||||
然后重启nginx
|
||||
|
||||
## 免责声明
|
||||
|
||||
本项目开源仅供学习使用,不得用于任何违法用途,否则后果自负,与本人无关。使用请保留项目地址谢谢。
|
||||
@@ -1,9 +1,12 @@
|
||||
<div style="text-align: center">
|
||||
<div align="center">
|
||||
<h1>File Express Cabinet - Lite</h1>
|
||||
<h2>FileCodeBox - Lite</h2>
|
||||
<p><em>share text and files with anonymous passwords, and take files like express delivery </em></p>
|
||||
</div>
|
||||
|
||||

|
||||
|
||||
|
||||
---
|
||||
|
||||
[简体中文](./readme.md) | [English](./readme_en.md)
|
||||
@@ -19,8 +22,40 @@
|
||||
- [x] anonymous sharing: no registration, no login
|
||||
- [x] management Panel: View all files and delete them
|
||||
- [x] one-click deployment: docker one-click deployment
|
||||
- [x] A variety of storage methods : Aliyun OSS、 local file flow
|
||||
|
||||
## 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,20 +78,36 @@ 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://fastly.jsdelivr.net/gh/vastsa/FileCodeBox@V1.6/images/img_10.png" alt="寄文件">
|
||||
|
||||
</td>
|
||||
<td style="width: 50%">
|
||||
<img src="https://fastly.jsdelivr.net/gh/vastsa/FileCodeBox@V1.6/images/img_11.png" alt="寄文件">
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
### Send
|
||||
|
||||
<table style="width: 100%">
|
||||
<tr style="width: 100%">
|
||||
<td style="width: 50%">
|
||||
<img src="https://raw.githubusercontent.com/vastsa/FileCodeBox/master/images/img_1.png" alt="寄文件">
|
||||
<img src="https://fastly.jsdelivr.net/gh/vastsa/FileCodeBox@V1.6/images/img_1.png" alt="寄文件">
|
||||
</td>
|
||||
<td style="width: 50%">
|
||||
<img src="https://raw.githubusercontent.com/vastsa/FileCodeBox/master/images/img_2.png" alt="寄文本">
|
||||
<img src="https://fastly.jsdelivr.net/gh/vastsa/FileCodeBox@V1.6/images/img_2.png" alt="寄文本">
|
||||
</td>
|
||||
</tr>
|
||||
<tr style="width: 100%;">
|
||||
<td colspan="2" style="width: 100%;">
|
||||
<img src="https://raw.githubusercontent.com/vastsa/FileCodeBox/master/images/img_3.png" alt="寄文本">
|
||||
<img src="https://fastly.jsdelivr.net/gh/vastsa/FileCodeBox@V1.6/images/img_3.png" alt="寄文本">
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
@@ -66,34 +117,36 @@ If you have better ideas and suggestions, welcome to file an issue.
|
||||
<table style="width: 100%">
|
||||
<tr style="width: 100%">
|
||||
<td style="width: 50%">
|
||||
<img src="https://raw.githubusercontent.com/vastsa/FileCodeBox/master/images/img_6.png" alt="取件">
|
||||
<img src="https://fastly.jsdelivr.net/gh/vastsa/FileCodeBox@V1.6/images/img_6.png" alt="取件">
|
||||
</td>
|
||||
<td style="width: 50%">
|
||||
<img src="https://raw.githubusercontent.com/vastsa/FileCodeBox/master/images/img_5.png" alt="取件码错误">
|
||||
<img src="https://fastly.jsdelivr.net/gh/vastsa/FileCodeBox@V1.6/images/img_5.png" alt="取件码错误">
|
||||
</td>
|
||||
</tr>
|
||||
<tr style="width: 100%;">
|
||||
<td colspan="2" style="width: 100%;">
|
||||
<img src="https://raw.githubusercontent.com/vastsa/FileCodeBox/master/images/img_4.png" alt="取文件">
|
||||
<img src="https://fastly.jsdelivr.net/gh/vastsa/FileCodeBox@V1.6/images/img_4.png" alt="取文件">
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
### Manage
|
||||
|
||||

|
||||
|
||||
## 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)
|
||||
<table style="width: 100%">
|
||||
<tr style="width: 100%">
|
||||
<td style="width: 50%">
|
||||
<img src="https://fastly.jsdelivr.net/gh/vastsa/FileCodeBox@V1.6/images/img_7.png" alt="admin">
|
||||
</td>
|
||||
<td style="width: 50%">
|
||||
<img src="https://fastly.jsdelivr.net/gh/vastsa/FileCodeBox@V1.6/images/img_12.png" alt="admin">
|
||||
</td>
|
||||
</tr>
|
||||
<tr style="width: 100%;">
|
||||
<td colspan="2" style="width: 100%;">
|
||||
<img src="https://fastly.jsdelivr.net/gh/vastsa/FileCodeBox@V1.6/images/img_13.png" alt="admin">
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
## Configuration file
|
||||
|
||||
@@ -137,23 +190,36 @@ DESCRIPTION=FileCodeBox,文件快递柜,口令传送箱,匿名口令分享
|
||||
KEYWORDS=FileCodeBox,文件快递柜,口令传送箱,匿名口令分享文本,文件,图片,视频,音频,压缩包等文件
|
||||
# 存储引擎
|
||||
STORAGE_ENGINE=filesystem
|
||||
# 如果使用阿里云OSS服务的话需要额外创建如下参数:
|
||||
# 阿里云账号AccessKey
|
||||
KeyId=阿里云账号AccessKey
|
||||
# 阿里云账号AccessKeySecret
|
||||
KeySecret=阿里云账号AccessKeySecret
|
||||
# 阿里云OSS Bucket的地域节点
|
||||
OSS_ENDPOINT=阿里云OSS Bucket的地域节点
|
||||
# 阿里云OSS Bucket的BucketName
|
||||
BUCKET_NAME=阿里云OSS Bucket的BucketName
|
||||
```
|
||||
|
||||
## Status
|
||||
|
||||

|
||||
|
||||
## Star History
|
||||
|
||||
[](https://star-history.com/#vastsa/FileCodeBox&Date)
|
||||
|
||||
## Appreciate
|
||||
|
||||
<table style="width: 100%">
|
||||
<tr style="width: 100%">
|
||||
<td style="width: 50%;text-align: center;">
|
||||
支付宝
|
||||
<img src="https://raw.githubusercontent.com/vastsa/FileCodeBox/master/images/img_9.png" alt="支付宝">
|
||||
<img src="https://fastly.jsdelivr.net/gh/vastsa/FileCodeBox@V1.6/images/img_9.png" alt="支付宝">
|
||||
</td>
|
||||
<td style="width: 50%;text-align: center">
|
||||
微信
|
||||
<img src="https://raw.githubusercontent.com/vastsa/FileCodeBox/master/images/img_8.png" alt="微信">
|
||||
<img src="https://fastly.jsdelivr.net/gh/vastsa/FileCodeBox@V1.6/images/img_8.png" alt="微信">
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
@@ -4,4 +4,6 @@ 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
|
||||
oss2==2.16.0
|
||||
uvicorn==0.15.0
|
||||
@@ -1,45 +1,88 @@
|
||||
import uuid
|
||||
|
||||
from starlette.config import Config
|
||||
|
||||
# 配置文件.env
|
||||
# 请将.env移动至data目录,方便docker部署
|
||||
# 配置文件.env,存放为data/.env
|
||||
config = Config("data/.env")
|
||||
# 是否开启DEBUG模式
|
||||
DEBUG = config('DEBUG', cast=bool, default=False)
|
||||
# 端口
|
||||
PORT = config('PORT', cast=int, default=12345)
|
||||
# Sqlite数据库文件
|
||||
DATABASE_FILE = config('DATABASE_FILE', cast=str, default='data/database.db')
|
||||
# Sqlite套接字
|
||||
DATABASE_URL = config('DATABASE_URL', cast=str, default=f"sqlite+aiosqlite:///{DATABASE_FILE}")
|
||||
# 数据存储文件夹,文件就不暴露在静态资源里面了
|
||||
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)
|
||||
# 最长天数
|
||||
MAX_DAYS = config('MAX_DAYS', cast=int, default=7)
|
||||
# 错误次数
|
||||
ERROR_COUNT = config('ERROR_COUNT', cast=int, default=5)
|
||||
# 错误限制分钟数
|
||||
ERROR_MINUTE = config('ERROR_MINUTE', cast=int, default=10)
|
||||
# 上传次数
|
||||
UPLOAD_COUNT = config('UPLOAD_COUNT', cast=int, default=60)
|
||||
# 上传限制分钟数
|
||||
UPLOAD_MINUTE = config('UPLOAD_MINUTE', cast=int, default=1)
|
||||
# 删除过期文件的间隔(分钟)
|
||||
DELETE_EXPIRE_FILES_INTERVAL = config('DELETE_EXPIRE_FILES_INTERVAL', cast=int, default=10)
|
||||
# 管理地址
|
||||
ADMIN_ADDRESS = config('ADMIN_ADDRESS', cast=str, default="admin")
|
||||
# 管理密码
|
||||
ADMIN_PASSWORD = config('ADMIN_PASSWORD', cast=str, default="admin")
|
||||
# 文件大小限制,默认10MB
|
||||
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,文件快递柜,口令传送箱,匿名口令分享文本,文件等文件")
|
||||
# 网站关键词
|
||||
KEYWORDS = config('KEYWORDS', cast=str, default="FileCodeBox,文件快递柜,口令传送箱,匿名口令分享文本,文件等文件")
|
||||
# 存储引擎
|
||||
STORAGE_ENGINE = config('STORAGE_ENGINE', cast=str, default="filesystem")
|
||||
|
||||
|
||||
class Settings:
|
||||
# 项目版本
|
||||
VERSION: str = config("VERSION", default="1.6")
|
||||
# 是否开启DEBUG模式
|
||||
DEBUG = config('DEBUG', cast=bool, default=False)
|
||||
# 端口
|
||||
PORT = config('PORT', cast=int, default=12345)
|
||||
# Sqlite数据库文件
|
||||
DATABASE_FILE = config('DATABASE_FILE', cast=str, default='data/database.db')
|
||||
# Sqlite套接字
|
||||
DATABASE_URL = config('DATABASE_URL', cast=str, default=f"sqlite+aiosqlite:///{DATABASE_FILE}")
|
||||
# 数据存储文件夹,文件就不暴露在静态资源里面了
|
||||
DATA_ROOT = './data/' + config('DATA_ROOT', cast=str, default=f"static")
|
||||
# 本地文件夹
|
||||
LOCAL_ROOT = './data/' + config('LOCAL_ROOT', cast=str, default=f"local")
|
||||
# 静态文件夹URL
|
||||
STATIC_URL = config('STATIC_URL', cast=str, default="/static")
|
||||
# 开启上传
|
||||
ENABLE_UPLOAD = config('ENABLE_UPLOAD', cast=bool, default=True)
|
||||
# 最长天数
|
||||
MAX_DAYS = config('MAX_DAYS', cast=int, default=7)
|
||||
# 错误次数
|
||||
ERROR_COUNT = config('ERROR_COUNT', cast=int, default=5)
|
||||
# 错误限制分钟数
|
||||
ERROR_MINUTE = config('ERROR_MINUTE', cast=int, default=10)
|
||||
# 上传次数
|
||||
UPLOAD_COUNT = config('UPLOAD_COUNT', cast=int, default=60)
|
||||
# 上传限制分钟数
|
||||
UPLOAD_MINUTE = config('UPLOAD_MINUTE', cast=int, default=1)
|
||||
# 删除过期文件的间隔(分钟)
|
||||
DELETE_EXPIRE_FILES_INTERVAL = config('DELETE_EXPIRE_FILES_INTERVAL', cast=int, default=10)
|
||||
# 管理地址
|
||||
ADMIN_ADDRESS = config('ADMIN_ADDRESS', cast=str, default=uuid.uuid4().hex)
|
||||
# 管理密码
|
||||
ADMIN_PASSWORD = config('ADMIN_PASSWORD', cast=str, default=uuid.uuid4().hex)
|
||||
# 文件大小限制,默认10MB
|
||||
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,文件快递柜,口令传送箱,匿名口令分享文本,文件")
|
||||
# 网站关键词
|
||||
KEYWORDS = config('KEYWORDS', cast=str, default="FileCodeBox,文件快递柜,口令传送箱,匿名口令分享文本,文件")
|
||||
# 存储引擎:['aliyunsystem','filesystem']
|
||||
STORAGE_ENGINE = config('STORAGE_ENGINE', cast=str, default="filesystem")
|
||||
# 存储引擎配置
|
||||
STORAGE_CONFIG = {}
|
||||
# Banners
|
||||
BANNERS = [{
|
||||
'text': 'FileCodeBox',
|
||||
'url': 'https://github.com/vastsa/FileCodeBox',
|
||||
'src': '/static/banners/img_1.png'
|
||||
}, {
|
||||
'text': 'LanBlog',
|
||||
'url': 'https://www.lanol.cn',
|
||||
'src': '/static/banners/img_2.png'
|
||||
}]
|
||||
int_dict = {'PORT', 'MAX_DAYS', 'ERROR_COUNT', 'ERROR_MINUTE', 'UPLOAD_COUNT', 'UPLOAD_MINUTE',
|
||||
'DELETE_EXPIRE_FILES_INTERVAL', 'FILE_SIZE_LIMIT'}
|
||||
bool_dict = {'DEBUG', 'ENABLE_UPLOAD'}
|
||||
|
||||
async def update(self, key, value) -> None:
|
||||
if hasattr(self, key):
|
||||
if key in self.int_dict:
|
||||
value = int(value)
|
||||
elif key in self.bool_dict:
|
||||
value = bool(value)
|
||||
setattr(self, key, value)
|
||||
|
||||
async def updates(self, options) -> None:
|
||||
with open('data/.env', 'w', encoding='utf-8') as f:
|
||||
for i, key, value in options:
|
||||
# 更新env文件
|
||||
f.write(f"{key}={value}\n")
|
||||
# 更新配置
|
||||
await self.update(key, value)
|
||||
f.flush()
|
||||
|
||||
|
||||
settings = Settings()
|
||||
|
Before Width: | Height: | Size: 172 KiB After Width: | Height: | Size: 499 KiB |
@@ -1,61 +0,0 @@
|
||||
import os
|
||||
import asyncio
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
from typing import BinaryIO
|
||||
|
||||
from fastapi import UploadFile
|
||||
|
||||
import settings
|
||||
|
||||
|
||||
class FileSystemStorage:
|
||||
DATA_ROOT = Path(settings.DATA_ROOT)
|
||||
STATIC_URL = settings.STATIC_URL
|
||||
NAME = "filesystem"
|
||||
|
||||
async def get_filepath(self, text: str):
|
||||
return self.DATA_ROOT / text.lstrip(self.STATIC_URL + '/')
|
||||
|
||||
async def get_text(self, file: UploadFile, key: str):
|
||||
ext = file.filename.split('.')[-1]
|
||||
now = datetime.now()
|
||||
path = self.DATA_ROOT / f"upload/{now.year}/{now.month}/{now.day}/"
|
||||
if not path.exists():
|
||||
path.mkdir(parents=True)
|
||||
text = f"{self.STATIC_URL}/{(path / f'{key}.{ext}').relative_to(self.DATA_ROOT)}"
|
||||
return text
|
||||
|
||||
@staticmethod
|
||||
async def get_size(file: UploadFile):
|
||||
f = file.file
|
||||
f.seek(0, os.SEEK_END)
|
||||
size = f.tell()
|
||||
f.seek(0, os.SEEK_SET)
|
||||
return size
|
||||
|
||||
@staticmethod
|
||||
def _save(filepath, file: BinaryIO):
|
||||
with open(filepath, 'wb') as f:
|
||||
chunk_size = 256 * 1024
|
||||
chunk = file.read(chunk_size)
|
||||
while chunk:
|
||||
f.write(chunk)
|
||||
chunk = file.read(chunk_size)
|
||||
|
||||
async def save_file(self, file: UploadFile, text: str):
|
||||
filepath = await self.get_filepath(text)
|
||||
await asyncio.to_thread(self._save, filepath, file.file)
|
||||
|
||||
async def delete_file(self, text: str):
|
||||
filepath = await self.get_filepath(text)
|
||||
await asyncio.to_thread(os.remove, filepath)
|
||||
|
||||
async def delete_files(self, texts):
|
||||
tasks = [self.delete_file(text) for text in texts]
|
||||
await asyncio.gather(*tasks)
|
||||
|
||||
|
||||
STORAGE_ENGINE = {
|
||||
"filesystem": FileSystemStorage
|
||||
}
|
||||
@@ -18,6 +18,10 @@
|
||||
.el-menu-demo {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
body {
|
||||
background: #f5f5f5;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
@@ -25,8 +29,9 @@
|
||||
<el-row v-if="login" :gutter="10">
|
||||
<el-col :span="24" style="text-align: center">
|
||||
<el-menu :default-active="activeIndex" class="el-menu-demo" mode="horizontal" @select="handleSelect">
|
||||
<el-menu-item index="2">文件管理</el-menu-item>
|
||||
<el-menu-item index="3">系统配置</el-menu-item>
|
||||
<el-menu-item index="2">分享文件管理</el-menu-item>
|
||||
<el-menu-item index="3">本地文件列表</el-menu-item>
|
||||
<el-menu-item index="4">系统配置</el-menu-item>
|
||||
</el-menu>
|
||||
</el-col>
|
||||
<el-col v-if="activeIndex === '2'">
|
||||
@@ -40,8 +45,8 @@
|
||||
<div>文件名:${ file.name }</div>
|
||||
<div>次 数:${ file.count }</div>
|
||||
<div>到 期:${ file.exp_time.slice(0,19) }</div>
|
||||
<div v-if="file.type==='text'">
|
||||
<span>内 容:${ file.text }</span>
|
||||
<div v-if="file.name==='文本分享'">
|
||||
<span style="white-space: pre-line">内 容:${ file.text }</span>
|
||||
</div>
|
||||
<div v-else>
|
||||
<span>链 接:</span>
|
||||
@@ -62,81 +67,145 @@
|
||||
style="text-align: center"
|
||||
layout="prev, pager, next, sizes"
|
||||
:page-size="paginate.page_size"
|
||||
@current-change="loginAdmin"
|
||||
@current-change="updatePage"
|
||||
@size-change="updateSize"
|
||||
:total="paginate.total"
|
||||
>
|
||||
</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)">
|
||||
<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>
|
||||
<el-input v-model="banner.src" placeholder="图片路径"></el-input>
|
||||
</div>
|
||||
<div style="display: inline-block">
|
||||
<el-button type="danger" @click="deleteBanner(index)">删除</el-button>
|
||||
</div>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button size="mini" @click="addBanner" type="primary">新增Banner</el-button>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button @click="updateConfig" type="primary">更新</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<el-card style="height: 80vh;overflow: scroll;margin-bottom: 1rem">
|
||||
<el-empty v-if="locals.length === 0"
|
||||
description="暂时还没有文件,请上传至/opt/data/locals目录"></el-empty>
|
||||
<el-card v-for="file in locals" :key="file.code">
|
||||
<el-row>
|
||||
<el-col :span="20">
|
||||
<div style="cursor: pointer;text-align: left">
|
||||
<div>文件名:${ file.name }</div>
|
||||
<div>路径:${ file.path }</div>
|
||||
</div>
|
||||
</el-col>
|
||||
<el-col :span="4">
|
||||
<el-button type="primary" @click="shareFile(file)">分享</el-button>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</el-card>
|
||||
</el-card>
|
||||
</el-col>
|
||||
<el-col v-if="activeIndex === '4'">
|
||||
<el-row>
|
||||
<el-col :span="4" style="height: 88vh;overflow: scroll;text-align: center" :gutter="10">
|
||||
<el-card v-for="menu in menus" :key="menu.key">
|
||||
<div style="cursor: pointer;" @click="updateTab=menu.key">${menu.name}</div>
|
||||
</el-card>
|
||||
</el-col>
|
||||
<el-col :span="20">
|
||||
<el-card style="height: 88vh;overflow: scroll">
|
||||
<div v-if="updateTab=='INSTALL'">
|
||||
<div>
|
||||
<h1>FileCodeBox V${config.INSTALL}</h1>
|
||||
<h2>Github:<a target="_blank"
|
||||
href="https://github.com/vastsa/FileCodeBox">FileCodeBox</a></h2>
|
||||
</div>
|
||||
</div>
|
||||
<div v-else-if="updateTab=='BANNERS'">
|
||||
<el-form ref="form" style="margin:1rem auto" :model="config" label-width="200px">
|
||||
<el-form-item v-for="(banner,index) in config.BANNERS" :label="'Banner'+ (index+1)">
|
||||
<div style="display: inline-block">
|
||||
<el-input v-model="banner.text" placeholder="文本"></el-input>
|
||||
<el-input v-model="banner.url" placeholder="跳转链接"></el-input>
|
||||
<el-input v-model="banner.src" placeholder="图片路径"></el-input>
|
||||
</div>
|
||||
<div style="display: inline-block">
|
||||
<el-button type="danger" @click="deleteBanner(index)">删除</el-button>
|
||||
</div>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button size="mini" @click="addBanner" type="primary">新增Banner</el-button>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button @click="updateConfig" type="primary">更新</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</div>
|
||||
<div v-else-if="updateTab=='WEBSITE'">
|
||||
<el-form ref="form" style="margin:1rem auto" :model="config" label-width="200px">
|
||||
<el-form-item label="后台密码">
|
||||
<el-input type="password" v-model="config.ADMIN_PASSWORD"
|
||||
placeholder="网站名称"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="网站名称">
|
||||
<el-input v-model="config.TITLE" placeholder="网站名称"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="网站描述">
|
||||
<el-input v-model="config.DESCRIPTION" placeholder="网站描述"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="网站关键词">
|
||||
<el-input v-model="config.KEYWORDS" placeholder="网站关键词"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-alert
|
||||
title="下列信息修改后需要手动重启系统"
|
||||
type="warning">
|
||||
</el-alert>
|
||||
</el-form-item>
|
||||
<el-form-item label="后台地址">
|
||||
<el-input v-model="config.ADMIN_ADDRESS" placeholder="后台地址"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="存储引擎">
|
||||
<el-input v-model="config.STORAGE_ENGINE" placeholder="存储引擎"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button @click="updateConfig" type="primary">更新</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</div>
|
||||
<div v-else-if="updateTab=='SHARE'">
|
||||
<el-form ref="form" style="margin:1rem auto" :model="config" label-width="200px">
|
||||
<el-form-item label="开启上传">
|
||||
<el-input v-model="config.ENABLE_UPLOAD" placeholder="开启上传"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="最长天数">
|
||||
<el-input v-model="config.MAX_DAYS" placeholder="最长允许保留多少天"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="删除过期间隔">
|
||||
<el-input v-model="config.DELETE_EXPIRE_FILES_INTERVAL"
|
||||
placeholder="删除过期文件的间隔(分钟)"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="上传大小限制">
|
||||
<small>单位:(bit),1mb=1 * 1024 * 1024</small>
|
||||
<el-input v-model="config.FILE_SIZE_LIMIT"
|
||||
placeholder="上传大小限制(bit)"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-alert
|
||||
title="下列信息修改后需要手动重启系统"
|
||||
type="warning">
|
||||
</el-alert>
|
||||
</el-form-item>
|
||||
<el-form-item label="口令错误限制">
|
||||
<small>每几分钟</small>
|
||||
<el-input v-model="config.ERROR_MINUTE"
|
||||
placeholder="错误次数过多后限制时间"></el-input>
|
||||
<small>允许错误几次</small>
|
||||
<el-input v-model="config.ERROR_COUNT" placeholder="允许错误次数"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="上传次数限制">
|
||||
<small>每几分钟</small>
|
||||
<el-input v-model="config.UPLOAD_MINUTE"
|
||||
placeholder="每几分钟"></el-input>
|
||||
<small>允许上传几次</small>
|
||||
<el-input v-model="config.UPLOAD_COUNT"
|
||||
placeholder="允许次数"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button @click="updateConfig" type="primary">更新</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</div>
|
||||
</el-card>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<div v-else style="width: 250px;text-align: center;margin: 40vh auto">
|
||||
@@ -144,6 +213,7 @@
|
||||
<el-button slot="append" type="primary" @click="loginAdmin">登录</el-button>
|
||||
</el-input>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</body>
|
||||
@@ -158,18 +228,12 @@
|
||||
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: []
|
||||
},
|
||||
menus: [],
|
||||
updateTab: 'INSTALL',
|
||||
files: [],
|
||||
locals: [],
|
||||
paginate: {
|
||||
page: 1,
|
||||
size: 10,
|
||||
@@ -182,27 +246,34 @@
|
||||
if (pwd) {
|
||||
login = true;
|
||||
this.pwd = pwd;
|
||||
axios.get('/config', {
|
||||
headers: {
|
||||
pwd: pwd
|
||||
}
|
||||
}).then(res => {
|
||||
console.log(res.data.data)
|
||||
this.config = res.data.data;
|
||||
});
|
||||
this.loginAdmin();
|
||||
this.getLocalFiles();
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
getConfig: function () {
|
||||
axios.get(window.location.href + '/config', {
|
||||
headers: {
|
||||
pwd: this.pwd
|
||||
}
|
||||
}).then(res => {
|
||||
this.config = res.data.data;
|
||||
this.menus = res.data.menus;
|
||||
});
|
||||
},
|
||||
updateSize: function (value) {
|
||||
this.paginate.size = value;
|
||||
this.loginAdmin();
|
||||
},
|
||||
updatePage: function (value) {
|
||||
this.paginate.page = value;
|
||||
this.loginAdmin();
|
||||
},
|
||||
deleteBanner: function (index) {
|
||||
this.config.banners.splice(index, 1);
|
||||
this.config.BANNERS.splice(index, 1);
|
||||
},
|
||||
addBanner: function () {
|
||||
this.config.banners.push({
|
||||
this.config.BANNERS.push({
|
||||
'url': '',
|
||||
'src': '',
|
||||
'text': '',
|
||||
@@ -221,8 +292,7 @@
|
||||
});
|
||||
})
|
||||
},
|
||||
loginAdmin: function (current_page = 1) {
|
||||
this.paginate.page = current_page;
|
||||
loginAdmin: function () {
|
||||
axios.post('', this.paginate, {
|
||||
'headers': {
|
||||
'pwd': this.pwd,
|
||||
@@ -233,6 +303,7 @@
|
||||
this.files = res.data.data
|
||||
this.login = true;
|
||||
localStorage.setItem('pwd', this.pwd);
|
||||
this.getConfig();
|
||||
}).catch(e => {
|
||||
localStorage.clear()
|
||||
this.$message({'message': e.response.data.detail, 'type': 'error'});
|
||||
@@ -250,7 +321,31 @@
|
||||
});
|
||||
})
|
||||
},
|
||||
getLocalFiles: function () {
|
||||
axios.get(window.location.href + '/files', {
|
||||
'headers': {
|
||||
'pwd': this.pwd,
|
||||
'Content-Type': 'multipart/form-data'
|
||||
}
|
||||
}).then(res => {
|
||||
this.locals = res.data.data;
|
||||
})
|
||||
},
|
||||
shareFile: function (file) {
|
||||
axios.post(window.location.href + '/files', file, {
|
||||
'headers': {
|
||||
'pwd': this.pwd,
|
||||
'Content-Type': 'multipart/form-data'
|
||||
}
|
||||
}).then(res => {
|
||||
this.getLocalFiles()
|
||||
this.$alert(`请在24小时内使用:${res.data.data.code}`, '分享成功', {
|
||||
confirmButtonText: '确定',
|
||||
});
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
})
|
||||
</script>
|
||||
</html>
|
||||
</html>
|
||||
@@ -11,8 +11,12 @@
|
||||
<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="V1.6 Beta"/>
|
||||
<style>
|
||||
body {
|
||||
background: #f5f5f5;
|
||||
}
|
||||
|
||||
.qu .el-button {
|
||||
width: 100px;
|
||||
height: 100px;
|
||||
@@ -21,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;
|
||||
@@ -32,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="请输入五位取件码">
|
||||
@@ -87,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">
|
||||
@@ -166,12 +204,13 @@
|
||||
: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>
|
||||
<div v-if="file.name==='文本分享'">
|
||||
<span @click="copyText(file.text,1)">内 容:${ file.text }</span>
|
||||
<span style="white-space: pre-line"
|
||||
@click="copyText(file.text,1)">内 容:${ file.text }</span>
|
||||
</div>
|
||||
<div v-else>
|
||||
<span>链 接:</span>
|
||||
@@ -181,40 +220,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.6 Beta</a>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
@@ -229,12 +267,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',
|
||||
@@ -277,7 +317,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
|
||||
})
|
||||
},
|
||||
@@ -313,7 +358,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');
|
||||
@@ -333,13 +378,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) {
|
||||
@@ -349,6 +394,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({
|
||||
@@ -356,17 +420,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) {
|
||||
@@ -374,7 +440,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)
|
||||
@@ -384,15 +450,9 @@
|
||||
});
|
||||
},
|
||||
beforeUpload: function (file) {
|
||||
if (file.size > this.fileSizeLimit) {
|
||||
this.$message({
|
||||
message: `文件大小不能超过${this.fileSizeLimit/1024/1024}MB`,
|
||||
type: 'error'
|
||||
});
|
||||
return false
|
||||
}
|
||||
return this.checkFile(file);
|
||||
}
|
||||
}
|
||||
})
|
||||
</script>
|
||||
</html>
|
||||
</html>
|
||||