Skip to content

Commit

Permalink
Merge pull request #191 from Jialin0502/master
Browse files Browse the repository at this point in the history
二维码修复和优化,安全性优化,描述优化。QR code repair and optimization, security optimization, description optimization.
  • Loading branch information
vastsa authored Jul 28, 2024
2 parents 6e910a6 + f430243 commit 3312ed7
Show file tree
Hide file tree
Showing 26 changed files with 60 additions and 45 deletions.
4 changes: 2 additions & 2 deletions apps/base/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ async def get_expire_info(expire_value: int, expire_style: str):
if int(settings.max_save_seconds) > 0:
max_timedelta = datetime.timedelta(seconds=settings.max_save_seconds)
detail = await max_save_times_desc(settings.max_save_seconds)
detail = f'保存时间超过限制,{detail[0]}'
detail = f'限制最长时间为 {detail[0]},可换用其他方式'
else:
max_timedelta = datetime.timedelta(days=7)
detail = '保存时间超过限制,最长保存时间:7天'
detail = '限制最长时间为 7天,可换用其他方式'
if expire_style == 'day':
if datetime.timedelta(days=expire_value) > max_timedelta:
raise HTTPException(status_code=403, detail=detail)
Expand Down
13 changes: 10 additions & 3 deletions apps/base/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
# 分享文本的API
@share_api.post('/text/', dependencies=[Depends(admin_required)])
async def share_text(text: str = Form(...), expire_value: int = Form(default=1, gt=0), expire_style: str = Form(default='day'), ip: str = Depends(ip_limit['upload'])):
# 获取大小
text_size = len(text.encode('utf-8'))
# 限制 222KB
max_txt_size = 222 * 1024 # 转换为字节
if text_size > max_txt_size:
raise HTTPException(status_code=403, detail=f'内容过多,建议采用文件形式')
# 获取过期信息
expired_at, expired_count, used_count, code = await get_expire_info(expire_value, expire_style)
# 创建一个新的FileCodes实例
Expand All @@ -47,9 +53,10 @@ async def share_text(text: str = Form(...), expire_value: int = Form(default=1,
@share_api.post('/file/', dependencies=[Depends(admin_required)])
async def share_file(expire_value: int = Form(default=1, gt=0), expire_style: str = Form(default='day'), file: UploadFile = File(...),
ip: str = Depends(ip_limit['upload'])):
# 检查文件大小是否超过限制
if file.size > int(settings.uploadSize):
raise HTTPException(status_code=403, detail=f'文件大小超过限制,最大为{settings.uploadSize}字节')
if file.size > settings.uploadSize:
# 转换为 MB 并格式化输出
max_size_mb = settings.uploadSize / (1024 * 1024)
raise HTTPException(status_code=403, detail=f'大小超过限制,最大为{max_size_mb:.2f} MB')
# 获取过期信息
if expire_style not in settings.expireStyle:
raise HTTPException(status_code=400, detail='过期时间类型错误')
Expand Down
6 changes: 3 additions & 3 deletions core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@

DEFAULT_CONFIG = {
'file_storage': 'local',
'name': '文件快递柜-FileCodeBox',
'name': '文件快递柜 - FileCodeBox',
'description': '开箱即用的文件快传系统',
'notify_title': '系统通知',
'notify_content': '欢迎使用FileCodeBox,本程序开源于 <a href="https://github.com/vastsa/FileCodeBox" target="_blank">Github</a> ,欢迎Star和Fork。',
'page_explain': '根据《中华人民共和国网络安全法》、《中华人民共和国刑法》、《中华人民共和国治安管理处罚法》等相关规定。 传播或存储违法、违规内容,会受到相关处罚,严重者将承担刑事责任。请勿上传非法文件,本站坚决配合相关部门,确保网络内容的安全,和谐,打造绿色网络环境。',
'notify_content': '欢迎使用 FileCodeBox,本程序开源于 <a href="https://github.com/vastsa/FileCodeBox" target="_blank">Github</a> ,欢迎Star和Fork。',
'page_explain': '请勿上传或分享违法内容。根据《中华人民共和国网络安全法》、《中华人民共和国刑法》、《中华人民共和国治安管理处罚法》等相关规定。 传播或存储违法、违规内容,会受到相关处罚,严重者将承担刑事责任。本站坚决配合相关部门,确保网络内容的安全,和谐,打造绿色网络环境。',
'keywords': 'FileCodeBox, 文件快递柜, 口令传送箱, 匿名口令分享文本, 文件',
's3_access_key_id': '',
's3_secret_access_key': '',
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Loading

0 comments on commit 3312ed7

Please sign in to comment.