fix(api): Cap download speed to 20KB/s
This commit is contained in:
+6
-1
@@ -198,8 +198,13 @@ async def handle_download(
|
|||||||
|
|
||||||
book_buffer = book.dump()
|
book_buffer = book.dump()
|
||||||
|
|
||||||
|
async def iterfile():
|
||||||
|
while chunk := book_buffer.read(512 * 4): # 4 kb/s
|
||||||
|
await asyncio.sleep(0.1) # throttle download speed
|
||||||
|
yield chunk
|
||||||
|
|
||||||
return StreamingResponse(
|
return StreamingResponse(
|
||||||
book_buffer,
|
iterfile(),
|
||||||
media_type=media_type,
|
media_type=media_type,
|
||||||
headers={
|
headers={
|
||||||
"Content-Disposition": f'attachment; filename="{slugify(metadata["title"])}_{story_id}{"_images" if download_images else ""}.{format.value}"' # Thanks https://stackoverflow.com/a/72729058
|
"Content-Disposition": f'attachment; filename="{slugify(metadata["title"])}_{story_id}{"_images" if download_images else ""}.{format.value}"' # Thanks https://stackoverflow.com/a/72729058
|
||||||
|
|||||||
Reference in New Issue
Block a user