From 345a20590da5fd1cabc85c4e7b0b72c05e1f0665 Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Wed, 23 Jun 2021 17:08:20 -0400 Subject: Squashed commit of the following: commit 8c2b915678b852f597c38ab00d18c22bf62d2051 Merge: cd586326 16f6341d Author: Ivan Chen Date: Wed Jun 23 16:26:12 2021 -0400 Merge pull request #473 from IvanIFChen/tma938-video-from-camera-video-streaming [TMA-938] Video From Camera & Video Streaming commit 16f6341daff56f827fbb6c6ade9cf1238e8e5f3e Author: Ivan Chen Date: Wed Jun 23 14:22:29 2021 -0400 Lint commit 7e7a3ea6b6462d295717db052c37d87e1f58a091 Author: Ivan Chen Date: Wed Jun 23 14:20:00 2021 -0400 Change to use image crop pickers instead commit 25d1a6514c9df784df27d22da648340ae018c1f8 Author: Ivan Chen Date: Wed Jun 23 13:37:39 2021 -0400 Minor logic cleanup commit 4ecc4525738dc8a56c9f37a05d0870e54cfa5be9 Author: Ivan Chen Date: Tue Jun 22 19:21:26 2021 -0400 Lint commit c3066187b9d253767e32880cc35ddd1abc6db6b3 Author: Ivan Chen Date: Tue Jun 22 19:16:04 2021 -0400 Remove test code commit ab13c937f1de947e68df03b443cf9fccb0cd54c9 Author: Ivan Chen Date: Tue Jun 22 19:14:06 2021 -0400 Add alert for gallery and camera commit 0561794c67d827c918029f2e06572fd03b4531fd Author: Ivan Chen Date: Tue Jun 22 18:51:57 2021 -0400 Finish poc for for video streaming commit 457b5cf34c032e7b73f972d5ba801ff420915190 Author: Ivan Chen Date: Tue Jun 22 18:37:20 2021 -0400 Squashed commit of the following: commit b6e4676b6ea262580453963ed6cfd85932d32341 Author: Ivan Chen Date: Mon Jun 21 19:04:08 2021 -0400 Add library, Add sample code commit 49dfe6a52e09bdb218e2b1ceb5a8df9ed46873f1 Author: Ivan Chen Date: Tue Jun 22 18:37:12 2021 -0400 Squashed commit of the following: commit b1c2002caa349dc96f81d3cc3e00ea545f4e654e Author: Ivan Chen Date: Tue Jun 22 15:28:18 2021 -0400 Add video for camerea commit ee890e517dd3688a4fd63c64592fdb6ce683d7b4 Author: Ivan Chen Date: Tue Jun 22 18:36:47 2021 -0400 Improve poc UX --- src/services/MomentService.ts | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'src/services') diff --git a/src/services/MomentService.ts b/src/services/MomentService.ts index d0ed56ab..da1bfb97 100644 --- a/src/services/MomentService.ts +++ b/src/services/MomentService.ts @@ -1,5 +1,4 @@ import AsyncStorage from '@react-native-community/async-storage'; -import {Image, Video} from 'react-native-image-crop-picker'; import RNFetchBlob from 'rn-fetch-blob'; import { MOMENTS_ENDPOINT, @@ -262,20 +261,17 @@ export const handlePresignedURL = async ( /** * This util function takes in the file object and the PresignedURLResponse object, creates form data from the latter, * and makes a post request to the presigned URL, sending the file object inside of the form data. - * @param file: Video, Image, Undefined + * @param filename: the filename + * @param filePath: the path to the file, including filename * @param urlObj PresignedURLResponse | undefined * @returns responseURL or boolean */ export const handleVideoUpload = async ( - file: Video | Image | undefined, + filename: string, + filePath: string, urlObj: PresignedURLResponse | undefined, ) => { try { - let fileName = file?.filename; - if (fileName === null || '') { - console.log('Invalid filename'); - return false; - } if (urlObj === null || urlObj === undefined) { console.log('Invalid urlObj'); return false; @@ -299,10 +295,10 @@ export const handleVideoUpload = async ( urlObj.response_url.fields['x-amz-signature'], ); form.append('file', { - uri: file?.sourceURL, + 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: fileName, + name: filename, }); const response = await fetch(urlObj.response_url.url, { method: 'POST', -- cgit v1.2.3-70-g09d2 From 9f835e1b82647477ec959a62b02dee4e9351b1b5 Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Wed, 23 Jun 2021 17:08:31 -0400 Subject: Clean up video upload logic --- src/screens/profile/CaptionScreen.tsx | 20 +++++++------------- src/services/MomentService.ts | 5 ++--- src/types/types.ts | 1 + 3 files changed, 10 insertions(+), 16 deletions(-) (limited to 'src/services') diff --git a/src/screens/profile/CaptionScreen.tsx b/src/screens/profile/CaptionScreen.tsx index 1b96face..d53570cb 100644 --- a/src/screens/profile/CaptionScreen.tsx +++ b/src/screens/profile/CaptionScreen.tsx @@ -147,19 +147,13 @@ const CaptionScreen: React.FC = ({route, navigation}) => { // separate upload logic for image/video if (isMediaAVideo) { const presignedURL = await handlePresignedURL(mediaFilename, title); - // TOOD: ignoring type error for PoC reason - const response: { - response_msg: string; - response_url: string; - moment_id: string; - } = handleVideoUpload( - { - filename: mediaFilename, - sourceURL: mediaUri, - }, - presignedURL, - ); - momentId = response.moment_id; + if (!presignedURL) { + handleFailed(); + return; + } + momentId = presignedURL.moment_id; + // TODO: assume success for now + await handleVideoUpload(mediaFilename, mediaUri, presignedURL); } else { const momentResponse = await postMoment( mediaFilename, diff --git a/src/services/MomentService.ts b/src/services/MomentService.ts index da1bfb97..ca32a3f3 100644 --- a/src/services/MomentService.ts +++ b/src/services/MomentService.ts @@ -311,7 +311,7 @@ export const handleVideoUpload = async ( // let data = await response.json(); if (status === 200 || status === 204) { console.log('complete'); - return response; + return true; } else { if (status === 404) { console.log( @@ -323,11 +323,10 @@ export const handleVideoUpload = async ( console.log(ERROR_SOMETHING_WENT_WRONG_REFRESH); } console.log(response); - return false; } } catch (error) { console.log(error); console.log(ERROR_SOMETHING_WENT_WRONG); - return false; } + return false; }; diff --git a/src/types/types.ts b/src/types/types.ts index f6f23fc8..416d9146 100644 --- a/src/types/types.ts +++ b/src/types/types.ts @@ -379,4 +379,5 @@ export type PresignedURLResponse = { 'x-amz-signature': string; }; }; + moment_id: string; }; -- cgit v1.2.3-70-g09d2