Versions added
This commit is contained in:
parent
08d060e160
commit
84be0c7154
@ -15,10 +15,19 @@ from modules.utils import 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, apikey: APIKey = Depends(get_api_key)):
|
||||
async def saves_get(device: Union[str, None] = None, version: Union[str, None] = None, apikey: APIKey = Depends(get_api_key)):
|
||||
|
||||
user = user_by_key(apikey)
|
||||
saves_entries = list(col_saves.find({"user": user})) if device is None else list(col_saves.find({"user": user_by_key(apikey), "user": user}))
|
||||
|
||||
query = {"user": user}
|
||||
|
||||
if device is not None:
|
||||
query["device"] = device
|
||||
|
||||
if version is not None:
|
||||
query["data.game_version"] = version
|
||||
|
||||
saves_entries = list(col_saves.find(query))
|
||||
|
||||
if len(saves_entries) == 0:
|
||||
raise HTTPException(HTTP_404_NOT_FOUND, detail="Could not find any saves.")
|
||||
@ -36,9 +45,17 @@ async def saves_get(device: Union[str, None] = None, apikey: APIKey = Depends(ge
|
||||
|
||||
|
||||
@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, apikey: APIKey = Depends(get_api_key)):
|
||||
async def saves_get_by_id(id: int, device: Union[str, None] = None, version: Union[str, None] = None, apikey: APIKey = Depends(get_api_key)):
|
||||
|
||||
saves_entries = list(col_saves.find({"id": id})) if device is None else list(col_saves.find({"id": id, "device": device}))
|
||||
query = {"id": id}
|
||||
|
||||
if device is not None:
|
||||
query["device"] = device
|
||||
|
||||
if version is not None:
|
||||
query["data.game_version"] = version
|
||||
|
||||
saves_entries = list(col_saves.find(query))
|
||||
|
||||
if len(saves_entries) == 0:
|
||||
raise HTTPException(HTTP_404_NOT_FOUND, detail="Could not find save with such id.")
|
||||
@ -57,7 +74,14 @@ async def saves_get_by_id(id: int, device: Union[str, None] = None, apikey: APIK
|
||||
|
||||
@app.get("/saves/{id}/{save_date}", response_class=UJSONResponse, response_model=List[StardewSave], description="Get game saves by name")
|
||||
async def saves_get_by_both_ids(id: int, save_date: int, device: Union[str, None] = None, apikey: APIKey = Depends(get_api_key)):
|
||||
saves_entry = col_saves.find_one({"user": user_by_key(apikey), "id": id, "date": save_date}) if device is None else col_saves.find_one({"user": user_by_key(apikey), "id": id, "device": device, "date": save_date})
|
||||
|
||||
query = {"user": user_by_key(apikey), "id": id, "date": save_date}
|
||||
|
||||
if device is not None:
|
||||
query["device"] = device
|
||||
|
||||
saves_entry = col_saves.find_one(query)
|
||||
|
||||
if saves_entry is not None:
|
||||
del saves_entry["_id"]
|
||||
del saves_entry["file"]
|
||||
|
Loading…
Reference in New Issue
Block a user