Skip to content

Commit 0ea6f98

Browse files
committed
fix: handle missing Content-Length header, fix docstring param name
- Default Content-Length to 0 when absent to avoid int(None) TypeError - Guard ETag skip with `and total_size` so 0==0 doesn't open a nonexistent file - Fix docstring: models_to_fetch → models to match actual param name
1 parent d1d4d93 commit 0ea6f98

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

nc_py_api/ex_app/integration_fastapi.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def fetch_models_task(nc: NextcloudApp, models: dict[str, dict], progress_init_s
160160
"""Use for cases when you want to define custom `/init` but still need to easy download models.
161161
162162
:param nc: NextcloudApp instance.
163-
:param models_to_fetch: Dictionary describing which models should be downloaded of the form:
163+
:param models: Dictionary describing which models should be downloaded of the form:
164164
.. code-block:: python
165165
{
166166
"model_url_1": {
@@ -222,12 +222,12 @@ def __fetch_model_as_file(
222222
break
223223
if not linked_etag:
224224
linked_etag = response.headers.get("X-Linked-ETag", response.headers.get("ETag", ""))
225-
total_size = int(response.headers.get("Content-Length"))
225+
total_size = int(response.headers.get("Content-Length", 0))
226226
try:
227227
existing_size = os.path.getsize(result_path)
228228
except OSError:
229229
existing_size = 0
230-
if linked_etag and total_size == existing_size:
230+
if linked_etag and total_size and total_size == existing_size:
231231
with builtins.open(result_path, "rb") as file:
232232
sha256_hash = hashlib.sha256()
233233
for byte_block in iter(lambda: file.read(4096), b""):

0 commit comments

Comments
 (0)