From c6c6bd7f0b532d514a3e71d05fc62aef3b4c1d2c Mon Sep 17 00:00:00 2001 From: boyska Date: Sat, 7 Dec 2024 19:40:27 +0100 Subject: [PATCH] create directory automatically --- caricari/private.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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: