From 5ad2ae8ed67b6f8fe60ceff8ff6a85d92ac36725 Mon Sep 17 00:00:00 2001 From: anand2312 <40204976+anand2312@users.noreply.github.com> Date: Fri, 29 Sep 2023 17:41:15 +0530 Subject: [PATCH 1/4] fix: use correct Any for typehint --- storage3/_async/file_api.py | 2 +- storage3/_sync/file_api.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/storage3/_async/file_api.py b/storage3/_async/file_api.py index 6a9650ad..495bfc2a 100644 --- a/storage3/_async/file_api.py +++ b/storage3/_async/file_api.py @@ -279,7 +279,7 @@ async def copy(self, from_path: str, to_path: str) -> dict[str, str]: ) return res.json() - async def remove(self, paths: list) -> list[dict[str, any]]: + async def remove(self, paths: list) -> list[dict[str, Any]]: """ Deletes files within the same bucket diff --git a/storage3/_sync/file_api.py b/storage3/_sync/file_api.py index d5faa917..26b2a9ec 100644 --- a/storage3/_sync/file_api.py +++ b/storage3/_sync/file_api.py @@ -279,7 +279,7 @@ def copy(self, from_path: str, to_path: str) -> dict[str, str]: ) return res.json() - def remove(self, paths: list) -> list[dict[str, any]]: + def remove(self, paths: list) -> list[dict[str, Any]]: """ Deletes files within the same bucket From 9910fe0d9e88c60798773d42a4449b1df62068ed Mon Sep 17 00:00:00 2001 From: anand2312 <40204976+anand2312@users.noreply.github.com> Date: Fri, 29 Sep 2023 17:49:02 +0530 Subject: [PATCH 2/4] fix: pass cache-control as formdata --- storage3/_async/file_api.py | 24 ++++++++++-------------- storage3/_sync/file_api.py | 26 ++++++++++---------------- 2 files changed, 20 insertions(+), 30 deletions(-) diff --git a/storage3/_async/file_api.py b/storage3/_async/file_api.py index 495bfc2a..5557d419 100644 --- a/storage3/_async/file_api.py +++ b/storage3/_async/file_api.py @@ -37,13 +37,10 @@ async def _request( headers: Optional[dict[str, Any]] = None, json: Optional[dict[Any, Any]] = None, files: Optional[Any] = None, + **kwargs: Any, ) -> Response: response = await self._client.request( - method, - url, - headers=headers or {}, - json=json, - files=files, + method, url, headers=headers or {}, json=json, files=files, **kwargs ) try: response.raise_for_status() @@ -108,9 +105,12 @@ async def upload_to_signed_url( file_options = {} cache_control = file_options.get("cache-control") + # cacheControl is also passed as form data + # https://github.com/supabase/storage-js/blob/fa44be8156295ba6320ffeff96bdf91016536a46/src/packages/StorageFileApi.ts#L89 + _data = {} if cache_control: file_options["cache-control"] = f"max-age={cache_control}" - + _data = {"cacheControl": cache_control} headers = { **self._client.headers, **DEFAULT_FILE_OPTIONS, @@ -135,10 +135,7 @@ async def upload_to_signed_url( ) } return await self._request( - "PUT", - final_url, - files=_file, - headers=headers, + "PUT", final_url, files=_file, headers=headers, data=_data ) async def create_signed_url( @@ -369,8 +366,10 @@ async def upload( if file_options is None: file_options = {} cache_control = file_options.get("cache-control") + _data = {} if cache_control: file_options["cache-control"] = f"max-age={cache_control}" + _data = {"cacheControl": cache_control} headers = { **self._client.headers, @@ -399,10 +398,7 @@ async def upload( _path = self._get_final_path(path) return await self._request( - "POST", - f"/object/{_path}", - files=files, - headers=headers, + "POST", f"/object/{_path}", files=files, headers=headers, data=_data ) def _get_final_path(self, path: str) -> str: diff --git a/storage3/_sync/file_api.py b/storage3/_sync/file_api.py index 26b2a9ec..f1e30b4a 100644 --- a/storage3/_sync/file_api.py +++ b/storage3/_sync/file_api.py @@ -37,13 +37,10 @@ def _request( headers: Optional[dict[str, Any]] = None, json: Optional[dict[Any, Any]] = None, files: Optional[Any] = None, + **kwargs: Any, ) -> Response: response = self._client.request( - method, - url, - headers=headers or {}, - json=json, - files=files, + method, url, headers=headers or {}, json=json, files=files, **kwargs ) try: response.raise_for_status() @@ -108,9 +105,12 @@ def upload_to_signed_url( file_options = {} cache_control = file_options.get("cache-control") + # cacheControl is also passed as form data + # https://github.com/supabase/storage-js/blob/fa44be8156295ba6320ffeff96bdf91016536a46/src/packages/StorageFileApi.ts#L89 + _data = {} if cache_control: file_options["cache-control"] = f"max-age={cache_control}" - + _data = {"cacheControl": cache_control} headers = { **self._client.headers, **DEFAULT_FILE_OPTIONS, @@ -134,12 +134,7 @@ def upload_to_signed_url( headers.pop("content-type"), ) } - return self._request( - "PUT", - final_url, - files=_file, - headers=headers, - ) + return self._request("PUT", final_url, files=_file, headers=headers, data=_data) def create_signed_url( self, path: str, expires_in: int, options: URLOptions = {} @@ -369,8 +364,10 @@ def upload( if file_options is None: file_options = {} cache_control = file_options.get("cache-control") + _data = {} if cache_control: file_options["cache-control"] = f"max-age={cache_control}" + _data = {"cacheControl": cache_control} headers = { **self._client.headers, @@ -399,10 +396,7 @@ def upload( _path = self._get_final_path(path) return self._request( - "POST", - f"/object/{_path}", - files=files, - headers=headers, + "POST", f"/object/{_path}", files=files, headers=headers, data=_data ) def _get_final_path(self, path: str) -> str: From d2530fe4b661e9b43dc6a0e124ac60ab3ffc64c9 Mon Sep 17 00:00:00 2001 From: anand2312 <40204976+anand2312@users.noreply.github.com> Date: Fri, 29 Sep 2023 17:57:30 +0530 Subject: [PATCH 3/4] fix: make precommit ignore markdown files --- .pre-commit-config.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5ccd6deb..1216405b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,3 +1,4 @@ +exclude: '^.*\.(md|MD)$' repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.0.1 From 5430e920492e6616ce833318daef44176b282401 Mon Sep 17 00:00:00 2001 From: anand2312 <40204976+anand2312@users.noreply.github.com> Date: Fri, 29 Sep 2023 18:14:23 +0530 Subject: [PATCH 4/4] docs: fix name of URLOptions type --- docs/api/types.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/api/types.rst b/docs/api/types.rst index 85e2658d..b99f4546 100644 --- a/docs/api/types.rst +++ b/docs/api/types.rst @@ -16,7 +16,7 @@ Options .. autotypeddict:: storage3.types.TransformOptions -.. autotypeddict:: storage3.types.CreateSignedURLOptions +.. autotypeddict:: storage3.types.URLOptions .. autotypeddict:: storage3.types.CreateSignedURLsOptions