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.
- {htx_cli-0.1.4 → htx_cli-0.1.5}/PKG-INFO +1 -1
- {htx_cli-0.1.4 → htx_cli-0.1.5}/pyproject.toml +1 -1
- {htx_cli-0.1.4 → htx_cli-0.1.5}/src/disk_cli/__init__.py +1 -1
- {htx_cli-0.1.4 → htx_cli-0.1.5}/src/disk_cli/api.py +28 -5
- {htx_cli-0.1.4 → htx_cli-0.1.5}/src/htx_cli.egg-info/PKG-INFO +1 -1
- {htx_cli-0.1.4 → htx_cli-0.1.5}/README.md +0 -0
- {htx_cli-0.1.4 → htx_cli-0.1.5}/setup.cfg +0 -0
- {htx_cli-0.1.4 → htx_cli-0.1.5}/src/disk_cli/__main__.py +0 -0
- {htx_cli-0.1.4 → htx_cli-0.1.5}/src/disk_cli/cli.py +0 -0
- {htx_cli-0.1.4 → htx_cli-0.1.5}/src/disk_cli/config.py +0 -0
- {htx_cli-0.1.4 → htx_cli-0.1.5}/src/htx_cli.egg-info/SOURCES.txt +0 -0
- {htx_cli-0.1.4 → htx_cli-0.1.5}/src/htx_cli.egg-info/dependency_links.txt +0 -0
- {htx_cli-0.1.4 → htx_cli-0.1.5}/src/htx_cli.egg-info/entry_points.txt +0 -0
- {htx_cli-0.1.4 → htx_cli-0.1.5}/src/htx_cli.egg-info/requires.txt +0 -0
- {htx_cli-0.1.4 → htx_cli-0.1.5}/src/htx_cli.egg-info/top_level.txt +0 -0
|
@@ -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:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|