diff --git a/src/index.tsx b/src/index.tsx index e3b9bd5..9b68601 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -25,6 +25,28 @@ const ApiVideoUploader = ApiVideoUploaderModule } ); +type ProgressiveUploadParams = { videoId: string }; +type ProgressiveUploadWithUploadTokenParams = { + token: string; + videoId?: string; +}; + +function isProgressiveUploadWithUploadTokenParams( + params: ProgressiveUploadWithUploadTokenParams | ProgressiveUploadParams +): params is ProgressiveUploadWithUploadTokenParams { + return ( + (params as ProgressiveUploadWithUploadTokenParams).token !== 'undefined' + ); +} + +function sanitizeVideo(videoJson: string): Video { + const video = JSON.parse(videoJson); + return { + ...video, + _public: video.public, + }; +} + export default { setApplicationName: (name: string, version: string): void => { ApiVideoUploader.setApplicationName(name, version); @@ -54,23 +76,56 @@ export default { token, filepath, videoId - ).then((value: string) => { - const json = JSON.parse(value); - - return { - ...json, - _public: json.public, - } as Video; - }); + ).then((value: string) => sanitizeVideo(value)); }, upload: (videoId: string, filepath: string): Promise