diff --git a/main.py b/main.py index 4c6b54b..366feb4 100644 --- a/main.py +++ b/main.py @@ -76,7 +76,7 @@ async def admin(): async def admin_post(s: AsyncSession = Depends(get_session)): query = select(Codes) codes = (await s.execute(query)).scalars().all() - return {'msg': '查询成功', 'data': codes} + return {'detail': '查询成功', 'data': codes} @app.delete(f'/{settings.ADMIN_ADDRESS}', dependencies=[Depends(admin_required)]) @@ -86,7 +86,7 @@ async def admin_delete(code: str, s: AsyncSession = Depends(get_session)): await storage.delete_file({'type': file.type, 'text': file.text}) await s.delete(file) await s.commit() - return {'msg': '删除成功'} + return {'detail': '删除成功'} @app.get('/') @@ -101,7 +101,7 @@ async def get_file(code: str, s: AsyncSession = Depends(get_session)): if not info: raise HTTPException(status_code=404, detail="口令不存在") if info.type == 'text': - return {'msg': '查询成功', 'data': info.text} + return {'detail': '查询成功', 'data': info.text} else: filepath = await storage.get_filepath(info.text) return FileResponse(filepath, filename=info.name) @@ -112,21 +112,19 @@ async def index(code: str, ip: str = Depends(ip_limit), s: AsyncSession = Depend query = select(Codes).where(Codes.code == code) info = (await s.execute(query)).scalars().first() if not info: - error_count = ip_limit.add_ip(ip) - raise HTTPException(status_code=404, detail=f"取件码错误,错误{settings.ERROR_COUNT - error_count}次将被禁止10分钟") + error_count = settings.ERROR_COUNT - ip_limit.add_ip(ip) + raise HTTPException(status_code=404, detail=f"取件码错误,错误{error_count}次将被禁止10分钟") if info.exp_time < datetime.datetime.now() or info.count == 0: await storage.delete_file({'type': info.type, 'text': info.text}) await s.delete(info) await s.commit() raise HTTPException(status_code=404, detail="取件码已过期,请联系寄件人") - count = info.count - 1 - query = update(Codes).where(Codes.id == info.id).values(count=count) - await s.execute(query) + 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 { - 'msg': '取件成功,请点击"取"查看', + 'detail': '取件成功,请点击"取"查看', 'data': {'type': info.type, 'text': info.text, 'name': info.name, 'code': info.code} } @@ -170,7 +168,7 @@ async def share(text: str = Form(default=None), style: str = Form(default='2'), s.add(info) await s.commit() return { - 'msg': '分享成功,请点击文件箱查看取件码', + 'detail': '分享成功,请点击文件箱查看取件码', 'data': {'code': code, 'key': key, 'name': name, 'text': _text} } diff --git a/static/assert/favicon.ico b/static/assert/favicon.ico new file mode 100644 index 0000000..0f16fa5 Binary files /dev/null and b/static/assert/favicon.ico differ diff --git a/storage.py b/storage.py index 3b43d24..851cbbb 100644 --- a/storage.py +++ b/storage.py @@ -31,8 +31,10 @@ class FileSystemStorage: return text async def delete_file(self, file): - filepath = self.DATA_ROOT / file['text'].lstrip(self.STATIC_URL + '/') - await asyncio.to_thread(os.remove, filepath) + # 是文件就删除 + if file['type'] != 'text': + filepath = self.DATA_ROOT / file['text'].lstrip(self.STATIC_URL + '/') + await asyncio.to_thread(os.remove, filepath) async def delete_files(self, files): for file in files: diff --git a/templates/admin.html b/templates/admin.html index 2050dbc..6d2be2b 100644 --- a/templates/admin.html +++ b/templates/admin.html @@ -6,11 +6,14 @@ content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> + 后台管理-{{title}} + +
@@ -57,8 +60,6 @@
- - + -
- +
+ - + + - 1 + 1 - 2 + 2 - 3 + 3 - 4 + 4 - 5 + 5 - 6 + 6 - 7 + 7 - 8 + 8 - 9 + 9 - + - 0 + 0 @@ -78,39 +82,49 @@ -
- - 次数 - 天数 - - - -
+ + + + + + + + + + 文件 + 文本 +
将文字、文件拖、粘贴到此处,或点击上传
天数<7或限制次数(24h后删除)
-
- 去取件 - 取件码 -
+ + +
+ 去取件 + 取件码 + 寄出去 +
- @@ -155,17 +169,17 @@
+ :src="qrcodeUrl(file)" alt="二维码" :alt="file.code">
+
+ FileCodeBox +
- - -