fix: 按单次取件过期问题

This commit is contained in:
lan
2024-01-11 17:51:05 +08:00
parent 87fb5ae7da
commit c6bdc53f5d
3 changed files with 5 additions and 7 deletions
+1 -1
View File
@@ -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}"
+4 -4
View File
@@ -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='文件不存在')
# 如果文件是文本,返回文本内容,否则返回文件响应
-2
View File
@@ -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