From af15c506610214c4bcd4d642454048d2789d86dd Mon Sep 17 00:00:00 2001 From: Robert Bo Davis Date: Fri, 8 Sep 2023 11:18:28 -0400 Subject: [PATCH] CHI-1348 - Use new files-url lambda instead of serverless getDownloadUrl function (#1638) * Added generateExternalMediaUrl fn * refactor: abstract away recording path * refactor: only load metadata to check for error * chore: remove console log --------- Co-authored-by: mythilytm --- .../contact/MediaSection/RecordingSection.tsx | 20 ++++++++++++------- .../src/services/ContactService.ts | 4 ++++ .../src/services/InsightsService.ts | 6 ++++-- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/plugin-hrm-form/src/components/contact/MediaSection/RecordingSection.tsx b/plugin-hrm-form/src/components/contact/MediaSection/RecordingSection.tsx index 3a676607a7..9160a66fb8 100644 --- a/plugin-hrm-form/src/components/contact/MediaSection/RecordingSection.tsx +++ b/plugin-hrm-form/src/components/contact/MediaSection/RecordingSection.tsx @@ -19,7 +19,8 @@ import CircularProgress from '@material-ui/core/CircularProgress'; import { ErrorFont, LoadMediaButton, LoadMediaButtonText } from './styles'; import { S3StoredRecording } from '../../../types/types'; -import { getFileDownloadUrl } from '../../../services/ServerlessService'; +import { generateExternalMediaPath } from '../../../services/ContactService'; +import fetchHrmApi from '../../../services/fetchHrmApi'; type OwnProps = { contactId: string; externalStoredRecording: S3StoredRecording }; @@ -34,11 +35,16 @@ const RecordingSection: React.FC = ({ contactId, externalStoredRecordi setLoading(true); setShowButton(false); - const recordingPreSignedUrl = await getFileDownloadUrl(externalStoredRecording.location.key); - const recordingResponse = await fetch(recordingPreSignedUrl.downloadUrl); - const recordingBlob = await recordingResponse.blob(); - const voiceRecording = new Audio(URL.createObjectURL(recordingBlob)); - setVoiceRecording(voiceRecording.src); + // TODO: this won't currently work for local dev env + const { media_url: recordingPreSignedUrl } = await fetchHrmApi( + generateExternalMediaPath( + contactId, + externalStoredRecording.location.bucket, + externalStoredRecording.location.key, + ), + ); + + setVoiceRecording(recordingPreSignedUrl); setLoading(false); } catch (error) { @@ -86,7 +92,7 @@ const RecordingSection: React.FC = ({ contactId, externalStoredRecordi return (
{voiceRecording ? ( -