From 29c4d466796b8087d460308dad58f9df267cea46 Mon Sep 17 00:00:00 2001 From: Andrew Smith Date: Sat, 26 Oct 2024 13:35:34 +0000 Subject: [PATCH 1/2] fix: add search params to list buckets method --- storage3/_async/file_api.py | 24 +++++++++++++++++++----- storage3/_sync/file_api.py | 20 +++++++++++++++++--- storage3/types.py | 5 +++-- 3 files changed, 39 insertions(+), 10 deletions(-) diff --git a/storage3/_async/file_api.py b/storage3/_async/file_api.py index 9f64da03..540b72a4 100644 --- a/storage3/_async/file_api.py +++ b/storage3/_async/file_api.py @@ -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"]}) @@ -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 @@ -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}", @@ -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 @@ -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: @@ -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"} diff --git a/storage3/_sync/file_api.py b/storage3/_sync/file_api.py index 4055fec6..2d108868 100644 --- a/storage3/_sync/file_api.py +++ b/storage3/_sync/file_api.py @@ -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"]}) @@ -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 @@ -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}", @@ -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 @@ -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"} diff --git a/storage3/types.py b/storage3/types.py index 5ecefefd..5e86d3c6 100644 --- a/storage3/types.py +++ b/storage3/types.py @@ -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"] @@ -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): From f2f97c142b7ac94aa8f2d6cfb05989d0538f448d Mon Sep 17 00:00:00 2001 From: Andrew Smith Date: Sat, 26 Oct 2024 13:47:02 +0000 Subject: [PATCH 2/2] fix: change the default download to empty string --- storage3/_async/file_api.py | 6 +++--- storage3/_sync/file_api.py | 18 +++++++++--------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/storage3/_async/file_api.py b/storage3/_async/file_api.py index 540b72a4..f3a31c46 100644 --- a/storage3/_async/file_api.py +++ b/storage3/_async/file_api.py @@ -157,7 +157,7 @@ async def create_signed_url( options to be passed for downloading or transforming the file. """ json = {"expiresIn": str(expires_in)} - download_query = None + download_query = "" if options.get("download"): json.update({"download": options["download"]}) @@ -195,7 +195,7 @@ async def create_signed_urls( options to be passed for downloading the file. """ json = {"paths": paths, "expiresIn": str(expires_in)} - download_query = None + download_query = "" if options.get("download"): json.update({"download": options.get("download")}) @@ -225,7 +225,7 @@ 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=" diff --git a/storage3/_sync/file_api.py b/storage3/_sync/file_api.py index 2d108868..c0854bd2 100644 --- a/storage3/_sync/file_api.py +++ b/storage3/_sync/file_api.py @@ -155,14 +155,14 @@ def create_signed_url( options to be passed for downloading or transforming the file. """ json = {"expiresIn": str(expires_in)} - download_query = None + download_query = "" if options.get("download"): json.update({"download": options["download"]}) download_query = ( - "download=" + "&download=" if options.get("download") is True - else f"download={options.get('download')}" + else f"&download={options.get('download')}" ) if options.get("transform"): json.update({"transform": options["transform"]}) @@ -193,14 +193,14 @@ def create_signed_urls( options to be passed for downloading the file. """ json = {"paths": paths, "expiresIn": str(expires_in)} - download_query = None + download_query = "" if options.get("download"): json.update({"download": 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')}" ) response = self._request( @@ -223,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: