Files zipping update
This commit is contained in:
@@ -62,7 +62,7 @@ def configGet(key: str, *args: str) -> Any:
|
||||
this_key = this_key[dict_key]
|
||||
return this_key[key]
|
||||
|
||||
def saveFile(filebytes: bytes) -> Tuple[str, str]:
|
||||
def saveFile(filebytes: bytes, filename: Union[str, None] = None, dirname: Union[str, None] = None) -> Tuple[str, str]:
|
||||
"""Save some bytedata into random file and return its ID
|
||||
|
||||
### Args:
|
||||
@@ -71,8 +71,11 @@ def saveFile(filebytes: bytes) -> Tuple[str, str]:
|
||||
### Returns:
|
||||
* `Tuple[str, str]`: Tuple where first item is an ID and the second is an absolute path to file
|
||||
"""
|
||||
makedirs(path.join(configGet("data", "locations"), "files"), exist_ok=True)
|
||||
filename = str(uuid4())
|
||||
with open(path.join(configGet("data", "locations"), "files", filename), "wb") as file:
|
||||
pathlist = [configGet("data", "locations"), "files"]
|
||||
if dirname is not None:
|
||||
pathlist.append(dirname)
|
||||
makedirs(path.join(pathlist), exist_ok=True)
|
||||
filename = str(uuid4()) if filename is None else filename
|
||||
with open(path.join(pathlist+[filename], "wb")) as file:
|
||||
file.write(filebytes)
|
||||
return filename, path.join(configGet("data", "locations"), "files", filename)
|
||||
return filename, path.join(pathlist+[filename])
|
Reference in New Issue
Block a user