Compare commits

...
38 Commits
Author SHA1 Message Date
lan-air 42dedfae1e 完善文档,以及docker新增文件夹映射 2022-12-11 23:06:28 +08:00
lan-air cfd2989bc0 完善文档,以及docker新增文件夹映射 2022-12-11 22:47:33 +08:00
lan-air 31b61a2f7a 完善文档,以及docker新增文件夹映射 2022-12-11 22:47:08 +08:00
lan-air 802b8a0a8f 完善文档,以及docker新增文件夹映射 2022-12-11 22:35:10 +08:00
vastsa ef89de6294 Merge pull request #6 from veoco/master
增加定时清理过期文件
2022-12-11 22:00:12 +08:00
veoco 74a835f8b6 增加独立配置文件 2022-12-11 21:07:39 +08:00
veoco 2ef6c752ee 增加定时清理过期文件 2022-12-11 18:55:02 +08:00
lan-air bec3eb2ea1 完善 aiosqlite 异步数据库驱动 2022-12-11 18:15:54 +08:00
lan-air ae7aa63e2a 完善 aiosqlite 异步数据库驱动 2022-12-11 18:14:41 +08:00
lan-air b999073da4 完善 aiosqlite 异步数据库驱动 2022-12-11 18:03:46 +08:00
lan-air e5d18a5bf3 完善 aiosqlite 异步数据库驱动 2022-12-11 17:41:54 +08:00
vastsa d25a92199f Merge pull request #1 from veoco/master
使用 aiosqlite 驱动异步化数据库操作
2022-12-11 17:19:00 +08:00
vastsa b7315bb840 Merge branch 'master' into master 2022-12-11 17:18:06 +08:00
vastsa ea647519c6 Update readme.md
update readme
2022-12-11 15:09:50 +08:00
lan-air 1dbcd8bd57 隐藏真实文件地址 2022-12-11 15:09:02 +08:00
lan-air dd39423d1a 隐藏真实文件地址 2022-12-11 15:04:38 +08:00
lan-air ff831e39f4 隐藏真实文件地址 2022-12-11 14:55:29 +08:00
lan-air 0883eafa49 隐藏真实文件地址 2022-12-11 14:52:28 +08:00
lan-air 1dc6a741b6 隐藏真实文件地址 2022-12-11 14:40:14 +08:00
veoco f4e6dfef0d 数据库操作改为异步 2022-12-11 14:04:25 +08:00
veoco 195c6f9ae4 添加 aiosqlite 异步数据库驱动 2022-12-11 14:03:46 +08:00
lan-air 710bb55a93 修改取件框margin 2022-12-11 12:11:10 +08:00
lan-air 8ab74728ac 改个名 2022-12-11 11:50:17 +08:00
lan-air 1cbb7534f3 开源协议 2022-12-11 11:07:38 +08:00
lan-air 132aeee4cc 更新输入取件后,弹出取件码,和寄件文件箱改为取件码 2022-12-11 10:39:54 +08:00
lan-air 896992aff6 Merge remote-tracking branch 'origin/master' 2022-12-11 01:54:58 +08:00
vastsa 2eb2c341eb Update readme.md
改个名
2022-12-11 01:52:59 +08:00
lan-air ce6bc749c1 update readme.md 2022-12-11 01:31:50 +08:00
lan-air 5f99457d14 update readme.md 2022-12-11 00:50:08 +08:00
lan-air e5eb071c2d update readme.md 2022-12-11 00:48:36 +08:00
lan-air 9b8b1e81fe 修复文件次数1直接删除 2022-12-11 00:08:43 +08:00
lan-air 77b7c58885 Merge remote-tracking branch 'origin/master' 2022-12-11 00:02:23 +08:00
lan-air 94fc0e856b 修复文件次数1直接删除 2022-12-11 00:02:12 +08:00
vastsa 5cbb122ddf Update readme.md
修复取件数据
2022-12-10 23:51:01 +08:00
lan-air 5eec46605b 修复取件问题 2022-12-10 23:47:36 +08:00
lan-air b273d38b31 新增部署教程地址 2022-12-10 21:59:09 +08:00
lan-air 90d1ab7330 main.py 启动 2022-12-10 21:43:12 +08:00
lan-air f4ba56138d 新增取件码过期条件,上传大小限制 2022-12-10 21:11:25 +08:00
10 changed files with 535 additions and 153 deletions

No files matched your search

+3 -5
View File
@@ -1,13 +1,11 @@
FROM python:3.9.5
LABEL author="Lan"
LABEL email="vast@tom.com"
LABEL version="1.0"
LABEL version="1.4.4"
COPY . /app
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
RUN echo 'Asia/Shanghai' >/etc/timezone
WORKDIR /app
RUN pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple/
RUN pip install -r requirements.txt
EXPOSE 12345
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "12345"]
CMD ["python","main.py"]
+165
View File
@@ -0,0 +1,165 @@
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.
+16 -6
View File
@@ -1,17 +1,27 @@
import datetime
from sqlalchemy import create_engine, DateTime
from sqlalchemy.orm import sessionmaker
from sqlalchemy import Boolean, Column, Integer, String, DateTime
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Boolean, Column, Integer, String
from sqlalchemy.ext.asyncio import create_async_engine
from sqlalchemy.ext.asyncio.session import AsyncSession
engine = create_async_engine("sqlite+aiosqlite:///database.db")
engine = create_engine('sqlite:///database.db', connect_args={"check_same_thread": False})
Base = declarative_base()
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
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 Codes(Base):
__tablename__ = 'codes'
__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)
BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 44 KiB

After

Width:  |  Height:  |  Size: 78 KiB

+175 -106
View File
@@ -2,94 +2,113 @@ import datetime
import os
import uuid
import threading
from fastapi import FastAPI, Depends, UploadFile, Form, File
from sqlalchemy.orm import Session
from starlette.requests import Request
from starlette.responses import HTMLResponse
import random
import asyncio
from pathlib import Path
from fastapi import FastAPI, Depends, UploadFile, Form, File
from starlette.requests import Request
from starlette.responses import HTMLResponse, FileResponse
from starlette.staticfiles import StaticFiles
import database
from database import engine, SessionLocal, Base
from sqlalchemy import or_, select, update, delete
from sqlalchemy.ext.asyncio.session import AsyncSession
import settings
from database import get_session, Codes, init_models, engine
app = FastAPI(debug=settings.DEBUG)
DATA_ROOT = Path(settings.DATA_ROOT)
if not DATA_ROOT.exists():
DATA_ROOT.mkdir(parents=True)
STATIC_URL = settings.STATIC_URL
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) \
.replace('{{keywords}}', settings.KEYWORDS)
admin_html = open('templates/admin.html', 'r', encoding='utf-8').read() \
.replace('{{title}}', settings.TITLE) \
.replace('{{description}}', settings.DESCRIPTION) \
.replace('{{keywords}}', settings.KEYWORDS)
Base.metadata.create_all(bind=engine)
app = FastAPI()
if not os.path.exists('./static'):
os.makedirs('./static')
app.mount("/static", StaticFiles(directory="static"), name="static")
index_html = open('templates/index.html', 'r', encoding='utf-8').read()
admin_html = open('templates/admin.html', 'r', encoding='utf-8').read()
# 过期时间
exp_hour = 24
# 允许错误次数
error_count = 5
# 禁止分钟数
error_minute = 60
# 后台地址
admin_address = 'admin'
# 管理密码
admin_password = 'admin'
error_ip_count = {}
def delete_file(files):
for file in files:
os.remove('.' + file)
if file['type'] != 'text':
os.remove(DATA_ROOT / file['text'].lstrip(STATIC_URL + '/'))
def get_db():
db = SessionLocal()
try:
yield db
finally:
db.close()
async def delete_expire_files():
while True:
async with AsyncSession(engine, expire_on_commit=False) as s:
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))
def get_code(db: Session = Depends(get_db)):
async def get_code(s: AsyncSession):
code = random.randint(10000, 99999)
while db.query(database.Codes).filter(database.Codes.code == code).first():
while (await s.execute(select(Codes.id).where(Codes.code == code))).scalar():
code = random.randint(10000, 99999)
return str(code)
def get_file_name(key, ext, file):
def get_file_name(key, ext, file, file_bytes):
now = datetime.datetime.now()
path = f'./static/upload/{now.year}/{now.month}/{now.day}/'
path = DATA_ROOT / f"upload/{now.year}/{now.month}/{now.day}/"
name = f'{key}.{ext}'
if not os.path.exists(path):
os.makedirs(path)
file = file.file.read()
with open(f'{os.path.join(path, name)}', 'wb') as f:
f.write(file)
return key, len(file), path[1:] + name
if not path.exists():
path.mkdir(parents=True)
filepath = path / name
with open(filepath, 'wb') as f:
f.write(file_bytes)
return f"{STATIC_URL}/{filepath.relative_to(DATA_ROOT)}", file.content_type, file.filename
@app.get(f'/{admin_address}')
@app.get(f'/{settings.ADMIN_ADDRESS}')
async def admin():
return HTMLResponse(admin_html)
@app.post(f'/{admin_address}')
async def admin_post(request: Request, db: Session = Depends(get_db)):
if request.headers.get('pwd') == admin_password:
codes = db.query(database.Codes).all()
@app.post(f'/{settings.ADMIN_ADDRESS}')
async def admin_post(request: Request, s: AsyncSession = Depends(get_session)):
if request.headers.get('pwd') == settings.ADMIN_PASSWORD:
query = select(Codes)
codes = (await s.execute(query)).scalars().all()
return {'code': 200, 'msg': '查询成功', 'data': codes}
else:
return {'code': 400, 'msg': '密码错误'}
return {'code': 404, 'msg': '密码错误'}
@app.delete(f'/{admin_address}')
async def admin_delete(request: Request, code: str, db: Session = Depends(get_db)):
if request.headers.get('pwd') == admin_password:
file = db.query(database.Codes).filter(database.Codes.code == code)
if file.first().type != 'text/plain':
threading.Thread(target=delete_file, args=([file.first().text],)).start()
file.delete()
db.commit()
@app.delete(f'/{settings.ADMIN_ADDRESS}')
async def admin_delete(request: Request, code: str, s: AsyncSession = Depends(get_session)):
if request.headers.get('pwd') == settings.ADMIN_PASSWORD:
query = select(Codes).where(Codes.code == code)
file = (await s.execute(query)).scalars().first()
await asyncio.to_thread(delete_file, [{'type': file.type, 'text': file.text}])
await s.delete(file)
await s.commit()
return {'code': 200, 'msg': '删除成功'}
else:
return {'code': 400, 'msg': '密码错误'}
return {'code': 404, 'msg': '密码错误'}
@app.get('/')
@@ -97,60 +116,110 @@ async def index():
return HTMLResponse(index_html)
@app.post('/')
async def index(request: Request, code: str, db: Session = Depends(get_db)):
info = db.query(database.Codes).filter(database.Codes.code == code).first()
error = error_ip_count.get(request.client.host, {'count': 0, 'time': datetime.datetime.now()})
if error['count'] > error_count:
if datetime.datetime.now() - error['time'] < datetime.timedelta(minutes=error_minute):
return {'code': 404, 'msg': '请求过于频繁,请稍后再试'}
def check_ip(ip):
# 检查ip是否被禁止
if ip in error_ip_count:
if error_ip_count[ip]['count'] >= settings.ERROR_COUNT:
if error_ip_count[ip]['time'] + datetime.timedelta(minutes=settings.ERROR_MINUTE) > datetime.datetime.now():
return False
else:
error_ip_count.pop(ip)
return True
def ip_error(ip):
ip_info = error_ip_count.get(ip, {'count': 0, 'time': datetime.datetime.now()})
ip_info['count'] += 1
error_ip_count[ip] = ip_info
return ip_info['count']
@app.get('/select')
async def get_file(code: str, s: AsyncSession = Depends(get_session)):
query = select(Codes).where(Codes.code == code)
info = (await s.execute(query)).scalars().first()
if info:
if info.type == 'text':
return {'code': code, 'msg': '查询成功', 'data': info.text}
else:
error['count'] = 0
return FileResponse(DATA_ROOT / info.text.lstrip(STATIC_URL + '/'), filename=info.name)
else:
if not info:
error['count'] += 1
error_ip_count[request.client.host] = error
return {'code': 404, 'msg': f'取件码错误,错误5次将被禁止10分钟'}
else:
return {'code': 200, 'msg': '取件成功,请点击“取”查看', 'data': info}
return {'code': 404, 'msg': '口令不存在'}
@app.post('/')
async def index(request: Request, code: str, s: AsyncSession = Depends(get_session)):
ip = request.client.host
if not check_ip(ip):
return {'code': 404, 'msg': '错误次数过多,请稍后再试'}
query = select(Codes).where(Codes.code == code)
info = (await s.execute(query)).scalars().first()
if not info:
return {'code': 404, 'msg': f'取件码错误,错误{settings.ERROR_COUNT - ip_error(ip)}次将被禁止10分钟'}
if info.exp_time < datetime.datetime.now() or info.count == 0:
threading.Thread(target=delete_file, args=([{'type': info.type, 'text': info.text}],)).start()
await s.delete(info)
await s.commit()
return {'code': 404, 'msg': '取件码已过期,请联系寄件人'}
count = info.count - 1
query = update(Codes).where(Codes.id == info.id).values(count=count)
await s.execute(query)
await s.commit()
if info.type != 'text':
info.text = f'/select?code={code}'
return {
'code': 200,
'msg': '取件成功,请点击"取"查看',
'data': {'type': info.type, 'text': info.text, 'name': info.name, 'code': info.code}
}
@app.post('/share')
async def share(text: str = Form(default=None), file: UploadFile = File(default=None), db: Session = Depends(get_db)):
cutoff_time = datetime.datetime.now() - datetime.timedelta(hours=exp_hour)
olds = db.query(database.Codes).filter(database.Codes.use_time < cutoff_time)
threading.Thread(target=delete_file, args=([old.text for old in olds if old.type != 'text/plain'],)).start()
olds.delete()
db.commit()
code = get_code(db)
if text:
info = database.Codes(
code=code,
text=text,
type='text/plain',
key=uuid.uuid4().hex,
size=len(text),
used=True,
name='分享文本'
)
db.add(info)
db.commit()
return {'code': 200, 'msg': '上传成功,请点击文件库查看',
'data': {'code': code, 'name': '分享文本', 'text': text}}
elif file:
key, size, full_path = get_file_name(uuid.uuid4().hex, file.filename.split('.')[-1], file)
info = database.Codes(
code=code,
text=full_path,
type=file.content_type,
key=key,
size=size,
used=True,
name=file.filename
)
db.add(info)
db.commit()
return {'code': 200, 'msg': '上传成功,请点击文件库查看',
'data': {'code': code, 'name': file.filename, 'text': full_path}}
async def share(text: str = Form(default=None), style: str = Form(default='2'), value: int = Form(default=1),
file: UploadFile = File(default=None), s: AsyncSession = Depends(get_session)):
code = await get_code(s)
if style == '2':
if value > 7:
return {'code': 404, 'msg': '最大有效天数为7天'}
exp_time = datetime.datetime.now() + datetime.timedelta(days=value)
exp_count = -1
elif style == '1':
if value < 1:
return {'code': 404, 'msg': '最小有效次数为1次'}
exp_time = datetime.datetime.now() + datetime.timedelta(days=1)
exp_count = value
else:
return {'code': 422, 'msg': '参数错误', 'data': []}
exp_time = datetime.datetime.now() + datetime.timedelta(days=1)
exp_count = -1
key = uuid.uuid4().hex
if 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(
code=code,
text=_text,
size=size,
type=_type,
name=name,
count=exp_count,
exp_time=exp_time,
key=key
)
s.add(info)
await s.commit()
return {
'code': 200,
'msg': '分享成功,请点击文件箱查看取件码',
'data': {'code': code, 'key': key, 'name': name, 'text': _text}
}
if __name__ == '__main__':
import uvicorn
uvicorn.run('main:app', host='0.0.0.0', port=12345)
+62 -7
View File
@@ -1,8 +1,8 @@
# 口令传送箱
# 文件快递柜
## 解决问题
很多时候,我们都想将一些文件或文本传送给别人,或者跨端传递一些信息,但是我们又不想为了分享,而去下载一些七里八里端软件,这时候,我们就可以使用口令传送箱。
很多时候,我们都想将一些文件或文本传送给别人,或者跨端传递一些信息,但是我们又不想为了分享,而去下载一些七里八里的软件,这时候,我们就可以使用口令传送箱,像拿快递一样取文件。
## 主要特色
@@ -15,9 +15,9 @@
- [x] 完全匿名:不记录任何信息
- [x] 无需注册:无需注册,无需登录
- [x] Sqlite3数据库:无需安装数据库
- [x] 可以加get参数code,这样打开就会读取取件码如:http://xxx.com?code=12345
- [x] 可以加get参数code,这样打开就会读取取件码如:http://host?code=12345
- [x] 管理面板:简单列表页删除违规文件
- [ ] 口令使用次数,口令有效期,二维码分享
- [x] 口令使用次数,口令有效期,二维码分享
## 更新记录
@@ -26,8 +26,24 @@
1. 管理面板已新增,一如既往的极简,只有删除
2. 二维码图片(调用的网络接口,如果离线环境将无法使用,一切为了极简)
### 2022年12月10日 21:10:00
1. 取件码有效期,取件码使用次数
2. 优化代码逻辑
3. 限制上传文件大小
4. 完善配置参数
### 2022年12月10日 23:50:00
1. 修复取件不显示码的问题
2. 修复文件次数为1时,文件被删除的问题
## 系统截图
### 2022年12月11日 14:55:00
1. 隐藏文件真实地址
### 取件
![取件](https://raw.githubusercontent.com/vastsa/FileCodeBox/master/images/img.png)
@@ -43,9 +59,40 @@
![取件](https://raw.githubusercontent.com/vastsa/FileCodeBox/master/images/img_4.png)
![取件](https://raw.githubusercontent.com/vastsa/FileCodeBox/master/images/img_5.png)
## 部署教程
https://www.yuque.com/lxyo/work/zd0kvzy7fofx6w7v
## 部署方式
先拉取代码,然后修改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
ADMIN_PASSWORD=admin
FILE_SIZE_LIMIT=10
TITLE=文件快递柜
DESCRIPTION=FileCodeBox,文件快递柜,口令传送箱,匿名口令分享文本,文件,图片,视频,音频,压缩包等文件
KEYWORDS=FileCodeBox,文件快递柜,口令传送箱,匿名口令分享文本,文件,图片,视频,音频,压缩包等文件
```
### 服务端部署
@@ -63,10 +110,18 @@
### 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
```
## 状态
![Alt](https://repobeats.axiom.co/api/embed/7a6c92f1d96ee57e6fb67f0df371528397b0c9ac.svg "Repobeats analytics image")
## 免责声明
本项目开源仅供学习使用,不得用于商业用途以及任何违法用途,否则后果自负,与本人无关。
本项目开源仅供学习使用,不得用于商业用途以及任何违法用途,否则后果自负,与本人无关。使用请保留项目地址谢谢。
+5 -2
View File
@@ -1,4 +1,7 @@
fastapi==0.88.0
python-multipart==0.0.5
aiosqlite==0.17.0
SQLAlchemy==1.4.44
uvicorn==0.20.0
python-multipart==0.0.5
uvicorn==0.15.0
greenlet==2.0.1
starlette~=0.22.0
+27
View File
@@ -0,0 +1,27 @@
from starlette.config import Config
config = Config(".env")
DEBUG = config('DEBUG', cast=bool, default=False)
DATABASE_URL = config('DATABASE_URL', cast=str, default="sqlite+aiosqlite:///database.db")
DATA_ROOT = config('DATA_ROOT', cast=str, default="./static")
STATIC_URL = config('STATIC_URL', cast=str, default="/static")
ERROR_COUNT = config('ERROR_COUNT', cast=int, default=5)
ERROR_MINUTE = config('ERROR_MINUTE', cast=int, default=10)
ADMIN_ADDRESS = config('ADMIN_ADDRESS', cast=str, default="admin")
ADMIN_PASSWORD = config('ADMIN_PASSWORD', cast=str, default="admin")
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,文件快递柜,口令传送箱,匿名口令分享文本,文件等文件")
+20 -7
View File
@@ -6,13 +6,19 @@
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="/static/assert/index.css">
<title>后台管理-口令传送箱</title>
<title>后台管理-{{title}}</title>
<meta name="description" content="{{description}}"/>
<meta name="keywords" content="{{keywords}}"/>
<meta name="generator" content="FileCodeBox"/>
<meta name="template" content="Lan"/>
</head>
<body>
<div id="app">
<el-row v-if="login">
<el-col :span="4">&nbsp;</el-col>
<el-col :span="16">
<el-row v-if="login" :gutter="10">
<el-col :xs="0" :sm="4" :md="4" :lg="4" :xl="4">
&nbsp;
</el-col>
<el-col :xs="24" :sm="16" :md="16" :lg="16" :xl="16">
<el-card>
<el-empty v-if="files.length===0" description="暂时还没有文件"></el-empty>
<el-card v-for="file in files" :key="file.code">
@@ -21,6 +27,8 @@
<div style="cursor: pointer;text-align: left">
<div>取件码:${ file.code }</div>
<div>文件名:${ file.name }</div>
<div>次&nbsp;&nbsp; 数:${ file.count }</div>
<div>到&nbsp;&nbsp; 期:${ file.exp_time.slice(0,19) }</div>
<div v-if="file.name==='分享文本'">
<span>内&nbsp;&nbsp; 容:${ file.text }</span>
</div>
@@ -39,7 +47,7 @@
</el-card>
</el-card>
</el-col>
<el-col :span="4">&nbsp;</el-col>
<el-col :xs="0" :sm="4" :md="4" :lg="4" :xl="4">&nbsp;</el-col>
</el-row>
<div v-else style="width: 250px;text-align: center;margin: 40vh auto">
<el-input v-model="pwd" placeholder="请输入登录密码">
@@ -60,7 +68,12 @@
return {
login: false,
pwd: '',
files: []
files: [],
config: {
error_count: 0,
file_size: 0,
admin_pwd: 'admin'
}
};
},
mounted: function () {
@@ -97,7 +110,7 @@
});
}
})
}
},
}
})
</script>
+62 -20
View File
@@ -6,8 +6,11 @@
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="/static/assert/index.css">
<!-- 引入组件库 -->
<title>口令传送箱</title>
<title>{{title}}</title>
<meta name="description" content="{{description}}"/>
<meta name="keywords" content="{{keywords}}"/>
<meta name="generator" content="FileCodeBox"/>
<meta name="template" content="Lan-V1.4.2"/>
<style>
.qu .el-button {
width: 100px;
@@ -27,7 +30,7 @@
</head>
<body>
<div id="app" style="text-align: center;">
<el-row v-if="tool==0" class="qu" style="width:400px;margin: auto">
<el-row v-if="tool === 0" class="qu" style="width:400px;margin: 6vh auto 0 auto">
<el-card style="padding-bottom: 1rem">
<el-col :span="24">
<el-input autofocus @input="inputing" clearable v-model:value="code" maxlength="5"
@@ -72,20 +75,32 @@
</el-col>
</el-card>
</el-row>
<el-row v-else style="width:400px;margin: auto">
<el-row v-else style="width:400px;margin: 20vh auto 0 auto">
<el-col :span="24" style="margin: 1rem 0">
<el-card>
<div style="margin-bottom: 1rem">
<el-radio-group v-model="destoryData.style">
<el-radio label="1">次数</el-radio>
<el-radio label="2">天数</el-radio>
</el-radio-group>
<el-input-number
placeholder="输入数量,默认1"
style="margin-left: 1rem" v-model="destoryData.value" controls-position="right" :min="1">
</el-input-number>
</div>
<el-upload
drag
action="/share"
multiple
:data="destoryData"
:on-success="successUpload"
>
<i class="el-icon-upload"></i>
<div class="el-upload__text">将文件拖、粘贴到此处,或<em>点击上传</em>,24h后删除</div>
<div class="el-upload__text">将文字、文件拖、粘贴到此处,或<em>点击上传</em></div>
<div class="el-upload__text" style="font-size: 10px">天数<7或限制次数(24h后删除)</div>
<div class="el-upload__tip" slot="tip">
<el-button @click="tool=0">去取件</el-button>
<el-button @click="cunDrawer=true">文件箱</el-button>
<el-button @click="cunDrawer=true">取件码</el-button>
</div>
</el-upload>
</el-card>
@@ -96,7 +111,7 @@
href="https://github.com/vastsa/FileCodeBox">FileCodeBox</a></span>
</div>
<el-drawer
title="文件库"
title="文件箱"
:visible.sync="quDrawer"
:direction="direction"
size="50%"
@@ -105,7 +120,7 @@
<div style="cursor: pointer;text-align: left">
<div>取件码:${ file.code }</div>
<div>文件名:${ file.name }</div>
<div v-if="file.name==='分享文本'">
<div v-if="file.name==='文本分享'">
<span>内&nbsp;&nbsp; 容:${ file.text }</span>
</div>
<div v-else>
@@ -119,13 +134,13 @@
<el-empty v-if="files.length===0" description="请输入取件码,收取文件"></el-empty>
</el-drawer>
<el-drawer
title="文件库"
title="文件箱"
:visible.sync="cunDrawer"
direction="btt"
size="50%">
<el-card>
<el-empty v-if="files.length===0" description="请上传文件"></el-empty>
<el-card style="margin-top: 0.2rem" v-for="file in files" :key="file.code">
<el-card style="margin-top: 0.2rem" v-for="(file,index) in files" :key="index">
<el-row>
<el-col :span="20">
<el-row>
@@ -139,7 +154,7 @@
</el-col>
<el-col :span="4">
<img style="width: 80px;height: 80px;"
:src="qrcodeUrl(file)">
:src="qrcodeUrl(file)" :alt="file.code">
</el-col>
</el-row>
</el-card>
@@ -164,7 +179,11 @@
quDrawer: false,
cunDrawer: false,
direction: 'btt',
tool: 0
tool: 0,
destoryData: {
style: '2',
value: 1
},
};
},
mounted: function () {
@@ -184,10 +203,16 @@
that.$message('剪切板文字正在上传,请稍等');
items[i].getAsString(function (str) {
FileData.append('text', str);
FileData.append('style', that.destoryData.style);
FileData.append('value', that.destoryData.value);
axios.post('/share', FileData)
.then(function (response) {
that.$message({'message': response.data.msg, 'type': 'success'});
that.files.push(response.data.data)
.then(function (res) {
if (res.data.code === 200) {
that.$message({'message': res.data.msg, 'type': 'success'});
that.files.push(res.data.data)
} else {
that.$message({'message': res.data.msg, 'type': 'error'});
}
})
.catch(function (error) {
that.$message({'message': error.data.msg, 'type': 'error'});
@@ -199,9 +224,15 @@
that.$message('剪切板文件正在上传,请稍等');
const FileData = new FormData();
FileData.append('file', file || '');
FileData.append('style', that.destoryData.style);
FileData.append('value', that.destoryData.value);
axios.post('/share', FileData).then(async res => {
that.files.push(res.data.data);
that.$message({'message': res.data.msg, 'type': 'success'});
if (res.data.code === 200) {
that.$message({'message': res.data.msg, 'type': 'success'});
that.files.push(res.data.data)
} else {
that.$message({'message': res.data.msg, 'type': 'error'});
}
})
}
@@ -231,6 +262,7 @@
message: response.data.msg,
type: 'success'
});
that.quDrawer = true;
}
that.code = '';
that.inout_disable = false
@@ -254,11 +286,21 @@
}
},
successUpload(response, file, fileList) {
this.$message({'message': '上传成功,请点击文件库查看', 'type': 'success'});
this.files.push(response.data)
if (response.code === 200) {
this.$message({
message: response.msg,
type: 'success'
});
this.files.push(response.data);
} else {
this.$message({
message: response.msg,
type: 'error'
});
}
},
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.origin + '/?code=' + file.code
},
}
})