From 14d1ba9fa7b6100bef3e322a438a5cd5bf7c2948 Mon Sep 17 00:00:00 2001 From: Profitroll <47523801+profitrollgame@users.noreply.github.com> Date: Sun, 22 Jan 2023 11:31:00 +0100 Subject: [PATCH] Added only_ids to GET /saves --- extensions/saves.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/extensions/saves.py b/extensions/saves.py index 30465f0..ab14ce6 100644 --- a/extensions/saves.py +++ b/extensions/saves.py @@ -14,8 +14,8 @@ from starlette.status import HTTP_204_NO_CONTENT, HTTP_403_FORBIDDEN, HTTP_404_N from modules.utils import configGet, zip_saves -@app.get("/saves", response_class=UJSONResponse, response_model=Dict[str, StardewSave], description="Get all available game saves") -async def saves_get(device: Union[str, None] = None, version: Union[str, None] = None, apikey: APIKey = Depends(get_api_key)): +@app.get("/saves", response_class=UJSONResponse, response_model=Union[List[Dict[str, StardewSave]], List[int]], description="Get all available game saves") +async def saves_get(device: Union[str, None] = None, version: Union[str, None] = None, only_ids: bool = False, apikey: APIKey = Depends(get_api_key)): user = user_by_key(apikey) @@ -34,12 +34,17 @@ async def saves_get(device: Union[str, None] = None, version: Union[str, None] = output = [] - for entry in saves_entries: - out_entry = entry - del out_entry["_id"] - del out_entry["user"] - del out_entry["file"] - output.append(out_entry) + if only_ids is True: + for entry in saves_entries: + if entry["id"] not in output: + output.append(entry["id"]) + else: + for entry in saves_entries: + out_entry = entry + del out_entry["_id"] + del out_entry["user"] + del out_entry["file"] + output.append(out_entry) return UJSONResponse(output)