瀏覽代碼

code review

Falko Schindler 1 年之前
父節點
當前提交
9bff408cf2
共有 3 個文件被更改,包括 10 次插入4 次删除
  1. 3 2
      nicegui/air.py
  2. 1 1
      nicegui/app/range_response.py
  3. 6 1
      nicegui/templates/index.html

+ 3 - 2
nicegui/air.py

@@ -12,12 +12,13 @@ import socketio.exceptions
 
 from . import background_tasks, core
 from .client import Client
+from .dataclasses import KWONLY_SLOTS
 from .logging import log
 
 RELAY_HOST = 'https://on-air.nicegui.io/'
 
 
-@dataclass
+@dataclass(**KWONLY_SLOTS)
 class Stream:
     data: AsyncIterator[bytes]
     response: httpx.Response
@@ -76,7 +77,7 @@ class Air:
                 headers=headers,
             )
             response = await self.streaming_client.send(request, stream=True)
-            stream_id = uuid4().hex
+            stream_id = str(uuid4())
             self.streams[stream_id] = Stream(data=response.aiter_bytes(), response=response)
             return {
                 'status_code': response.status_code,

+ 1 - 1
nicegui/app/range_response.py

@@ -23,7 +23,7 @@ def get_range_response(file: Path, request: Request, chunk_size: int) -> Respons
         return Response(status_code=304)  # Not Modified
     headers = {
         'E-Tag': e_tag,
-        'Last-Modified': last_modified_time.strftime("%a, %d %b %Y %H:%M:%S GMT")
+        'Last-Modified': last_modified_time.strftime(r'%a, %d %b %Y %H:%M:%S GMT'),
     }
     range_header = request.headers.get('range')
     media_type = mimetypes.guess_type(str(file))[0] or 'application/octet-stream'

+ 6 - 1
nicegui/templates/index.html

@@ -214,7 +214,12 @@
 
       function download(src, filename) {
         const anchor = document.createElement("a");
-        anchor.href = typeof src === "string" ? "{{ prefix | safe }}" + src : URL.createObjectURL(new Blob([src]));
+        if (typeof src === "string") {
+          anchor.href = src.startsWith("/") ? "{{ prefix | safe }}" + src : src;
+        }
+        else {
+          anchor.href = URL.createObjectURL(new Blob([src]))
+        }
         anchor.target = "_blank";
         anchor.download = filename || "";
         document.body.appendChild(anchor);