fix(connection): support absolute download urls for public data
This commit is contained in:
@@ -5,12 +5,7 @@ from pydantic import TypeAdapter
|
||||
from requests import Response
|
||||
|
||||
from mdrsclient.connection import MDRSConnection
|
||||
from mdrsclient.exceptions import (
|
||||
BadRequestException,
|
||||
ForbiddenException,
|
||||
UnauthorizedException,
|
||||
UnexpectedException,
|
||||
)
|
||||
from mdrsclient.exceptions import BadRequestException, ForbiddenException, UnauthorizedException, UnexpectedException
|
||||
from mdrsclient.models.error import DRFStandardizedErrors
|
||||
|
||||
|
||||
|
||||
@@ -54,7 +54,10 @@ class FilesApi(BaseApi):
|
||||
try:
|
||||
with open(os.path.realpath(path), mode="rb") as fp:
|
||||
data = MultipartEncoder(
|
||||
fields={"folder_id": folder_id, "file": (normalize("NFC", os.path.basename(path)), fp, self._get_mime_type(path))}
|
||||
fields={
|
||||
"folder_id": folder_id,
|
||||
"file": (normalize("NFC", os.path.basename(path)), fp, self._get_mime_type(path)),
|
||||
}
|
||||
)
|
||||
response = self.connection.post(url, data=data, headers={"Content-Type": data.content_type})
|
||||
self._raise_response_error(response)
|
||||
@@ -76,7 +79,9 @@ class FilesApi(BaseApi):
|
||||
# update file body
|
||||
try:
|
||||
with open(os.path.realpath(path), mode="rb") as fp:
|
||||
data = MultipartEncoder(fields={"file": (normalize("NFC", os.path.basename(path)), fp, self._get_mime_type(path))})
|
||||
data = MultipartEncoder(
|
||||
fields={"file": (normalize("NFC", os.path.basename(path)), fp, self._get_mime_type(path))}
|
||||
)
|
||||
response = self.connection.put(url, data=data, headers={"Content-Type": data.content_type})
|
||||
except OSError:
|
||||
raise UnexpectedException(f"Could not open `{path}` file.")
|
||||
|
||||
@@ -28,7 +28,9 @@ class ConfigCommand(BaseCommand):
|
||||
list_parser = config_parsers.add_parser("list", help="list all the remote hosts", aliases=["ls"])
|
||||
list_parser.set_defaults(func=cls.func_list)
|
||||
# config delete
|
||||
delete_parser = config_parsers.add_parser("delete", help="delete an existing remote host", aliases=["remove", "rm"])
|
||||
delete_parser = config_parsers.add_parser(
|
||||
"delete", help="delete an existing remote host", aliases=["remove", "rm"]
|
||||
)
|
||||
delete_parser.add_argument("remote", help="label of remote host")
|
||||
delete_parser.set_defaults(func=cls.func_delete)
|
||||
|
||||
|
||||
@@ -92,6 +92,8 @@ class MDRSConnection:
|
||||
self.__cache.laboratories = laboratories
|
||||
|
||||
def __build_url(self, path: str) -> str:
|
||||
if path.startswith("http://") or path.startswith("https://"):
|
||||
return path
|
||||
if self.url == "":
|
||||
raise MissingConfigurationException("remote host is not configured")
|
||||
return f"{self.url}/{path}"
|
||||
|
||||
Reference in New Issue
Block a user