Skip to content

Commit

Permalink
Use file download URL as provided by the API
Browse files Browse the repository at this point in the history
  • Loading branch information
Danny Guinther committed Sep 26, 2023
1 parent 038a113 commit d6f01a0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
4 changes: 3 additions & 1 deletion src/sparsezoo/api/query_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@

DEFAULT_MODELS_FIELDS = ["modelId", "stub"]

DEFAULT_FILES_FIELDS = ["displayName", "fileSize", "modelId", "fileType"]
DEFAULT_FILES_FIELDS = [
"displayName", "downloadUrl", "fileSize", "fileType", "modelId"
]

DEFAULT_TRAINING_RESULTS_FIELDS = [
"datasetName",
Expand Down
14 changes: 5 additions & 9 deletions src/sparsezoo/model/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,9 +599,8 @@ def _copy_and_overwrite(from_path, to_path, func):

def include_file_download_url(files: List[Dict]):
for file in files:
file["url"] = get_file_download_url(
model_id=file["model_id"], file_name=file["display_name"]
)
file["url"] = get_file_download_url(file["download_url"])
del file["download_url"]


def get_model_metadata_from_stub(stub: str) -> Dict[str, str]:
Expand Down Expand Up @@ -637,15 +636,12 @@ def is_stub(candidate: str) -> bool:


def get_file_download_url(
model_id: str,
file_name: str,
base_url: str = BASE_API_URL,
download_url: str,
):
"""Url to download a file"""
download_url = f"{base_url}/v2/models/{model_id}/files/{file_name}"

# important, do not remove
if convert_to_bool(os.getenv("SPARSEZOO_TEST_MODE")):
download_url += "?increment_download=False"
delimiter = "&" if "?" in download_url else "?"
download_url += f"{delimiter}increment_download=False"

return download_url

0 comments on commit d6f01a0

Please sign in to comment.