diff --git a/api/chalicelib/core/sessions_mobs.py b/api/chalicelib/core/sessions_mobs.py index 6856fd2b7..9b28a0cb9 100644 --- a/api/chalicelib/core/sessions_mobs.py +++ b/api/chalicelib/core/sessions_mobs.py @@ -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): diff --git a/api/chalicelib/core/sessions_replay.py b/api/chalicelib/core/sessions_replay.py index 05b7db99b..48c02f862 100644 --- a/api/chalicelib/core/sessions_replay.py +++ b/api/chalicelib/core/sessions_replay.py @@ -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: diff --git a/api/routers/core_dynamic.py b/api/routers/core_dynamic.py index f97ea6c23..82a314539 100644 --- a/api/routers/core_dynamic.py +++ b/api/routers/core_dynamic.py @@ -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)):