htx-cli 0.1.4__tar.gz → 0.1.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: htx-cli
3
- Version: 0.1.4
3
+ Version: 0.1.5
4
4
  Summary: htx-cli command-line client for the Disk backend API
5
5
  Requires-Python: >=3.9
6
6
  Description-Content-Type: text/markdown
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "htx-cli"
7
- version = "0.1.4"
7
+ version = "0.1.5"
8
8
  description = "htx-cli command-line client for the Disk backend API"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.9"
@@ -1,3 +1,3 @@
1
1
  __all__ = ["__version__"]
2
2
 
3
- __version__ = "0.1.4"
3
+ __version__ = "0.1.5"
@@ -4,7 +4,7 @@ from dataclasses import dataclass
4
4
  from pathlib import Path
5
5
  import time
6
6
  from typing import Any, Callable, Dict, Optional
7
- from urllib.parse import urljoin
7
+ from urllib.parse import urljoin, urlparse
8
8
 
9
9
  import requests
10
10
  from qiniu import Auth
@@ -230,6 +230,27 @@ class DiskClient:
230
230
  def delete_resource(self, res_str_id: str) -> None:
231
231
  self.request("DELETE", f"/api/res/{res_str_id}")
232
232
 
233
+ def _is_backend_json_api_response(
234
+ self,
235
+ response: requests.Response,
236
+ *,
237
+ requested_url: str,
238
+ ) -> bool:
239
+ content_type = response.headers.get("content-type", "").lower()
240
+ if "application/json" not in content_type:
241
+ return False
242
+
243
+ content_disposition = response.headers.get("content-disposition", "").lower()
244
+ if "attachment" in content_disposition or "filename=" in content_disposition:
245
+ return False
246
+
247
+ final_url = urlparse(response.url)
248
+ backend_url = urlparse(self.settings.backend_url)
249
+ requested = urlparse(requested_url)
250
+ if (final_url.scheme, final_url.netloc) != (backend_url.scheme, backend_url.netloc):
251
+ return False
252
+ return final_url.path.rstrip("/") == requested.path.rstrip("/")
253
+
233
254
  def download_resource(
234
255
  self,
235
256
  res_str_id: str,
@@ -250,10 +271,6 @@ class DiskClient:
250
271
  stream=True,
251
272
  allow_redirects=True,
252
273
  )
253
- content_type = response.headers.get("content-type", "")
254
- if "application/json" in content_type:
255
- self._unwrap_response(response)
256
- raise DiskAPIError("Download endpoint returned JSON instead of file content.")
257
274
  try:
258
275
  response.raise_for_status()
259
276
  except requests.HTTPError as exc:
@@ -262,6 +279,12 @@ class DiskClient:
262
279
  status_code=response.status_code,
263
280
  ) from exc
264
281
 
282
+ if self._is_backend_json_api_response(response, requested_url=url):
283
+ self._unwrap_response(response)
284
+ raise DiskAPIError(
285
+ "Download endpoint returned JSON metadata instead of file content."
286
+ )
287
+
265
288
  total_header = response.headers.get("content-length")
266
289
  total = int(total_header) if total_header and total_header.isdigit() else None
267
290
  if progress_callback:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: htx-cli
3
- Version: 0.1.4
3
+ Version: 0.1.5
4
4
  Summary: htx-cli command-line client for the Disk backend API
5
5
  Requires-Python: >=3.9
6
6
  Description-Content-Type: text/markdown
File without changes
File without changes
File without changes
File without changes