Skip to content

Commit

Permalink
fix: add search params to list buckets method (#308)
Browse files Browse the repository at this point in the history
  • Loading branch information
silentworks authored Oct 26, 2024
1 parent a9e874a commit fca2f00
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 14 deletions.
26 changes: 20 additions & 6 deletions storage3/_async/file_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,15 @@ async def create_signed_url(
options to be passed for downloading or transforming the file.
"""
json = {"expiresIn": str(expires_in)}
download_query = ""
if options.get("download"):
json.update({"download": options["download"]})

download_query = (
"&download="
if options.get("download") is True
else f"&download={options.get('download')}"
)
if options.get("transform"):
json.update({"transform": options["transform"]})

Expand All @@ -170,7 +177,7 @@ async def create_signed_url(
)
data = response.json()
data["signedURL"] = (
f"{self._client.base_url}{cast(str, data['signedURL']).lstrip('/')}"
f"{self._client.base_url}{cast(str, data['signedURL']).lstrip('/')}{download_query}"
)
return data

Expand All @@ -188,9 +195,16 @@ async def create_signed_urls(
options to be passed for downloading the file.
"""
json = {"paths": paths, "expiresIn": str(expires_in)}
download_query = ""
if options.get("download"):
json.update({"download": options.get("download")})

download_query = (
"&download="
if options.get("download") is True
else f"&download={options.get('download')}"
)

response = await self._request(
"POST",
f"/object/sign/{self.id}",
Expand All @@ -199,7 +213,7 @@ async def create_signed_urls(
data = response.json()
for item in data:
item["signedURL"] = (
f"{self._client.base_url}{cast(str, item['signedURL']).lstrip('/')}"
f"{self._client.base_url}{cast(str, item['signedURL']).lstrip('/')}{download_query}"
)
return data

Expand All @@ -211,12 +225,12 @@ async def get_public_url(self, path: str, options: URLOptions = {}) -> str:
file path, including the path and file name. For example `folder/image.png`.
"""
_query_string = []
download_query = None
download_query = ""
if options.get("download"):
download_query = (
"download="
"&download="
if options.get("download") is True
else f"download={options.get('download')}"
else f"&download={options.get('download')}"
)

if download_query:
Expand Down Expand Up @@ -310,7 +324,7 @@ async def list(
path
The folder path.
options
Search options, including `limit`, `offset`, and `sortBy`.
Search options, including `limit`, `offset`, `sortBy` and `search`.
"""
extra_options = options or {}
extra_headers = {"Content-Type": "application/json"}
Expand Down
26 changes: 20 additions & 6 deletions storage3/_sync/file_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,15 @@ def create_signed_url(
options to be passed for downloading or transforming the file.
"""
json = {"expiresIn": str(expires_in)}
download_query = ""
if options.get("download"):
json.update({"download": options["download"]})

download_query = (
"&download="
if options.get("download") is True
else f"&download={options.get('download')}"
)
if options.get("transform"):
json.update({"transform": options["transform"]})

Expand All @@ -168,7 +175,7 @@ def create_signed_url(
)
data = response.json()
data["signedURL"] = (
f"{self._client.base_url}{cast(str, data['signedURL']).lstrip('/')}"
f"{self._client.base_url}{cast(str, data['signedURL']).lstrip('/')}{download_query}"
)
return data

Expand All @@ -186,9 +193,16 @@ def create_signed_urls(
options to be passed for downloading the file.
"""
json = {"paths": paths, "expiresIn": str(expires_in)}
download_query = ""
if options.get("download"):
json.update({"download": options.get("download")})

download_query = (
"&download="
if options.get("download") is True
else f"&download={options.get('download')}"
)

response = self._request(
"POST",
f"/object/sign/{self.id}",
Expand All @@ -197,7 +211,7 @@ def create_signed_urls(
data = response.json()
for item in data:
item["signedURL"] = (
f"{self._client.base_url}{cast(str, item['signedURL']).lstrip('/')}"
f"{self._client.base_url}{cast(str, item['signedURL']).lstrip('/')}{download_query}"
)
return data

Expand All @@ -209,12 +223,12 @@ def get_public_url(self, path: str, options: URLOptions = {}) -> str:
file path, including the path and file name. For example `folder/image.png`.
"""
_query_string = []
download_query = None
download_query = ""
if options.get("download"):
download_query = (
"download="
"&download="
if options.get("download") is True
else f"download={options.get('download')}"
else f"&download={options.get('download')}"
)

if download_query:
Expand Down Expand Up @@ -308,7 +322,7 @@ def list(
path
The folder path.
options
Search options, including `limit`, `offset`, and `sortBy`.
Search options, including `limit`, `offset`, `sortBy` and `search`.
"""
extra_options = options or {}
extra_headers = {"Content-Type": "application/json"}
Expand Down
5 changes: 3 additions & 2 deletions storage3/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __post_init__(self) -> None:


# used in bucket.list method's option parameter
class _sortByType(TypedDict):
class _sortByType(TypedDict, total=False):
column: str
order: Literal["asc", "desc"]

Expand All @@ -47,10 +47,11 @@ class CreateOrUpdateBucketOptions(TypedDict, total=False):
allowed_mime_types: list[str]


class ListBucketFilesOptions(TypedDict):
class ListBucketFilesOptions(TypedDict, total=False):
limit: int
offset: int
sortBy: _sortByType
search: str


class TransformOptions(TypedDict, total=False):
Expand Down

0 comments on commit fca2f00

Please sign in to comment.