Skip to content

Commit e11c77c

Browse files
committed
auto-fix download too
1 parent 4c7d27f commit e11c77c

1 file changed

Lines changed: 18 additions & 6 deletions

File tree

ayon_api/server_api.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,7 +1352,7 @@ def _endpoint_to_url(
13521352

13531353
def _download_file_to_stream(
13541354
self,
1355-
url: str,
1355+
endpoint: str,
13561356
stream: StreamType,
13571357
chunk_size: int,
13581358
progress: TransferProgress,
@@ -1367,7 +1367,11 @@ def _download_file_to_stream(
13671367
else:
13681368
get_func = self._session_functions_mapping[RequestTypes.get]
13691369

1370+
url = self._endpoint_to_url(endpoint, use_rest=False)
1371+
progress.set_source_url(url)
1372+
13701373
retries = self.get_default_max_retries()
1374+
api_prepended = False
13711375
for attempt in range(retries):
13721376
# Continue in download
13731377
offset = progress.get_transferred_size()
@@ -1376,6 +1380,18 @@ def _download_file_to_stream(
13761380

13771381
try:
13781382
with get_func(url, **kwargs) as response:
1383+
# Auto-fix missing 'api/'
1384+
if response.status_code == 405 and not api_prepended:
1385+
api_prepended = True
1386+
if (
1387+
not endpoint.startswith(self._base_url)
1388+
and not endpoint.startswith("api/")
1389+
):
1390+
url = self._endpoint_to_url(
1391+
endpoint, use_rest=True
1392+
)
1393+
progress.set_destination_url(url)
1394+
continue
13791395
response.raise_for_status()
13801396
if progress.get_content_size() is None:
13811397
progress.set_content_size(
@@ -1427,17 +1443,14 @@ def download_file_to_stream(
14271443
if not chunk_size:
14281444
chunk_size = self.default_download_chunk_size
14291445

1430-
url = self._endpoint_to_url(endpoint, use_rest=False)
1431-
14321446
if progress is None:
14331447
progress = TransferProgress()
14341448

1435-
progress.set_source_url(url)
14361449
progress.set_started()
14371450

14381451
try:
14391452
self._download_file_to_stream(
1440-
url, stream, chunk_size, progress
1453+
endpoint, stream, chunk_size, progress
14411454
)
14421455

14431456
except Exception as exc:
@@ -1648,7 +1661,6 @@ def _upload_file(
16481661
# Set content size to progress object
16491662
progress.set_content_size(size)
16501663

1651-
api_prepended = False
16521664
for attempt in range(retries):
16531665
try:
16541666
response = post_func(

0 commit comments

Comments
 (0)