feat(chalice): added a new endpoint for pre-replay (pre-signed url for a first mob file) (#2100)

This commit is contained in:
Alexander 2024-04-17 12:38:14 +02:00 committed by GitHub
parent ceb714617e
commit 872d50671b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 31 additions and 0 deletions

View file

@ -28,6 +28,17 @@ def __get_mob_keys_deprecated(session_id):
return [str(session_id), str(session_id) + "e"]
def get_first_url(project_id, session_id, check_existence: bool = True):
k = __get_mob_keys(project_id=project_id, session_id=session_id)[0]
if check_existence and not StorageClient.exists(bucket=config("sessions_bucket"), key=k):
return None
return StorageClient.get_presigned_url_for_sharing(
bucket=config("sessions_bucket"),
expires_in=config("PRESIGNED_URL_EXPIRATION", cast=int, default=900),
key=k
)
def get_urls(project_id, session_id, check_existence: bool = True):
results = []
for k in __get_mob_keys(project_id=project_id, session_id=session_id):

View file

@ -91,6 +91,11 @@ def get_by_id2_pg(project_id, session_id, context: schemas.CurrentContext, full_
return None
def get_pre_replay(project_id, session_id, context: schemas.CurrentContext):
return {
'domURL': [sessions_mobs.get_first_url(project_id=project_id, session_id=session_id, check_existence=False)]}
def get_replay(project_id, session_id, context: schemas.CurrentContext, full_data=False, include_fav_viewed=False,
group_metadata=False, live=True):
with pg_client.PostgresClient() as cur:

View file

@ -253,6 +253,21 @@ def session_ids_search(projectId: int, data: schemas.SessionsSearchPayloadSchema
return {'data': data}
@app.get('/{projectId}/sessions/{sessionId}/first-mob', tags=["sessions", "replay"])
def get_first_mob_file(projectId: int, sessionId: Union[int, str], background_tasks: BackgroundTasks,
context: schemas.CurrentContext = Depends(OR_context)):
if not sessionId.isnumeric():
return {"errors": ["session not found"]}
else:
sessionId = int(sessionId)
data = sessions_replay.get_pre_replay(project_id=projectId, session_id=sessionId, context=context)
if data is None:
return {"errors": ["session not found"]}
return {
'data': data
}
@app.get('/{projectId}/sessions/{sessionId}/replay', tags=["sessions", "replay"])
def get_session_events(projectId: int, sessionId: Union[int, str], background_tasks: BackgroundTasks,
context: schemas.CurrentContext = Depends(OR_context)):