Skip to content

Commit

Permalink
Validate the decoded play id
Browse files Browse the repository at this point in the history
  • Loading branch information
thomaserlang committed Nov 4, 2023
1 parent 8959374 commit 5c0c482
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions seplis_play_server/dependencies.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import jwt
from sqlalchemy import select
from fastapi import HTTPException
from seplis_play_server import database, models
from seplis_play_server import database, logger, models, schemas
from seplis_play_server import config


async def get_metadata(play_id) -> list[dict]:
data = decode_play_id(play_id)
if data['type'] == 'series':
if data.type == 'series':
query = select(models.Episode.meta_data).where(
models.Episode.series_id == data['series_id'],
models.Episode.number == data['number'],
models.Episode.series_id == data.series_id,
models.Episode.number == data.number,
)
elif data['type'] == 'movie':
elif data.type == 'movie':
query = select(models.Movie.meta_data).where(
models.Movie.movie_id == data['movie_id'],
models.Movie.movie_id == data.movie_id,
)
else:
raise HTTPException(400, 'Play id type not supported')
Expand All @@ -30,6 +30,7 @@ def decode_play_id(play_id: str):
config.secret,
algorithms=['HS256'],
)
return data
except Exception as e:
return schemas.Play_id.model_validate(data)
except jwt.PyJWTError as e:
logger.error(f'Failed to decode play id: {e}')
raise HTTPException(400, 'Play id invalid')

0 comments on commit 5c0c482

Please sign in to comment.