|
@@ -24,12 +24,13 @@ def save(content: bytes, root='app/rest/static') -> str:
|
|
|
f.write(content)
|
|
|
return _b32
|
|
|
|
|
|
-def save_upload(content: BufferedRandom, root='app/rest/static') -> str:
|
|
|
+def save_upload(name: str, content: BufferedRandom, root='app/rest/static') -> str:
|
|
|
tmpdir = '/tmp/upload'
|
|
|
try:
|
|
|
os.mkdir(tmpdir, mode=0o700, dir_fd=None)
|
|
|
except FileExistsError:
|
|
|
pass
|
|
|
+
|
|
|
unique = uuid4()
|
|
|
fd = os.open(f'{tmpdir}/{unique.hex}', os.O_WRONLY | os.O_TRUNC | os.O_CREAT, 0o600)
|
|
|
with open(fd, "wb") as f:
|
|
@@ -37,9 +38,7 @@ def save_upload(content: BufferedRandom, root='app/rest/static') -> str:
|
|
|
seg = content.read(1024)
|
|
|
f.write(seg)
|
|
|
|
|
|
- fd = os.open(f'{tmpdir}/{unique.hex}', os.O_RDONLY, 0o600)
|
|
|
- with open(fd, "rb") as f:
|
|
|
- f.seek(0)
|
|
|
+ with open(f'{tmpdir}/{unique.hex}', "rb") as f:
|
|
|
_blake = blake2b(usedforsecurity=False, digest_size=DIGEST_SIZE_BYTES, person='upload'.encode('utf-8'))
|
|
|
while f.peek(1):
|
|
|
_blake.update(f.read(1024))
|
|
@@ -54,6 +53,9 @@ def save_upload(content: BufferedRandom, root='app/rest/static') -> str:
|
|
|
pass
|
|
|
|
|
|
os.replace(f'{tmpdir}/{unique.hex}', f'{directory}/{_b32}.file')
|
|
|
-
|
|
|
+ fd = os.open(f'{directory}/{_b32}.name', os.O_WRONLY | os.O_TRUNC | os.O_CREAT, 0o600)
|
|
|
+ with open(fd, "w") as f:
|
|
|
+ f.write(name)
|
|
|
+
|
|
|
return _b32
|
|
|
|