create directory automatically

This commit is contained in:
boyska 2024-12-07 19:40:27 +01:00
parent 67527ef585
commit c6c6bd7f0b

View file

@ -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: