From dc746646d6fc3dccd4e0a98802f9e64c5c613206 Mon Sep 17 00:00:00 2001 From: Ely Deckers Date: Mon, 17 Jan 2022 22:52:13 +0100 Subject: [PATCH 1/3] refactor: adapt interface for raw upload --- src/ExposedTypes.tsx | 4 ++++ src/index.tsx | 57 +++++++++++++++++++++++++++++++------------- 2 files changed, 44 insertions(+), 17 deletions(-) diff --git a/src/ExposedTypes.tsx b/src/ExposedTypes.tsx index 63694afc..4ad4158e 100644 --- a/src/ExposedTypes.tsx +++ b/src/ExposedTypes.tsx @@ -4,6 +4,10 @@ * This source code is licensed under the MPL-2.0 license found in the * LICENSE file in the root directory of this source tree. */ +export declare interface BlobRequestBody { + readonly body?: string; +} + export declare interface BlobRequestHeaders { readonly headers?: { [key: string]: string }; } diff --git a/src/index.tsx b/src/index.tsx index 107a6ad0..dedce6c4 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -42,6 +42,8 @@ type BlobFetchNativeInput = BlobFetchInput & BlobRequestTask; type BlobUploadNativeInput = BlobUploadInput & BlobRequestTask; +type BlobUploadType = 'raw' | 'multipart'; + type BlobUploadMultipartInput = BlobMultipartMapUploadRequest & BlobRequestSettings; @@ -248,9 +250,16 @@ const uploadParts = ( input.signal ); -const uploadBlob = (input: Readonly) => { +const uploadBlob = ( + input: Readonly, + type: BlobUploadType +) => { const { absoluteFilePath, filename, mimeType, multipartName } = input; + if (type !== 'multipart') { + throw new Error('Raw uploadBlob not implemented'); + } + return uploadParts({ ...input, parts: { @@ -265,7 +274,6 @@ const uploadBlob = (input: Readonly) => { }, }); }; - const onProgress = ( taskId: string, fn: (e: BlobProgressEvent) => void, @@ -278,13 +286,19 @@ const onProgress = ( onProgress: fn, taskId, }), - uploadBlob: (input: BlobUploadRequest) => - uploadBlob({ - ...input, - ...requestSettings, - onProgress: fn, - taskId, - }), + /** + * @deprecated This behavior of this method will change from multipart to raw in a future version. For multipart upload use `uploadBlobMultipart` instead. + */ + uploadBlob: (input: BlobUploadRequest, type: BlobUploadType = 'multipart') => + uploadBlob( + { + ...input, + ...requestSettings, + onProgress: fn, + taskId, + }, + type + ), uploadParts: (input: BlobUploadMultipartInput) => uploadParts({ ...input, @@ -327,12 +341,18 @@ const settings = (taskId: string, requestSettings: BlobRequestSettings) => ({ }), onProgress: (fn: (e: BlobProgressEvent) => void) => onProgress(taskId, fn, requestSettings), - uploadBlob: (input: BlobUploadRequest) => - uploadBlob({ - ...input, - ...requestSettings, - taskId, - }), + /** + * @deprecated This behavior of this method will change from multipart to raw in a future version. For multipart upload use `uploadBlobMultipart` instead. + */ + uploadBlob: (input: BlobUploadRequest, type: BlobUploadType = 'multipart') => + uploadBlob( + { + ...input, + ...requestSettings, + taskId, + }, + type + ), uploadParts: (input: BlobUploadMultipartInput) => uploadParts({ ...input, @@ -355,8 +375,11 @@ export default { onProgress: (fn: (e: BlobProgressEvent) => void) => onProgress(createTaskId(), fn), settings: (input: BlobRequestSettings) => settings(createTaskId(), input), - uploadBlob: (input: BlobUploadInput) => - uploadBlob({ ...input, taskId: createTaskId() }), + /** + * @deprecated This behavior of this method will change from multipart to raw in a future version. For multipart upload use `uploadBlobMultipart` instead. + */ + uploadBlob: (input: BlobUploadInput, type: BlobUploadType = 'multipart') => + uploadBlob({ ...input, taskId: createTaskId() }, type), uploadParts: (input: BlobUploadMultipartInput) => uploadParts({ ...input, taskId: createTaskId() }), useDownloadManagerOnAndroid: ( From a308656b28aed31c12168cf42e106fd3d2d4ab32 Mon Sep 17 00:00:00 2001 From: Ely Deckers Date: Thu, 10 Feb 2022 23:30:08 +0100 Subject: [PATCH 2/3] chore: split android dl manager interface from raw request --- src/ExposedTypes.tsx | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src/ExposedTypes.tsx b/src/ExposedTypes.tsx index 4ad4158e..4f39624b 100644 --- a/src/ExposedTypes.tsx +++ b/src/ExposedTypes.tsx @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ export declare interface BlobRequestBody { - readonly body?: string; + readonly body?: BlobBodyData; } export declare interface BlobRequestHeaders { @@ -37,15 +37,27 @@ export declare interface BlobBaseRequest BlobRequestOnProgress, BlobRequestUrl {} -export declare interface BlobFetchRequest +export declare interface BlobRawFetchRequest extends BlobBaseRequest, + BlobRequestBody, BlobRequestMimeType, BlobRequestMethod, - AndroidFetchSettings, + AndroidFetchWithoutManagerSettings, IOSFetchSettings { readonly filename: string; } +export declare interface BlobAndroidManagerFetchRequest + extends BlobBaseRequest, + AndroidFetchWithManagerSettings, + IOSFetchSettings { + readonly filename: string; +} + +export type BlobFetchRequest = + | BlobRawFetchRequest + | BlobAndroidManagerFetchRequest; + export declare interface AndroidDownloadManagerToggle { readonly useDownloadManager?: boolean; } @@ -64,12 +76,17 @@ export type TargetType = 'cache' | 'data'; export declare interface TargetSettings { target?: TargetType; } -export declare interface AndroidFetchSettings { + +export declare interface AndroidFetchWithManagerSettings { readonly android?: AndroidDownloadManagerToggle & AndroidDownloadManager & TargetSettings; } +export declare interface AndroidFetchWithoutManagerSettings { + readonly android?: TargetSettings; +} + export declare interface IOSFetchSettings { readonly ios?: TargetSettings; } @@ -80,6 +97,7 @@ export declare interface BlobProgressEvent { } export declare type BlobMultipartFormData = string | { [key: string]: any }; +export declare type BlobBodyData = string | { [key: string]: any }; export declare type BlobMultipartType = 'file' | 'string'; export declare type BlobMultipart = { payload: BlobMultipartFormData | BlobMultipartFormDataFile; @@ -100,6 +118,7 @@ export declare interface BlobMultipartFormDataFile { export declare interface BlobUploadRequest extends BlobBaseRequest, + BlobRequestBody, BlobRequestMimeType, BlobRequestMethod, BlobRequestReturnResponse { @@ -163,7 +182,6 @@ export declare interface BlobUploadResponse extends BlobUnmanagedData {} export type BlobFetchInput = BlobFetchRequest & BlobRequestSettings & - AndroidFetchSettings & IOSFetchSettings; export type BlobUploadInput = BlobUploadRequest & BlobRequestSettings; From d5093defa2427c798ee332af4a8fe63a0f825146 Mon Sep 17 00:00:00 2001 From: Ely Deckers Date: Wed, 23 Feb 2022 19:42:20 +0100 Subject: [PATCH 3/3] chore: allow mime-type on DL manager request --- src/ExposedTypes.tsx | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/ExposedTypes.tsx b/src/ExposedTypes.tsx index 4f39624b..507a11e5 100644 --- a/src/ExposedTypes.tsx +++ b/src/ExposedTypes.tsx @@ -37,22 +37,25 @@ export declare interface BlobBaseRequest BlobRequestOnProgress, BlobRequestUrl {} +export declare interface BlobRequestFilename { + readonly filename: string; +} + export declare interface BlobRawFetchRequest extends BlobBaseRequest, BlobRequestBody, - BlobRequestMimeType, + BlobRequestFilename, BlobRequestMethod, + BlobRequestMimeType, AndroidFetchWithoutManagerSettings, - IOSFetchSettings { - readonly filename: string; -} + IOSFetchSettings {} export declare interface BlobAndroidManagerFetchRequest extends BlobBaseRequest, + BlobRequestFilename, + BlobRequestMimeType, AndroidFetchWithManagerSettings, - IOSFetchSettings { - readonly filename: string; -} + IOSFetchSettings {} export type BlobFetchRequest = | BlobRawFetchRequest