allow optional file expire timestmap

This commit is contained in:
Hay1tsme 2024-05-23 17:36:22 -04:00
parent de51fcf887
commit 5fba7dd863

View File

@ -8,6 +8,7 @@ from random import choices
from string import ascii_letters, digits, punctuation from string import ascii_letters, digits, punctuation
from sys import argv from sys import argv
from typing import Dict from typing import Dict
from datetime import datetime
from logging.handlers import TimedRotatingFileHandler from logging.handlers import TimedRotatingFileHandler
import logging import logging
import coloredlogs import coloredlogs
@ -90,10 +91,20 @@ async def handle_file(request: Request) -> FileResponse:
if not info: if not info:
return Response(status_code=404) 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: if info.get("key", "") != key:
logger.info(f"Incorrect key for file {name} from {req_ip}") logger.info(f"Incorrect key for file {name} from {req_ip}")
return Response(status_code=404) return Response(status_code=404)
fpath: str = info.get("path", "") fpath: str = info.get("path", "")
if not fpath or not path.exists(fpath): if not fpath or not path.exists(fpath):
logger.info(f"File {name} does not exist at {fpath}") logger.info(f"File {name} does not exist at {fpath}")