mirror of
https://github.com/flibusta-apps/fb2converter_server.git
synced 2025-12-06 15:05:37 +01:00
Refactoring
This commit is contained in:
@@ -37,6 +37,7 @@ async def convert(
|
||||
temp_filename = str(temp_uuid) + ".fb2"
|
||||
converted_temp_filename = str(temp_uuid) + "." + format_lower
|
||||
|
||||
try:
|
||||
async with aiofiles.open(temp_filename, "wb") as f:
|
||||
while content := await file.read(1024):
|
||||
if isinstance(content, str):
|
||||
@@ -55,7 +56,7 @@ async def convert(
|
||||
)
|
||||
|
||||
_, stderr = await proc.communicate()
|
||||
|
||||
finally:
|
||||
await aiofiles.os.remove(temp_filename)
|
||||
|
||||
if proc.returncode != 0 or len(stderr) != 0:
|
||||
@@ -69,10 +70,11 @@ async def convert(
|
||||
)
|
||||
|
||||
async def result_iterator() -> AsyncIterator[bytes]:
|
||||
try:
|
||||
async with aiofiles.open(converted_temp_filename, "rb") as f:
|
||||
while data := await f.read(2048):
|
||||
yield data
|
||||
|
||||
finally:
|
||||
await aiofiles.os.remove(converted_temp_filename)
|
||||
|
||||
return StreamingResponse(result_iterator())
|
||||
|
||||
Reference in New Issue
Block a user