mirror of
https://github.com/vastsa/FileCodeBox.git
synced 2026-11-20 21:57:02 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e5d18a5bf3 | ||
|
|
d25a92199f | ||
|
|
b7315bb840 | ||
|
|
ea647519c6 | ||
|
|
1dbcd8bd57 | ||
|
|
dd39423d1a | ||
|
|
ff831e39f4 | ||
|
|
0883eafa49 | ||
|
|
1dc6a741b6 | ||
|
|
f4e6dfef0d | ||
|
|
195c6f9ae4 | ||
|
|
710bb55a93 | ||
|
|
8ab74728ac | ||
|
|
1cbb7534f3 | ||
|
|
132aeee4cc | ||
|
|
896992aff6 | ||
|
|
2eb2c341eb | ||
|
|
ce6bc749c1 | ||
|
|
5f99457d14 | ||
|
|
e5eb071c2d | ||
|
|
9b8b1e81fe | ||
|
|
77b7c58885 | ||
|
|
94fc0e856b | ||
|
|
5cbb122ddf | ||
|
|
5eec46605b | ||
|
|
b273d38b31 | ||
|
|
90d1ab7330 | ||
|
|
f4ba56138d |
No files matched your search
@@ -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.
|
||||
+11
-6
@@ -1,17 +1,22 @@
|
||||
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 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)
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 44 KiB After Width: | Height: | Size: 78 KiB |
@@ -2,67 +2,80 @@ 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
|
||||
|
||||
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
|
||||
|
||||
from database import get_session, Codes
|
||||
|
||||
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
|
||||
error_minute = 10
|
||||
# 后台地址
|
||||
admin_address = 'admin'
|
||||
# 管理密码
|
||||
admin_password = 'admin'
|
||||
# 文件大小限制 10M
|
||||
file_size_limit = 1024 * 1024 * 10
|
||||
# 系统标题
|
||||
title = '文件快递柜'
|
||||
# 系统描述
|
||||
description = 'FileCodeBox,文件快递柜,口令传送箱,匿名口令分享文本,文件,图片,视频,音频,压缩包等文件'
|
||||
# 系统关键字
|
||||
keywords = 'FileCodeBox,文件快递柜,口令传送箱,匿名口令分享文本,文件,图片,视频,音频,压缩包等文件'
|
||||
############################################
|
||||
|
||||
index_html = open('templates/index.html', 'r', encoding='utf-8').read() \
|
||||
.replace('{{title}}', title) \
|
||||
.replace('{{description}}', description) \
|
||||
.replace('{{keywords}}', keywords)
|
||||
admin_html = open('templates/admin.html', 'r', encoding='utf-8').read() \
|
||||
.replace('{{title}}', title) \
|
||||
.replace('{{description}}', description) \
|
||||
.replace('{{keywords}}', keywords)
|
||||
|
||||
error_ip_count = {}
|
||||
|
||||
|
||||
def delete_file(files):
|
||||
for file in files:
|
||||
os.remove('.' + file)
|
||||
if file['type'] != 'text':
|
||||
os.remove('.' + file['text'])
|
||||
|
||||
|
||||
def get_db():
|
||||
db = SessionLocal()
|
||||
try:
|
||||
yield db
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
|
||||
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):
|
||||
now = datetime.datetime.now()
|
||||
file_bytes = file.file.read()
|
||||
size = len(file_bytes)
|
||||
if size > file_size_limit:
|
||||
return size, '', '', ''
|
||||
path = f'./static/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
|
||||
f.write(file_bytes)
|
||||
return size, path[1:] + name, file.content_type, file.filename
|
||||
|
||||
|
||||
@app.get(f'/{admin_address}')
|
||||
@@ -71,25 +84,26 @@ async def admin():
|
||||
|
||||
|
||||
@app.post(f'/{admin_address}')
|
||||
async def admin_post(request: Request, db: Session = Depends(get_db)):
|
||||
async def admin_post(request: Request, s: AsyncSession = Depends(get_session)):
|
||||
if request.headers.get('pwd') == admin_password:
|
||||
codes = db.query(database.Codes).all()
|
||||
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)):
|
||||
async def admin_delete(request: Request, code: str, s: AsyncSession = Depends(get_session)):
|
||||
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()
|
||||
query = select(Codes).where(Codes.code == code)
|
||||
file = (await s.execute(query)).scalars().first()
|
||||
threading.Thread(target=delete_file, args=([{'type': file.type, 'text': file.text}],)).start()
|
||||
await s.delete(file)
|
||||
await s.commit()
|
||||
return {'code': 200, 'msg': '删除成功'}
|
||||
else:
|
||||
return {'code': 400, 'msg': '密码错误'}
|
||||
return {'code': 404, 'msg': '密码错误'}
|
||||
|
||||
|
||||
@app.get('/')
|
||||
@@ -97,60 +111,118 @@ 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'] >= error_count:
|
||||
if error_ip_count[ip]['time'] + datetime.timedelta(minutes=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('.' + info.text, 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'取件码错误,错误{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)):
|
||||
query = select(Codes).where(or_(Codes.exp_time < datetime.datetime.now(), Codes.count == 0))
|
||||
exps = (await s.execute(query)).scalars().all()
|
||||
threading.Thread(target=delete_file, args=([[{'type': old.type, 'text': old.text}] for old in exps],)).start()
|
||||
|
||||
exps_ids = [exp.id for exp in exps]
|
||||
query = delete(Codes).where(Codes.id.in_(exps_ids))
|
||||
await s.execute(query)
|
||||
await s.commit()
|
||||
|
||||
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:
|
||||
size, _text, _type, name = get_file_name(key, file.filename.split('.')[-1], file)
|
||||
if size > file_size_limit:
|
||||
return {'code': 404, 'msg': '文件过大'}
|
||||
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)
|
||||
@@ -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. 隐藏文件真实地址
|
||||
|
||||
### 取件
|
||||
|
||||

|
||||
@@ -43,6 +59,10 @@
|
||||

|
||||

|
||||
|
||||
## 部署教程
|
||||
|
||||
https://www.yuque.com/lxyo/work/zd0kvzy7fofx6w7v
|
||||
|
||||
## 部署方式
|
||||
|
||||
先拉取代码,然后修改main.py文件,将里面写了注释的可以根据需求改一下
|
||||
@@ -67,6 +87,10 @@ docker build --file Dockerfile --tag filecodebox .
|
||||
docker run -d -p 12345:12345 --name filecodebox filecodebox
|
||||
```
|
||||
|
||||
## 状态
|
||||
|
||||

|
||||
|
||||
## 免责声明
|
||||
|
||||
本项目开源仅供学习使用,不得用于商业用途以及任何违法用途,否则后果自负,与本人无关。
|
||||
本项目开源仅供学习使用,不得用于商业用途以及任何违法用途,否则后果自负,与本人无关。使用请保留项目地址谢谢。
|
||||
+5
-2
@@ -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
|
||||
+20
-7
@@ -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"> </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">
|
||||
|
||||
</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>次 数:${ file.count }</div>
|
||||
<div>到 期:${ file.exp_time.slice(0,19) }</div>
|
||||
<div v-if="file.name==='分享文本'">
|
||||
<span>内 容:${ file.text }</span>
|
||||
</div>
|
||||
@@ -39,7 +47,7 @@
|
||||
</el-card>
|
||||
</el-card>
|
||||
</el-col>
|
||||
<el-col :span="4"> </el-col>
|
||||
<el-col :xs="0" :sm="4" :md="4" :lg="4" :xl="4"> </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
@@ -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.1"/>
|
||||
<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>内 容:${ 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
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user