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
@@ -130,7 +131,7 @@ async def photo_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())
@@ -266,8 +267,8 @@ if configGet("media_token_access") is True:
mime = Magic(mime=True).from_file(image_path)
with open(image_path, "rb") as f:
image_file = f.read()
async with aiofiles.open(image_path, "rb") as f:
image_file = await f.read()
return Response(image_file, media_type=mime)
@@ -293,8 +294,8 @@ async def photo_get(
mime = Magic(mime=True).from_file(image_path)
with open(image_path, "rb") as f:
image_file = f.read()
async with aiofiles.open(image_path, "rb") as f:
image_file = await f.read()
return Response(image_file, media_type=mime)