update:自动删除过期文件
This commit is contained in:
@@ -12,7 +12,6 @@ from core.response import APIResponse
|
||||
|
||||
class IPRateLimit:
|
||||
def __init__(self, count, minutes):
|
||||
print(count, minutes)
|
||||
self.ips = {}
|
||||
self.count = count
|
||||
self.minutes = minutes
|
||||
|
||||
+2
-2
@@ -28,10 +28,10 @@ class FileCodes(Model):
|
||||
created_at: Optional[datetime] = fields.DatetimeField(auto_now_add=True, description='创建时间')
|
||||
|
||||
async def is_expired(self):
|
||||
if self.expired_at and (self.expired_count == -1 or self.used_count < self.expired_count):
|
||||
if self.expired_at and (self.expired_count == -1 or self.expired_count > 0):
|
||||
return self.expired_at < await get_now()
|
||||
else:
|
||||
return self.expired_count != -1 and self.used_count >= self.expired_count
|
||||
return self.expired_count != -1 and self.expired_count == 0
|
||||
|
||||
async def get_file_path(self):
|
||||
return f"{self.file_path}/{self.uuid_file_name}"
|
||||
|
||||
@@ -71,6 +71,7 @@ async def select_file(data: SelectFileModel, ip: str = Depends(error_ip_limit)):
|
||||
if await file_code.is_expired():
|
||||
return APIResponse(code=403, detail='文件已过期')
|
||||
file_code.used_count += 1
|
||||
file_code.expired_count -= 1
|
||||
await file_code.save()
|
||||
return APIResponse(detail={
|
||||
'code': file_code.code,
|
||||
|
||||
Reference in New Issue
Block a user