From e60e3b436d2c5e225fed7808629f95e90ea56876 Mon Sep 17 00:00:00 2001 From: Olivier Lando Date: Tue, 2 Apr 2024 18:19:49 +0200 Subject: [PATCH] add createProgressiveUploadSession() --- src/index.tsx | 85 ++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 70 insertions(+), 15 deletions(-) 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