Fixing coding error around checking for empty chuunks

This commit is contained in:
Darren Burns
2024-08-09 11:00:50 +01:00
parent c89d2f5e3e
commit 2c7ee2abfc
8 changed files with 251 additions and 12 deletions

213
examples/screenshot.svg Normal file
View File

@@ -0,0 +1,213 @@
<svg class="rich-terminal" viewBox="0 0 1653 1001.5999999999999" xmlns="http://www.w3.org/2000/svg">
<!-- Generated with Rich https://www.textualize.io -->
<style>
@font-face {
font-family: "Fira Code";
src: local("FiraCode-Regular"),
url("https://cdnjs.cloudflare.com/ajax/libs/firacode/6.2.0/woff2/FiraCode-Regular.woff2") format("woff2"),
url("https://cdnjs.cloudflare.com/ajax/libs/firacode/6.2.0/woff/FiraCode-Regular.woff") format("woff");
font-style: normal;
font-weight: 400;
}
@font-face {
font-family: "Fira Code";
src: local("FiraCode-Bold"),
url("https://cdnjs.cloudflare.com/ajax/libs/firacode/6.2.0/woff2/FiraCode-Bold.woff2") format("woff2"),
url("https://cdnjs.cloudflare.com/ajax/libs/firacode/6.2.0/woff/FiraCode-Bold.woff") format("woff");
font-style: bold;
font-weight: 700;
}
.terminal-1887221314-matrix {
font-family: Fira Code, monospace;
font-size: 20px;
line-height: 24.4px;
font-variant-east-asian: full-width;
}
.terminal-1887221314-title {
font-size: 18px;
font-weight: bold;
font-family: arial;
}
.terminal-1887221314-r1 { fill: #05080f }
.terminal-1887221314-r2 { fill: #e1e1e1 }
.terminal-1887221314-r3 { fill: #c5c8c6 }
.terminal-1887221314-r4 { fill: #1e2226;font-weight: bold }
.terminal-1887221314-r5 { fill: #35393d }
</style>
<defs>
<clipPath id="terminal-1887221314-clip-terminal">
<rect x="0" y="0" width="1633.8" height="950.5999999999999" />
</clipPath>
<clipPath id="terminal-1887221314-line-0">
<rect x="0" y="1.5" width="1634.8" height="24.65"/>
</clipPath>
<clipPath id="terminal-1887221314-line-1">
<rect x="0" y="25.9" width="1634.8" height="24.65"/>
</clipPath>
<clipPath id="terminal-1887221314-line-2">
<rect x="0" y="50.3" width="1634.8" height="24.65"/>
</clipPath>
<clipPath id="terminal-1887221314-line-3">
<rect x="0" y="74.7" width="1634.8" height="24.65"/>
</clipPath>
<clipPath id="terminal-1887221314-line-4">
<rect x="0" y="99.1" width="1634.8" height="24.65"/>
</clipPath>
<clipPath id="terminal-1887221314-line-5">
<rect x="0" y="123.5" width="1634.8" height="24.65"/>
</clipPath>
<clipPath id="terminal-1887221314-line-6">
<rect x="0" y="147.9" width="1634.8" height="24.65"/>
</clipPath>
<clipPath id="terminal-1887221314-line-7">
<rect x="0" y="172.3" width="1634.8" height="24.65"/>
</clipPath>
<clipPath id="terminal-1887221314-line-8">
<rect x="0" y="196.7" width="1634.8" height="24.65"/>
</clipPath>
<clipPath id="terminal-1887221314-line-9">
<rect x="0" y="221.1" width="1634.8" height="24.65"/>
</clipPath>
<clipPath id="terminal-1887221314-line-10">
<rect x="0" y="245.5" width="1634.8" height="24.65"/>
</clipPath>
<clipPath id="terminal-1887221314-line-11">
<rect x="0" y="269.9" width="1634.8" height="24.65"/>
</clipPath>
<clipPath id="terminal-1887221314-line-12">
<rect x="0" y="294.3" width="1634.8" height="24.65"/>
</clipPath>
<clipPath id="terminal-1887221314-line-13">
<rect x="0" y="318.7" width="1634.8" height="24.65"/>
</clipPath>
<clipPath id="terminal-1887221314-line-14">
<rect x="0" y="343.1" width="1634.8" height="24.65"/>
</clipPath>
<clipPath id="terminal-1887221314-line-15">
<rect x="0" y="367.5" width="1634.8" height="24.65"/>
</clipPath>
<clipPath id="terminal-1887221314-line-16">
<rect x="0" y="391.9" width="1634.8" height="24.65"/>
</clipPath>
<clipPath id="terminal-1887221314-line-17">
<rect x="0" y="416.3" width="1634.8" height="24.65"/>
</clipPath>
<clipPath id="terminal-1887221314-line-18">
<rect x="0" y="440.7" width="1634.8" height="24.65"/>
</clipPath>
<clipPath id="terminal-1887221314-line-19">
<rect x="0" y="465.1" width="1634.8" height="24.65"/>
</clipPath>
<clipPath id="terminal-1887221314-line-20">
<rect x="0" y="489.5" width="1634.8" height="24.65"/>
</clipPath>
<clipPath id="terminal-1887221314-line-21">
<rect x="0" y="513.9" width="1634.8" height="24.65"/>
</clipPath>
<clipPath id="terminal-1887221314-line-22">
<rect x="0" y="538.3" width="1634.8" height="24.65"/>
</clipPath>
<clipPath id="terminal-1887221314-line-23">
<rect x="0" y="562.7" width="1634.8" height="24.65"/>
</clipPath>
<clipPath id="terminal-1887221314-line-24">
<rect x="0" y="587.1" width="1634.8" height="24.65"/>
</clipPath>
<clipPath id="terminal-1887221314-line-25">
<rect x="0" y="611.5" width="1634.8" height="24.65"/>
</clipPath>
<clipPath id="terminal-1887221314-line-26">
<rect x="0" y="635.9" width="1634.8" height="24.65"/>
</clipPath>
<clipPath id="terminal-1887221314-line-27">
<rect x="0" y="660.3" width="1634.8" height="24.65"/>
</clipPath>
<clipPath id="terminal-1887221314-line-28">
<rect x="0" y="684.7" width="1634.8" height="24.65"/>
</clipPath>
<clipPath id="terminal-1887221314-line-29">
<rect x="0" y="709.1" width="1634.8" height="24.65"/>
</clipPath>
<clipPath id="terminal-1887221314-line-30">
<rect x="0" y="733.5" width="1634.8" height="24.65"/>
</clipPath>
<clipPath id="terminal-1887221314-line-31">
<rect x="0" y="757.9" width="1634.8" height="24.65"/>
</clipPath>
<clipPath id="terminal-1887221314-line-32">
<rect x="0" y="782.3" width="1634.8" height="24.65"/>
</clipPath>
<clipPath id="terminal-1887221314-line-33">
<rect x="0" y="806.7" width="1634.8" height="24.65"/>
</clipPath>
<clipPath id="terminal-1887221314-line-34">
<rect x="0" y="831.1" width="1634.8" height="24.65"/>
</clipPath>
<clipPath id="terminal-1887221314-line-35">
<rect x="0" y="855.5" width="1634.8" height="24.65"/>
</clipPath>
<clipPath id="terminal-1887221314-line-36">
<rect x="0" y="879.9" width="1634.8" height="24.65"/>
</clipPath>
<clipPath id="terminal-1887221314-line-37">
<rect x="0" y="904.3" width="1634.8" height="24.65"/>
</clipPath>
</defs>
<rect fill="#292929" stroke="rgba(255,255,255,0.35)" stroke-width="1" x="1" y="1" width="1651" height="999.6" rx="8"/><text class="terminal-1887221314-title" fill="#c5c8c6" text-anchor="middle" x="825" y="27">ScreenshotApp</text>
<g transform="translate(26,22)">
<circle cx="0" cy="0" r="7" fill="#ff5f57"/>
<circle cx="22" cy="0" r="7" fill="#febc2e"/>
<circle cx="44" cy="0" r="7" fill="#28c840"/>
</g>
<g transform="translate(9, 41)" clip-path="url(#terminal-1887221314-clip-terminal)">
<rect fill="#1e2226" x="0" y="1.5" width="195.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="195.2" y="1.5" width="1439.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#a3a4a4" x="0" y="25.9" width="183" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e2226" x="183" y="25.9" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="195.2" y="25.9" width="1439.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e2226" x="0" y="50.3" width="195.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="195.2" y="50.3" width="1439.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="74.7" width="1634.8" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="99.1" width="1634.8" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="123.5" width="1634.8" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="147.9" width="1634.8" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="172.3" width="1634.8" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="196.7" width="1634.8" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="221.1" width="1634.8" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="245.5" width="1634.8" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="269.9" width="1634.8" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="294.3" width="1634.8" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="318.7" width="1634.8" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="343.1" width="1634.8" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="367.5" width="1634.8" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="391.9" width="1634.8" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="416.3" width="1634.8" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="440.7" width="1634.8" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="465.1" width="1634.8" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="489.5" width="1634.8" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="513.9" width="1634.8" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="538.3" width="1634.8" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="562.7" width="1634.8" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="587.1" width="1634.8" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="611.5" width="1634.8" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="635.9" width="1634.8" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="660.3" width="1634.8" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="684.7" width="1634.8" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="709.1" width="1634.8" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="733.5" width="1634.8" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="757.9" width="1634.8" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="782.3" width="1634.8" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="806.7" width="1634.8" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="831.1" width="1634.8" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="855.5" width="1634.8" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="879.9" width="1634.8" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="904.3" width="1634.8" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="928.7" width="1634.8" height="24.65" shape-rendering="crispEdges"/>
<g class="terminal-1887221314-matrix">
<text class="terminal-1887221314-r1" x="0" y="20" textLength="195.2" clip-path="url(#terminal-1887221314-line-0)">▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔</text><text class="terminal-1887221314-r3" x="1634.8" y="20" textLength="12.2" clip-path="url(#terminal-1887221314-line-0)">
</text><text class="terminal-1887221314-r4" x="0" y="44.4" textLength="183" clip-path="url(#terminal-1887221314-line-1)">&#160;Hello,&#160;World!&#160;</text><text class="terminal-1887221314-r3" x="1634.8" y="44.4" textLength="12.2" clip-path="url(#terminal-1887221314-line-1)">
</text><text class="terminal-1887221314-r5" x="0" y="68.8" textLength="195.2" clip-path="url(#terminal-1887221314-line-2)">▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁</text><text class="terminal-1887221314-r3" x="1634.8" y="68.8" textLength="12.2" clip-path="url(#terminal-1887221314-line-2)">
</text><text class="terminal-1887221314-r3" x="1634.8" y="93.2" textLength="12.2" clip-path="url(#terminal-1887221314-line-3)">
</text><text class="terminal-1887221314-r3" x="1634.8" y="117.6" textLength="12.2" clip-path="url(#terminal-1887221314-line-4)">
</text><text class="terminal-1887221314-r3" x="1634.8" y="142" textLength="12.2" clip-path="url(#terminal-1887221314-line-5)">
</text><text class="terminal-1887221314-r3" x="1634.8" y="166.4" textLength="12.2" clip-path="url(#terminal-1887221314-line-6)">
</text><text class="terminal-1887221314-r3" x="1634.8" y="190.8" textLength="12.2" clip-path="url(#terminal-1887221314-line-7)">
</text><text class="terminal-1887221314-r3" x="1634.8" y="215.2" textLength="12.2" clip-path="url(#terminal-1887221314-line-8)">
</text><text class="terminal-1887221314-r3" x="1634.8" y="239.6" textLength="12.2" clip-path="url(#terminal-1887221314-line-9)">
</text><text class="terminal-1887221314-r3" x="1634.8" y="264" textLength="12.2" clip-path="url(#terminal-1887221314-line-10)">
</text><text class="terminal-1887221314-r3" x="1634.8" y="288.4" textLength="12.2" clip-path="url(#terminal-1887221314-line-11)">
</text><text class="terminal-1887221314-r3" x="1634.8" y="312.8" textLength="12.2" clip-path="url(#terminal-1887221314-line-12)">
</text><text class="terminal-1887221314-r3" x="1634.8" y="337.2" textLength="12.2" clip-path="url(#terminal-1887221314-line-13)">
</text><text class="terminal-1887221314-r3" x="1634.8" y="361.6" textLength="12.2" clip-path="url(#terminal-1887221314-line-14)">
</text><text class="terminal-1887221314-r3" x="1634.8" y="386" textLength="12.2" clip-path="url(#terminal-1887221314-line-15)">
</text><text class="terminal-1887221314-r3" x="1634.8" y="410.4" textLength="12.2" clip-path="url(#terminal-1887221314-line-16)">
</text><text class="terminal-1887221314-r3" x="1634.8" y="434.8" textLength="12.2" clip-path="url(#terminal-1887221314-line-17)">
</text><text class="terminal-1887221314-r3" x="1634.8" y="459.2" textLength="12.2" clip-path="url(#terminal-1887221314-line-18)">
</text><text class="terminal-1887221314-r3" x="1634.8" y="483.6" textLength="12.2" clip-path="url(#terminal-1887221314-line-19)">
</text><text class="terminal-1887221314-r3" x="1634.8" y="508" textLength="12.2" clip-path="url(#terminal-1887221314-line-20)">
</text><text class="terminal-1887221314-r3" x="1634.8" y="532.4" textLength="12.2" clip-path="url(#terminal-1887221314-line-21)">
</text><text class="terminal-1887221314-r3" x="1634.8" y="556.8" textLength="12.2" clip-path="url(#terminal-1887221314-line-22)">
</text><text class="terminal-1887221314-r3" x="1634.8" y="581.2" textLength="12.2" clip-path="url(#terminal-1887221314-line-23)">
</text><text class="terminal-1887221314-r3" x="1634.8" y="605.6" textLength="12.2" clip-path="url(#terminal-1887221314-line-24)">
</text><text class="terminal-1887221314-r3" x="1634.8" y="630" textLength="12.2" clip-path="url(#terminal-1887221314-line-25)">
</text><text class="terminal-1887221314-r3" x="1634.8" y="654.4" textLength="12.2" clip-path="url(#terminal-1887221314-line-26)">
</text><text class="terminal-1887221314-r3" x="1634.8" y="678.8" textLength="12.2" clip-path="url(#terminal-1887221314-line-27)">
</text><text class="terminal-1887221314-r3" x="1634.8" y="703.2" textLength="12.2" clip-path="url(#terminal-1887221314-line-28)">
</text><text class="terminal-1887221314-r3" x="1634.8" y="727.6" textLength="12.2" clip-path="url(#terminal-1887221314-line-29)">
</text><text class="terminal-1887221314-r3" x="1634.8" y="752" textLength="12.2" clip-path="url(#terminal-1887221314-line-30)">
</text><text class="terminal-1887221314-r3" x="1634.8" y="776.4" textLength="12.2" clip-path="url(#terminal-1887221314-line-31)">
</text><text class="terminal-1887221314-r3" x="1634.8" y="800.8" textLength="12.2" clip-path="url(#terminal-1887221314-line-32)">
</text><text class="terminal-1887221314-r3" x="1634.8" y="825.2" textLength="12.2" clip-path="url(#terminal-1887221314-line-33)">
</text><text class="terminal-1887221314-r3" x="1634.8" y="849.6" textLength="12.2" clip-path="url(#terminal-1887221314-line-34)">
</text><text class="terminal-1887221314-r3" x="1634.8" y="874" textLength="12.2" clip-path="url(#terminal-1887221314-line-35)">
</text><text class="terminal-1887221314-r3" x="1634.8" y="898.4" textLength="12.2" clip-path="url(#terminal-1887221314-line-36)">
</text><text class="terminal-1887221314-r3" x="1634.8" y="922.8" textLength="12.2" clip-path="url(#terminal-1887221314-line-37)">
</text>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 16 KiB

View File

@@ -9,7 +9,7 @@ dependencies = [
"aiohttp>=3.9.5", "aiohttp>=3.9.5",
"aiohttp-jinja2>=1.6", "aiohttp-jinja2>=1.6",
"jinja2>=3.1.4", "jinja2>=3.1.4",
"textual>=0.66.0", "textual[syntax] @ file:///Users/darrenburns/Code/textual-serve/../textual",
"msgpack>=1.0.8", "msgpack>=1.0.8",
"rich", "rich",
"msgpack-types>=0.3.0", "msgpack-types>=0.3.0",

View File

@@ -58,13 +58,17 @@ mdit-py-plugins==0.4.1
mdurl==0.1.2 mdurl==0.1.2
# via markdown-it-py # via markdown-it-py
msgpack==1.0.8 msgpack==1.0.8
# via textual
# via textual-dev # via textual-dev
# via textual-serve # via textual-serve
msgpack-types==0.3.0 msgpack-types==0.3.0
# via textual
# via textual-serve # via textual-serve
multidict==6.0.5 multidict==6.0.5
# via aiohttp # via aiohttp
# via yarl # via yarl
platformdirs==4.2.2
# via textual
pygments==2.18.0 pygments==2.18.0
# via rich # via rich
rich==13.7.1 rich==13.7.1
@@ -73,10 +77,15 @@ rich==13.7.1
sniffio==1.3.1 sniffio==1.3.1
# via anyio # via anyio
# via httpx # via httpx
textual==0.75.1 textual @ file:///Users/darrenburns/Code/textual-serve/../textual
# via textual-dev # via textual-dev
# via textual-serve # via textual-serve
textual-dev==1.5.1 textual-dev==1.5.1
tree-sitter==0.20.4
# via textual
# via tree-sitter-languages
tree-sitter-languages==1.10.2
# via textual
typing-extensions==4.12.2 typing-extensions==4.12.2
# via anyio # via anyio
# via rich # via rich

View File

@@ -41,19 +41,28 @@ mdit-py-plugins==0.4.1
mdurl==0.1.2 mdurl==0.1.2
# via markdown-it-py # via markdown-it-py
msgpack==1.0.8 msgpack==1.0.8
# via textual
# via textual-serve # via textual-serve
msgpack-types==0.3.0 msgpack-types==0.3.0
# via textual
# via textual-serve # via textual-serve
multidict==6.0.5 multidict==6.0.5
# via aiohttp # via aiohttp
# via yarl # via yarl
platformdirs==4.2.2
# via textual
pygments==2.18.0 pygments==2.18.0
# via rich # via rich
rich==13.7.1 rich==13.7.1
# via textual # via textual
# via textual-serve # via textual-serve
textual==0.75.1 textual @ file:///Users/darrenburns/Code/textual-serve/../textual
# via textual-serve # via textual-serve
tree-sitter==0.20.4
# via textual
# via tree-sitter-languages
tree-sitter-languages==1.10.2
# via textual
typing-extensions==4.12.2 typing-extensions==4.12.2
# via rich # via rich
# via textual # via textual

View File

@@ -20,7 +20,6 @@ from textual_serve.download_manager import DownloadManager
log = logging.getLogger("textual-serve") log = logging.getLogger("textual-serve")
@rich.repr.auto
class AppService: class AppService:
"""Creates and manages a single Textual app subprocess. """Creates and manages a single Textual app subprocess.
@@ -347,8 +346,9 @@ class AppService:
payload: Encoded packed data. payload: Encoded packed data.
""" """
unpacked = msgpack.unpackb(payload) unpacked = msgpack.unpackb(payload)
if unpacked[0] == "deliver_file_chunk": if unpacked[0] == "deliver_chunk":
# If we receive a chunk, hand it to the download manager to # If we receive a chunk, hand it to the download manager to
# handle distribution to the browser. # handle distribution to the browser.
_, delivery_key, chunk_bytes = unpacked _, delivery_key, chunk_bytes = unpacked
await self._download_manager.chunk_received(self, delivery_key, chunk_bytes) print("unpacked chunk:" + str(unpacked))
await self._download_manager.chunk_received(delivery_key, chunk_bytes)

View File

@@ -115,14 +115,16 @@ class DownloadManager:
) )
chunk = await incoming_chunks.get() chunk = await incoming_chunks.get()
if chunk is None: if not chunk:
# The app process has finished sending the file. # The app process has finished sending the file.
incoming_chunks.task_done() incoming_chunks.task_done()
raise StopAsyncIteration break
else: else:
incoming_chunks.task_done() incoming_chunks.task_done()
yield chunk yield chunk
await asyncio.sleep(0.01)
async def chunk_received(self, delivery_key: str, chunk: bytes) -> None: async def chunk_received(self, delivery_key: str, chunk: bytes) -> None:
"""Handle a chunk received from the app service for a download. """Handle a chunk received from the app service for a download.

View File

@@ -154,6 +154,7 @@ class Server:
async def handle_download(self, request: web.Request) -> web.StreamResponse: async def handle_download(self, request: web.Request) -> web.StreamResponse:
"""Handle a download request.""" """Handle a download request."""
print("in download handler")
key = request.match_info["key"] key = request.match_info["key"]
try: try:
@@ -161,7 +162,7 @@ class Server:
except KeyError: except KeyError:
raise web.HTTPNotFound(text=f"Download with key {key!r} not found") raise web.HTTPNotFound(text=f"Download with key {key!r} not found")
download_stream = self.download_manager.download(key) print("download_meta:", download_meta)
response = web.StreamResponse() response = web.StreamResponse()
response.headers["Content-Type"] = "application/octet-stream" response.headers["Content-Type"] = "application/octet-stream"
@@ -169,13 +170,18 @@ class Server:
"attachment" if download_meta.open_method == "download" else "inline" "attachment" if download_meta.open_method == "download" else "inline"
) )
response.headers["Content-Disposition"] = ( response.headers["Content-Disposition"] = (
f"{disposition}; filename={download_meta.file_name}" f"inline; filename={download_meta.file_name}"
) )
await response.prepare(request) await response.prepare(request)
async for chunk in download_stream: async for chunk in self.download_manager.download(key):
print("writing chunk to response stream")
await response.write(chunk) await response.write(chunk)
await response.drain()
await asyncio.sleep(0.01)
print("=== writing eof")
await response.write_eof() await response.write_eof()
return response return response

File diff suppressed because one or more lines are too long