allow optional file expire timestmap
This commit is contained in:
parent
de51fcf887
commit
5fba7dd863
13
index.py
13
index.py
@ -8,6 +8,7 @@ from random import choices
|
||||
from string import ascii_letters, digits, punctuation
|
||||
from sys import argv
|
||||
from typing import Dict
|
||||
from datetime import datetime
|
||||
from logging.handlers import TimedRotatingFileHandler
|
||||
import logging
|
||||
import coloredlogs
|
||||
@ -90,10 +91,20 @@ async def handle_file(request: Request) -> FileResponse:
|
||||
if not info:
|
||||
return Response(status_code=404)
|
||||
|
||||
expire = info.get("expire", None)
|
||||
if expire and expire <= int(datetime.now().timestamp()):
|
||||
logger.info(f"File {name} expired on {expire}")
|
||||
flist.pop(name)
|
||||
|
||||
with open("flist.json", "w") as f:
|
||||
json.dump(flist, f)
|
||||
|
||||
return Response(status_code=404)
|
||||
|
||||
if info.get("key", "") != key:
|
||||
logger.info(f"Incorrect key for file {name} from {req_ip}")
|
||||
return Response(status_code=404)
|
||||
|
||||
|
||||
fpath: str = info.get("path", "")
|
||||
if not fpath or not path.exists(fpath):
|
||||
logger.info(f"File {name} does not exist at {fpath}")
|
||||
|
Loading…
Reference in New Issue
Block a user