diff --git a/caricari/private.py b/caricari/private.py index c7a2997..f8e1423 100644 --- a/caricari/private.py +++ b/caricari/private.py @@ -70,21 +70,21 @@ async def upload( proxy: Annotated[ProxyInfo, Header()], request: Request, ): + assert data.file.filename is not None now = datetime.datetime.now() directory = f"{now.year}/{now.month}" if not Path(data.file.filename).suffix: raise HTTPException(status_code=400, detail="Invalid filename extension") - # XXX: normalize filename - # XXX: avoid duplicates + directory_absolute = Path(CONFIG["general"]["files"]) / directory + directory_absolute.mkdir(parents=True, exist_ok=True) temp = tempfile.NamedTemporaryFile( prefix=normalize_filename(Path(data.file.filename).stem), suffix=Path(data.file.filename).suffix, - dir=Path(CONFIG["general"]["files"]) / directory, + dir=directory_absolute, delete=False, ) temp.close() - print(temp.name) sha256 = hashlib.sha256() try: