Skip to content

Commit

Permalink
Add /nx/forwarder/{console}/{tid} route for console-specific forwar…
Browse files Browse the repository at this point in the history
…der requests

- Introduced a new route `/nx/forwarder/{console}/{tid}` to handle requests for retro forwarders by specifying the console type.
- Added validation to ensure that the requested console matches the TID's actual console, returning a 400 error if there's a mismatch.
- Enhanced flexibility for retrieving retro forwarders by allowing console-specific queries.
  • Loading branch information
Lenochxd committed Sep 8, 2024
1 parent 86100bc commit 1cc39e8
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def format_json_dates(data: dict) -> dict:
@app.get('/{platform}/{tid}')
@app.get('/{platform}/{tid}/{asset_type}')
@app.get('/{platform}/{tid}/{asset_type}/{screen_id}')
async def get_nx(platform: str, tid: str, asset_type: str = None, screen_id: int = 1):
async def get_nx(platform: str, tid: str, asset_type: str = None, screen_id = 1):
if platform.lower() not in ['nx', 'switch']:
raise HTTPException(status_code=404, detail=f"Platform {platform} not supported")

Expand All @@ -223,6 +223,16 @@ async def get_nx(platform: str, tid: str, asset_type: str = None, screen_id: int
tid = asset_type
console, id_type, file_path = find_id_type(tid)

if (console, id_type, file_path) == (None, None, None):
asked_console = asset_type.lower()
tid = screen_id
console, id_type, file_path = find_id_type(tid)
if id_type is not None:
console = console.lower()
if console != asked_console:
raise HTTPException(status_code=400, detail=f"Invalid console or title ID combination. Asked for console: {asked_console}, but title ID is for console: {console}")


if id_type is None:
raise HTTPException(status_code=404, detail="Item not found")
if id_type.upper() != type.replace('FORWARDER','RETRO'):
Expand Down

0 comments on commit 1cc39e8

Please sign in to comment.