Skip to content

Commit 83bba49

Browse files
some patches to the main api structure and downloads
1 parent c1df0c8 commit 83bba49

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
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

0 commit comments

Comments
 (0)