Skip to content

Commit 76772bd

Browse files
Merge pull request #5 from Programmer-Timmy/Savgame-function-fixes
Savgame function fixes
2 parents ce19348 + 08209d6 commit 76772bd

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

satisfactory_api_client/api_client.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,25 @@ def _post(self, function, data=None, files=None):
5757

5858
payload = {'function': function, 'data': data} if data else {'function': function}
5959

60-
response = requests.post(url, json=payload, headers=headers, files=files, verify=False)
60+
response = requests.post(url, json=payload, headers=headers, files=files, verify=False, stream=True)
6161
if response.status_code != 200 and response.status_code != 204:
6262
raise APIError(f"API error: {response.text}")
6363

6464
if response.status_code == 204:
6565
return {}
66-
if response.json().get('errorCode'):
67-
raise APIError(response.json().get('errorMessage'))
68-
return response.json().get('data')
66+
67+
# if response is not json, return the text
68+
print(response.headers.get('Content-Type'))
69+
# use switch
70+
match response.headers.get('Content-Type'):
71+
case 'application/json;charset=utf-8':
72+
if response.json().get('errorCode'):
73+
raise APIError(response.json().get('errorMessage'))
74+
return response.json().get('data')
75+
case 'application/octet-stream':
76+
return response.content
77+
case _:
78+
return response.text
6979

7080
def health_check(self, client_custom_data='') -> (
7181
Response):
@@ -510,7 +520,7 @@ def download_save_game(self, save_name: str) -> Response:
510520
Returns
511521
-------
512522
Response
513-
A Response indicating the success of the download operation.
523+
A Response indicating the success and the save game in bytes.
514524
"""
515525
response = self._post('DownloadSaveGame', {
516526
'SaveName': save_name

satisfactory_api_client/data/response.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ class Response:
1010
----------
1111
success : bool
1212
Whether the request was successful.
13-
data : dict
13+
data : dict | str
1414
The data returned from the API.
1515
"""
1616
success: bool
17-
data: dict
17+
data: dict | bytes

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
setup(
1010
name='satisfactory_api_client',
11-
version='0.1.7',
11+
version='0.1.8',
1212
packages=find_packages(exclude=['tests', 'examples']),
1313
install_requires=[
1414
"python-dotenv~=1.0.1",

0 commit comments

Comments
 (0)