Skip to content

Commit

Permalink
fix: 按单次取件过期问题
Browse files Browse the repository at this point in the history
  • Loading branch information
vastsa committed Jan 11, 2024
1 parent c6e0d32 commit 4e9d859
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
2 changes: 1 addition & 1 deletion apps/base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ async def is_expired(self):
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}"
Expand Down
8 changes: 4 additions & 4 deletions apps/base/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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='文件不存在')
# 如果文件是文本,返回文本内容,否则返回文件响应
Expand Down
2 changes: 0 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4e9d859

Please sign in to comment.