create directory automatically
This commit is contained in:
parent
67527ef585
commit
c6c6bd7f0b
1 changed files with 4 additions and 4 deletions
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue