From a8c210165938cfa4da7ed6bc185af297d528d2aa Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Wed, 30 Jun 2021 15:32:52 -0400 Subject: Remove filename requirement for all moment upload --- src/screens/profile/CaptionScreen.tsx | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) (limited to 'src/screens/profile') diff --git a/src/screens/profile/CaptionScreen.tsx b/src/screens/profile/CaptionScreen.tsx index 364b81a3..da3efb06 100644 --- a/src/screens/profile/CaptionScreen.tsx +++ b/src/screens/profile/CaptionScreen.tsx @@ -69,7 +69,6 @@ const CaptionScreen: React.FC = ({route, navigation}) => { selectedTags ? selectedTags : [], ); const [taggedList, setTaggedList] = useState(''); - const mediaFilename = moment ? undefined : route.params.media!.filename; const mediaUri = moment ? moment.moment_url : route.params.media!.uri; // TODO: change this once moment refactor is done const isMediaAVideo = moment @@ -138,7 +137,7 @@ const CaptionScreen: React.FC = ({route, navigation}) => { const handleShare = async () => { setLoading(true); - if (moment || !mediaFilename || !title) { + if (moment || !title) { handleFailed(); return; } @@ -146,22 +145,16 @@ const CaptionScreen: React.FC = ({route, navigation}) => { let momentId; // separate upload logic for image/video if (isMediaAVideo) { - const presignedURL = await handlePresignedURL(mediaFilename, title); + const presignedURL = await handlePresignedURL(title); if (!presignedURL) { handleFailed(); return; } momentId = presignedURL.moment_id; // TODO: assume success for now - await handleVideoUpload(mediaFilename, mediaUri, presignedURL); + await handleVideoUpload(mediaUri, presignedURL); } else { - const momentResponse = await postMoment( - mediaFilename, - mediaUri, - caption, - title, - userId, - ); + const momentResponse = await postMoment(mediaUri, caption, title, userId); if (!momentResponse) { handleFailed(); return; @@ -252,7 +245,6 @@ const CaptionScreen: React.FC = ({route, navigation}) => { onPress={() => navigation.navigate('TagFriendsScreen', { media: { - filename: mediaFilename ?? '', uri: mediaUri, isVideo: isMediaAVideo, }, -- cgit v1.2.3-70-g09d2 From 29f64921943fb7016ab0db79e4c06377d617a3bf Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Thu, 1 Jul 2021 15:53:25 -0400 Subject: Add logic for handling new video upload handshake --- src/screens/profile/CaptionScreen.tsx | 14 +++++++++----- src/services/MomentService.ts | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) (limited to 'src/screens/profile') diff --git a/src/screens/profile/CaptionScreen.tsx b/src/screens/profile/CaptionScreen.tsx index da3efb06..05db8ed7 100644 --- a/src/screens/profile/CaptionScreen.tsx +++ b/src/screens/profile/CaptionScreen.tsx @@ -145,14 +145,18 @@ const CaptionScreen: React.FC = ({route, navigation}) => { let momentId; // separate upload logic for image/video if (isMediaAVideo) { - const presignedURL = await handlePresignedURL(title); - if (!presignedURL) { + const presignedURLResponse = await handlePresignedURL(title); + if (!presignedURLResponse) { handleFailed(); return; } - momentId = presignedURL.moment_id; - // TODO: assume success for now - await handleVideoUpload(mediaUri, presignedURL); + momentId = presignedURLResponse.moment_id; + const fileHash = presignedURLResponse.response_url.fields.key; + if (fileHash !== null && fileHash !== '' && fileHash !== undefined) { + await handleVideoUpload(mediaUri, presignedURLResponse); + } else { + handleFailed(); + } } else { const momentResponse = await postMoment(mediaUri, caption, title, userId); if (!momentResponse) { diff --git a/src/services/MomentService.ts b/src/services/MomentService.ts index 9e853a49..87bdfa40 100644 --- a/src/services/MomentService.ts +++ b/src/services/MomentService.ts @@ -289,7 +289,7 @@ export const handleVideoUpload = async ( uri: filePath, // other types such as 'quicktime' 'image' etc exist, and we can programmatically type this, but for now sticking with simple 'video' type: 'video', - name: 'moment.mov', // we don't care about filename, anything works + name: urlObj.response_url.fields.key, }); const response = await fetch(urlObj.response_url.url, { method: 'POST', -- cgit v1.2.3-70-g09d2