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

fix: add search params to list buckets method #308

Merged
merged 2 commits into from
Oct 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
24 changes: 19 additions & 5 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 = None
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 = None
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 @@ -214,9 +228,9 @@ async def get_public_url(self, path: str, options: URLOptions = {}) -> str:
download_query = None
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
20 changes: 17 additions & 3 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 = None
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 = None
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 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
Loading