Added only_ids to GET /saves

This commit is contained in:
Profitroll 2023-01-22 11:31:00 +01:00
parent ce768d895d
commit 14d1ba9fa7

View File

@ -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 from modules.utils import configGet, zip_saves
@app.get("/saves", response_class=UJSONResponse, response_model=Dict[str, StardewSave], description="Get all available game saves") @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, apikey: APIKey = Depends(get_api_key)): 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) user = user_by_key(apikey)
@ -34,12 +34,17 @@ async def saves_get(device: Union[str, None] = None, version: Union[str, None] =
output = [] output = []
for entry in saves_entries: if only_ids is True:
out_entry = entry for entry in saves_entries:
del out_entry["_id"] if entry["id"] not in output:
del out_entry["user"] output.append(entry["id"])
del out_entry["file"] else:
output.append(out_entry) 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) return UJSONResponse(output)