From 5543811c20478e66b7946a0d6d807bc1b1b091d2 Mon Sep 17 00:00:00 2001 From: lan Date: Thu, 15 Dec 2022 16:34:18 +0800 Subject: [PATCH] =?UTF-8?q?add:=E5=89=8D=E7=AB=AF=E5=88=A4=E6=96=AD?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=A4=A7=E5=B0=8F=20add:=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E5=88=A0=E9=99=A4=E8=BF=87=E6=9C=9F=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E9=97=B4=E9=9A=94=EF=BC=8C=E4=BF=AE=E5=A4=8D=E5=9B=A0=E9=97=B4?= =?UTF-8?q?=E9=9A=94=E8=BF=87=E7=9F=AD=E5=AF=BC=E8=87=B4=E8=BF=98=E6=B2=A1?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E6=96=87=E4=BB=B6=E5=B0=B1=E6=B2=A1=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 5 +++-- readme.md | 4 ++-- readme_en.md | 4 ++-- settings.py | 2 ++ templates/index.html | 11 +++++++++++ utils.py | 2 +- 6 files changed, 21 insertions(+), 7 deletions(-) diff --git a/main.py b/main.py index 4628a02..f783b20 100644 --- a/main.py +++ b/main.py @@ -39,7 +39,8 @@ async def startup(): index_html = open('templates/index.html', 'r', encoding='utf-8').read() \ .replace('{{title}}', settings.TITLE) \ .replace('{{description}}', settings.DESCRIPTION) \ - .replace('{{keywords}}', settings.KEYWORDS) + .replace('{{keywords}}', settings.KEYWORDS) \ + .replace("'{{fileSizeLimit}}'", str(settings.FILE_SIZE_LIMIT)) # 管理页面 admin_html = open('templates/admin.html', 'r', encoding='utf-8').read() \ .replace('{{title}}', settings.TITLE) \ @@ -116,7 +117,7 @@ async def index(code: str, ip: str = Depends(error_ip_limit), s: AsyncSession = if info.type != 'text': info.text = f'/select?code={code}' return { - 'detail': '取件成功,请点击"取"查看', + 'detail': f'取件成功,文件将在{settings.DELETE_EXPIRE_FILES_INTERVAL}分钟后删除', 'data': {'type': info.type, 'text': info.text, 'name': info.name, 'code': info.code} } diff --git a/readme.md b/readme.md index ff6266f..e85f7c8 100644 --- a/readme.md +++ b/readme.md @@ -104,8 +104,6 @@ DATABASE_URL=sqlite+aiosqlite:///database.db DATA_ROOT=./static # 静态文件夹URL STATIC_URL=/static -# 是否开启上传 -ENABLE_UPLOAD=true # 错误次数 ERROR_COUNT=5 # 错误限制分钟数 @@ -114,6 +112,8 @@ ERROR_MINUTE=10 UPLOAD_COUNT=60 # 上传限制分钟数 UPLOAD_MINUTE=1 +# 删除过期文件的间隔(秒) +DELETE_EXPIRE_FILES_INTERVAL=60 # 管理地址 ADMIN_ADDRESS=admin # 管理密码 diff --git a/readme_en.md b/readme_en.md index d9f906c..ed02f7e 100644 --- a/readme_en.md +++ b/readme_en.md @@ -113,8 +113,6 @@ DATABASE_URL=sqlite+aiosqlite:///database.db DATA_ROOT=./static # 静态文件夹URL STATIC_URL=/static -# 是否开启上传 -ENABLE_UPLOAD=true # 错误次数 ERROR_COUNT=5 # 错误限制分钟数 @@ -123,6 +121,8 @@ ERROR_MINUTE=10 UPLOAD_COUNT=60 # 上传限制分钟数 UPLOAD_MINUTE=1 +# 删除过期文件的间隔(秒) +DELETE_EXPIRE_FILES_INTERVAL=60 # 管理地址 ADMIN_ADDRESS=admin # 管理密码 diff --git a/settings.py b/settings.py index 21e9b47..80b3111 100644 --- a/settings.py +++ b/settings.py @@ -27,6 +27,8 @@ 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") # 管理密码 diff --git a/templates/index.html b/templates/index.html index c078cda..27eeae5 100644 --- a/templates/index.html +++ b/templates/index.html @@ -102,6 +102,7 @@ multiple style="margin: 1rem 0;" :data="uploadData" + :before-upload="beforeUpload" :headers="{'pwd':pwd}" :on-success="successUpload" :on-error="errorUpload" @@ -195,6 +196,7 @@ files: [], pageNum: 0, inputDisable: false, + fileSizeLimit: '{{fileSizeLimit}}', pwd: localStorage.getItem('pwd') || '', uploadData: { style: '2', @@ -322,6 +324,15 @@ type: 'error' }); }, + beforeUpload: function (file) { + if (file.size > this.fileSizeLimit) { + this.$message({ + message: `文件大小不能超过${this.fileSizeLimit/1024/1024}MB`, + type: 'error' + }); + return false + } + } } }) diff --git a/utils.py b/utils.py index fd648bd..fd10797 100644 --- a/utils.py +++ b/utils.py @@ -33,7 +33,7 @@ async def delete_expire_files(): query = delete(Codes).where(Codes.id.in_(exps_ids)) await s.execute(query) await s.commit() - await asyncio.sleep(random.randint(2, 2)) + await asyncio.sleep(settings.DELETE_EXPIRE_FILES_INTERVAL) async def get_code(s: AsyncSession):