From 4e9d859ab0aeb181f18267e92a888766d4185482 Mon Sep 17 00:00:00 2001 From: lan Date: Thu, 11 Jan 2024 17:51:05 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=8C=89=E5=8D=95=E6=AC=A1=E5=8F=96?= =?UTF-8?q?=E4=BB=B6=E8=BF=87=E6=9C=9F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/base/models.py | 2 +- apps/base/views.py | 8 ++++---- main.py | 2 -- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/apps/base/models.py b/apps/base/models.py index 61fe96b..ad08c79 100644 --- a/apps/base/models.py +++ b/apps/base/models.py @@ -33,7 +33,7 @@ class FileCodes(Model): return self.expired_at < await get_now() # 按次数 else: - return self.expired_count != -1 and self.expired_count == 0 + return self.expired_count <= 0 async def get_file_path(self): return f"{self.file_path}/{self.uuid_file_name}" diff --git a/apps/base/views.py b/apps/base/views.py index ba478c3..88d0803 100644 --- a/apps/base/views.py +++ b/apps/base/views.py @@ -77,14 +77,14 @@ async def share_file(expire_value: int = Form(default=1, gt=0), expire_style: st # 根据code获取文件 -async def get_code_file_by_code(code): +async def get_code_file_by_code(code, check=True): # 查询文件 file_code = await FileCodes.filter(code=code).first() # 检查文件是否存在 if not file_code: return False, '文件不存在' # 检查文件是否过期 - if await file_code.is_expired(): + if await file_code.is_expired() and check: return False, '文件已过期', return True, file_code @@ -143,9 +143,9 @@ async def download_file(key: str, code: str, ip: str = Depends(error_ip_limit)): # 添加IP到限制列表 error_ip_limit.add_ip(ip) # 获取文件 - has, file_code = await get_code_file_by_code(code) + has, file_code = await get_code_file_by_code(code, False) # 检查文件是否存在 - if not file_code: + if not has: # 返回API响应 return APIResponse(code=404, detail='文件不存在') # 如果文件是文本,返回文本内容,否则返回文件响应 diff --git a/main.py b/main.py index 1687906..5d73d40 100644 --- a/main.py +++ b/main.py @@ -3,13 +3,11 @@ # @File : main.py # @Software: PyCharm import asyncio -import os import re from fastapi import FastAPI from starlette.middleware.cors import CORSMiddleware from starlette.responses import HTMLResponse, FileResponse -from starlette.staticfiles import StaticFiles from tortoise.contrib.fastapi import register_tortoise from apps.base.views import share_api