From ce768d895d5424089069497433bfc65922c99e42 Mon Sep 17 00:00:00 2001 From: Profitroll <47523801+profitrollgame@users.noreply.github.com> Date: Sat, 21 Jan 2023 18:02:36 +0100 Subject: [PATCH] Added getting the last save --- extensions/saves.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/extensions/saves.py b/extensions/saves.py index d5f031d..30465f0 100644 --- a/extensions/saves.py +++ b/extensions/saves.py @@ -1,7 +1,7 @@ from datetime import datetime from urllib.parse import quote_plus from os import remove -from typing import Dict, List, Union +from typing import Dict, List, Literal, Union from xmltodict import parse from models.saves import StardewSave from modules.app import app, get_api_key, user_by_key @@ -72,8 +72,8 @@ async def saves_get_by_id(id: int, device: Union[str, None] = None, version: Uni return UJSONResponse(output) -@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)): +@app.get("/saves/{id}/{save_date}", response_class=UJSONResponse, response_model=List[StardewSave], description="Get game saves by id and upload date") +async def saves_get_by_both_ids(id: int, save_date: Union[int, Literal["latest"]], device: Union[str, None] = None, apikey: APIKey = Depends(get_api_key)): query = {"user": user_by_key(apikey), "id": id, "date": save_date} @@ -90,7 +90,7 @@ async def saves_get_by_both_ids(id: int, save_date: int, device: Union[str, None raise HTTPException(HTTP_404_NOT_FOUND, detail="Could not find save with such id.") -@app.delete("/saves/{id}", description="Get game saves by name") +@app.delete("/saves/{id}", description="Delete game saves by id") async def saves_delete_by_id(id: int, apikey: APIKey = Depends(get_api_key)): user = user_by_key(apikey) if col_saves.count_documents({"user": user, "id": id}) > 0: @@ -103,7 +103,7 @@ async def saves_delete_by_id(id: int, apikey: APIKey = Depends(get_api_key)): raise HTTPException(HTTP_404_NOT_FOUND, detail="Could not find save with such id.") -@app.delete("/saves/{id}/{save_date}", response_class=UJSONResponse, description="Get game saves by name") +@app.delete("/saves/{id}/{save_date}", response_class=UJSONResponse, description="Delete game saves by id and upload date") async def saves_delete_by_both_ids(id: int, save_date: int, apikey: APIKey = Depends(get_api_key)): saves_entry = col_saves.find_one_and_delete({"id": id, "date": save_date}) if saves_entry is not None: @@ -113,7 +113,7 @@ async def saves_delete_by_both_ids(id: int, save_date: int, apikey: APIKey = Dep raise HTTPException(HTTP_404_NOT_FOUND, detail="Could not find save with such id.") -@app.get("/saves/{id}/{save_date}/download", response_class=FileResponse, description="Get game save as .svsave file by its id and save date") +@app.get("/saves/{id}/{save_date}/download", response_class=FileResponse, description="Get game save as .svsave file by its id and upload date") async def saves_download(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}) if saves_entry is not None: # type: ignore