Async I/O implemented

This commit is contained in:
2023-06-22 13:16:12 +02:00
parent db77f62459
commit 47435c6128
3 changed files with 28 additions and 17 deletions

View File

@@ -1,3 +1,4 @@
import aiofiles
import re
import pickle
from secrets import token_urlsafe
@@ -59,10 +60,10 @@ async def video_upload(
".".join(base_name) + f"_{int(datetime.now().timestamp())}." + extension
)
with open(
async with aiofiles.open(
path.join("data", "users", current_user.user, "albums", album, filename), "wb"
) as f:
f.write(await file.read())
await f.write(await file.read())
# Hashing and duplicates check should be here
@@ -112,8 +113,8 @@ async def video_get(
mime = Magic(mime=True).from_file(video_path)
with open(video_path, "rb") as f:
video_file = f.read()
with aiofiles.open(video_path, "rb") as f:
video_file = await f.read()
return Response(video_file, media_type=mime)