Skip to content

Commit fca2f00

Browse files
authored
fix: add search params to list buckets method (#308)
1 parent a9e874a commit fca2f00

File tree

3 files changed

+43
-14
lines changed

3 files changed

+43
-14
lines changed

storage3/_async/file_api.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,15 @@ async def create_signed_url(
157157
options to be passed for downloading or transforming the file.
158158
"""
159159
json = {"expiresIn": str(expires_in)}
160+
download_query = ""
160161
if options.get("download"):
161162
json.update({"download": options["download"]})
163+
164+
download_query = (
165+
"&download="
166+
if options.get("download") is True
167+
else f"&download={options.get('download')}"
168+
)
162169
if options.get("transform"):
163170
json.update({"transform": options["transform"]})
164171

@@ -170,7 +177,7 @@ async def create_signed_url(
170177
)
171178
data = response.json()
172179
data["signedURL"] = (
173-
f"{self._client.base_url}{cast(str, data['signedURL']).lstrip('/')}"
180+
f"{self._client.base_url}{cast(str, data['signedURL']).lstrip('/')}{download_query}"
174181
)
175182
return data
176183

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

202+
download_query = (
203+
"&download="
204+
if options.get("download") is True
205+
else f"&download={options.get('download')}"
206+
)
207+
194208
response = await self._request(
195209
"POST",
196210
f"/object/sign/{self.id}",
@@ -199,7 +213,7 @@ async def create_signed_urls(
199213
data = response.json()
200214
for item in data:
201215
item["signedURL"] = (
202-
f"{self._client.base_url}{cast(str, item['signedURL']).lstrip('/')}"
216+
f"{self._client.base_url}{cast(str, item['signedURL']).lstrip('/')}{download_query}"
203217
)
204218
return data
205219

@@ -211,12 +225,12 @@ async def get_public_url(self, path: str, options: URLOptions = {}) -> str:
211225
file path, including the path and file name. For example `folder/image.png`.
212226
"""
213227
_query_string = []
214-
download_query = None
228+
download_query = ""
215229
if options.get("download"):
216230
download_query = (
217-
"download="
231+
"&download="
218232
if options.get("download") is True
219-
else f"download={options.get('download')}"
233+
else f"&download={options.get('download')}"
220234
)
221235

222236
if download_query:
@@ -310,7 +324,7 @@ async def list(
310324
path
311325
The folder path.
312326
options
313-
Search options, including `limit`, `offset`, and `sortBy`.
327+
Search options, including `limit`, `offset`, `sortBy` and `search`.
314328
"""
315329
extra_options = options or {}
316330
extra_headers = {"Content-Type": "application/json"}

storage3/_sync/file_api.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,15 @@ def create_signed_url(
155155
options to be passed for downloading or transforming the file.
156156
"""
157157
json = {"expiresIn": str(expires_in)}
158+
download_query = ""
158159
if options.get("download"):
159160
json.update({"download": options["download"]})
161+
162+
download_query = (
163+
"&download="
164+
if options.get("download") is True
165+
else f"&download={options.get('download')}"
166+
)
160167
if options.get("transform"):
161168
json.update({"transform": options["transform"]})
162169

@@ -168,7 +175,7 @@ def create_signed_url(
168175
)
169176
data = response.json()
170177
data["signedURL"] = (
171-
f"{self._client.base_url}{cast(str, data['signedURL']).lstrip('/')}"
178+
f"{self._client.base_url}{cast(str, data['signedURL']).lstrip('/')}{download_query}"
172179
)
173180
return data
174181

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

200+
download_query = (
201+
"&download="
202+
if options.get("download") is True
203+
else f"&download={options.get('download')}"
204+
)
205+
192206
response = self._request(
193207
"POST",
194208
f"/object/sign/{self.id}",
@@ -197,7 +211,7 @@ def create_signed_urls(
197211
data = response.json()
198212
for item in data:
199213
item["signedURL"] = (
200-
f"{self._client.base_url}{cast(str, item['signedURL']).lstrip('/')}"
214+
f"{self._client.base_url}{cast(str, item['signedURL']).lstrip('/')}{download_query}"
201215
)
202216
return data
203217

@@ -209,12 +223,12 @@ def get_public_url(self, path: str, options: URLOptions = {}) -> str:
209223
file path, including the path and file name. For example `folder/image.png`.
210224
"""
211225
_query_string = []
212-
download_query = None
226+
download_query = ""
213227
if options.get("download"):
214228
download_query = (
215-
"download="
229+
"&download="
216230
if options.get("download") is True
217-
else f"download={options.get('download')}"
231+
else f"&download={options.get('download')}"
218232
)
219233

220234
if download_query:
@@ -308,7 +322,7 @@ def list(
308322
path
309323
The folder path.
310324
options
311-
Search options, including `limit`, `offset`, and `sortBy`.
325+
Search options, including `limit`, `offset`, `sortBy` and `search`.
312326
"""
313327
extra_options = options or {}
314328
extra_headers = {"Content-Type": "application/json"}

storage3/types.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def __post_init__(self) -> None:
3030

3131

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

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

4949

50-
class ListBucketFilesOptions(TypedDict):
50+
class ListBucketFilesOptions(TypedDict, total=False):
5151
limit: int
5252
offset: int
5353
sortBy: _sortByType
54+
search: str
5455

5556

5657
class TransformOptions(TypedDict, total=False):

0 commit comments

Comments
 (0)