Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File fetch #408

Merged
merged 4 commits into from
May 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 22 additions & 16 deletions kgforge/specializations/stores/bluebrain_nexus.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,12 +472,16 @@ def retrieve(
query_params=query_params,
)

def _retrieve_filename(self, id_: str) -> Tuple[str, str]:
def _retrieve_file_metadata(self, id_: str) -> Dict:
response = requests.get(
id_, headers=self.service.headers, timeout=REQUEST_TIMEOUT
)
catch_http_error_nexus(response, DownloadingError)
metadata = response.json()
return metadata

def _retrieve_filename(self, id_: str) -> Tuple[str, str]:
metadata = self._retrieve_file_metadata(id_)
return metadata["_filename"], metadata["_mediaType"]

def _download_many(
Expand Down Expand Up @@ -557,21 +561,7 @@ def _download_one(
for chunk in response.iter_content(chunk_size=4096):
f.write(chunk)

def _prepare_download_one(
self, url: str, store_metadata: Optional[DictWrapper], cross_bucket: bool
) -> Tuple[str, str]:
if cross_bucket:
if store_metadata is not None:
project = store_metadata._project.split("/")[-1]
org = store_metadata._project.split("/")[-2]
else:
raise ValueError(
f"Downloading non registered file is not allowed when cross_bucket is set to {cross_bucket}"
)
else:
org = self.service.organisation
project = self.service.project

def _prepare_download_one_with_org_project(self, url: str, org: str, project: str):
file_id = url.split("/")[-1]
file_id = unquote(file_id)
if len(file_id) < 1:
Expand All @@ -593,6 +583,22 @@ def _prepare_download_one(
)
return url_base, f"{org}/{project}"

def _prepare_download_one(
self, url: str, store_metadata: Optional[DictWrapper], cross_bucket: bool
) -> Tuple[str, str]:
if cross_bucket:
if store_metadata is not None:
org, project = store_metadata._project.split("/")
else:
raise ValueError(
f"Downloading non registered file is not allowed when cross_bucket is set to True"
)
else:
org = self.service.organisation
project = self.service.project

return self._prepare_download_one_with_org_project(url, org, project)

# CR[U]D.

def update(
Expand Down
Loading