Added save sorting by upload and progress
This commit is contained in:
parent
dd7031ff19
commit
c0d608b63f
@ -16,7 +16,7 @@ from modules.utils import configGet, zip_saves
|
||||
|
||||
|
||||
@app.get("/saves", response_class=UJSONResponse, response_model=Union[List[Dict[str, StardewSave]], List[StardewSaveBrief]], 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)):
|
||||
async def saves_get(device: Union[str, None] = None, version: Union[str, None] = None, only_ids: bool = False, sort: Union[Literal["upload", "progress"], None] = "upload", apikey: APIKey = Depends(get_api_key)):
|
||||
|
||||
user = user_by_key(apikey)
|
||||
|
||||
@ -28,7 +28,7 @@ async def saves_get(device: Union[str, None] = None, version: Union[str, None] =
|
||||
if version is not None:
|
||||
query["data.game_version"] = version
|
||||
|
||||
saves_entries = list(col_saves.find(query).sort("date", DESCENDING))
|
||||
saves_entries = list(col_saves.find(query).sort("date", DESCENDING)) if sort == "upload" else list(col_saves.find(query).sort("data.save_time", DESCENDING))
|
||||
|
||||
if len(saves_entries) == 0:
|
||||
raise HTTPException(HTTP_404_NOT_FOUND, detail="Could not find any saves.")
|
||||
@ -52,7 +52,7 @@ async def saves_get(device: Union[str, None] = None, version: Union[str, None] =
|
||||
|
||||
|
||||
@app.get("/saves/{id}", response_class=UJSONResponse, response_model=List[StardewSave], description="Get game saves by name")
|
||||
async def saves_get_by_id(id: int, device: Union[str, None] = None, version: Union[str, None] = None, apikey: APIKey = Depends(get_api_key)):
|
||||
async def saves_get_by_id(id: int, device: Union[str, None] = None, version: Union[str, None] = None, sort: Union[Literal["upload", "progress"], None] = "upload", apikey: APIKey = Depends(get_api_key)):
|
||||
|
||||
query = {"id": id}
|
||||
|
||||
@ -62,7 +62,7 @@ async def saves_get_by_id(id: int, device: Union[str, None] = None, version: Uni
|
||||
if version is not None:
|
||||
query["data.game_version"] = version
|
||||
|
||||
saves_entries = list(col_saves.find(query).sort("date", DESCENDING))
|
||||
saves_entries = list(col_saves.find(query).sort("date", DESCENDING)) if sort == "upload" else list(col_saves.find(query).sort("data.save_time", DESCENDING))
|
||||
|
||||
if len(saves_entries) == 0:
|
||||
raise HTTPException(HTTP_404_NOT_FOUND, detail="Could not find save with such id.")
|
||||
|
Loading…
Reference in New Issue
Block a user