Skip to content

Commit 67e73e6

Browse files
Build path using helper to avoid adding none params
1 parent 0522b16 commit 67e73e6

File tree

1 file changed

+20
-24
lines changed

1 file changed

+20
-24
lines changed

jigsawstack/store.py

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,14 @@
33
from .request import Request, RequestConfig
44
from .async_request import AsyncRequest, AsyncRequestConfig
55
from ._config import ClientConfig
6-
7-
8-
9-
6+
from .helpers import build_path
7+
from .exceptions import JigsawStackError
108
class FileDeleteResponse(TypedDict):
119
success: bool
1210

13-
14-
1511
class FileUploadParams(TypedDict):
16-
overwrite: bool
17-
filename: str
12+
overwrite: NotRequired[bool]
13+
filename: NotRequired[str]
1814
content_type: NotRequired[str]
1915

2016
class Store(ClientConfig):
@@ -34,19 +30,19 @@ def __init__(
3430
disable_request_logging=disable_request_logging,
3531
)
3632

37-
def upload(self, file: bytes, options=FileUploadParams) -> Any:
38-
overwrite = options.get("overwrite")
39-
filename = options.get("filename")
40-
params = {"key": filename, "overwrite": overwrite}
41-
path = f"/store/file?overwrite={overwrite}&key={filename}"
42-
content_type = options.get("content_type")
43-
_headers = {"Content-Type": "application/octet-stream"}
44-
if content_type is not None:
45-
_headers = {"Content-Type": content_type}
33+
def upload(self, file: bytes, options: Union[FileUploadParams, None] = None) -> Any:
34+
if options is None:
35+
options = {}
36+
37+
path = build_path(base_path="/store/file", params=options)
38+
print(path)
39+
content_type = options.get("content_type", "application/octet-stream")
40+
41+
_headers = {"Content-Type": content_type}
4642

4743
resp = Request(
4844
config=self.config,
49-
params=params,
45+
params=options, # Empty params since we're using them in the URL
5046
path=path,
5147
data=file,
5248
headers=_headers,
@@ -92,19 +88,19 @@ def __init__(
9288
)
9389

9490

95-
async def upload(self, file: bytes, options=FileUploadParams) -> Any:
96-
overwrite = options.get("overwrite")
97-
filename = options.get("filename")
98-
params = {"key": filename, "overwrite": overwrite}
99-
path = f"/store/file?overwrite={overwrite}&key={filename}"
91+
async def upload(self, file: bytes, options: Union[FileUploadParams, None] = None) -> Any:
92+
if options is None:
93+
options = {}
94+
95+
path = build_path(base_path="/store/file", params=options)
10096
content_type = options.get("content_type")
10197
_headers = {"Content-Type": "application/octet-stream"}
10298
if content_type is not None:
10399
_headers = {"Content-Type": content_type}
104100

105101
resp = await AsyncRequest(
106102
config=self.config,
107-
params=params,
103+
params={}, # Empty params since we're using them in the URL
108104
path=path,
109105
data=file,
110106
headers=_headers,

0 commit comments

Comments
 (0)