diff --git a/lib/actions/upload-actions.js b/lib/actions/upload-actions.js --- a/lib/actions/upload-actions.js +++ b/lib/actions/upload-actions.js @@ -9,7 +9,7 @@ import { extractKeyserverIDFromID } from '../keyserver-conn/keyserver-call-utils.js'; import { useKeyserverCall } from '../keyserver-conn/keyserver-call.js'; import type { CallKeyserverEndpoint } from '../keyserver-conn/keyserver-conn-types.js'; -import { type UploadBlob } from '../keyserver-conn/upload-blob.js'; +import { type PerformHTTPMultipartUpload } from '../keyserver-conn/multipart-upload.js'; import { IdentityClientContext } from '../shared/identity-client-context.js'; import type { AuthMetadata } from '../shared/identity-client-context.js'; import type { UploadMultimediaResult, Dimensions } from '../types/media-types'; @@ -28,7 +28,7 @@ export type MultimediaUploadCallbacks = Partial<{ +onProgress: (percent: number) => void, +abortHandler: (abort: () => void) => void, - +uploadBlob: UploadBlob, + +performHTTPMultipartUpload: PerformHTTPMultipartUpload, +blobServiceUploadHandler: BlobServiceUploadHandler, +timeout: ?number, }>; @@ -52,7 +52,8 @@ async (multimedia, extras, callbacks) => { const onProgress = callbacks && callbacks.onProgress; const abortHandler = callbacks && callbacks.abortHandler; - const uploadBlob = callbacks && callbacks.uploadBlob; + const performHTTPMultipartUpload = + callbacks && callbacks.performHTTPMultipartUpload; const stringExtras: { [string]: string } = {}; if (extras.height !== null && extras.height !== undefined) { @@ -85,7 +86,9 @@ { onProgress, abortHandler, - blobUpload: uploadBlob ? uploadBlob : true, + performHTTPMultipartUpload: performHTTPMultipartUpload + ? performHTTPMultipartUpload + : true, }, ); const [uploadResult] = response.results; diff --git a/lib/keyserver-conn/call-single-keyserver-endpoint.js b/lib/keyserver-conn/call-single-keyserver-endpoint.js --- a/lib/keyserver-conn/call-single-keyserver-endpoint.js +++ b/lib/keyserver-conn/call-single-keyserver-endpoint.js @@ -2,7 +2,10 @@ import _isEqual from 'lodash/fp/isEqual.js'; -import { uploadBlob, type UploadBlob } from './upload-blob.js'; +import { + defaultPerformHTTPMultipartUpload, + type PerformHTTPMultipartUpload, +} from './multipart-upload.js'; import { updateLastCommunicatedPlatformDetailsActionType } from '../actions/device-actions.js'; import { callSingleKeyserverEndpointTimeout } from '../shared/timeouts.js'; import type { PlatformDetails } from '../types/device-types.js'; @@ -29,13 +32,14 @@ import sleep from '../utils/sleep.js'; export type CallSingleKeyserverEndpointOptions = Partial<{ - // null timeout means no timeout, which is the default for uploadBlob + // null timeout means no timeout, which is the default for + // defaultPerformHTTPMultipartUpload +timeout: ?number, // in milliseconds // getResultInfo will be called right before callSingleKeyserverEndpoint // successfully resolves and includes additional information about the request +getResultInfo: (resultInfo: CallSingleKeyserverEndpointResultInfo) => mixed, - +blobUpload: boolean | UploadBlob, - // the rest (onProgress, abortHandler) only work with blobUpload + +performHTTPMultipartUpload: boolean | PerformHTTPMultipartUpload, + // onProgress and abortHandler only work with performHTTPMultipartUpload +onProgress: (percent: number) => void, // abortHandler will receive an abort function once the upload starts +abortHandler: (abort: () => void) => void, @@ -132,12 +136,18 @@ const url = resolvedURLPrefix ? `${resolvedURLPrefix}/${endpoint}` : endpoint; let json; - if (options && options.blobUpload) { - const uploadBlobCallback = - typeof options.blobUpload === 'function' - ? options.blobUpload - : uploadBlob; - json = await uploadBlobCallback(url, cookie, sessionID, input, options); + if (options && options.performHTTPMultipartUpload) { + const performHTTPMultipartUpload = + typeof options.performHTTPMultipartUpload === 'function' + ? options.performHTTPMultipartUpload + : defaultPerformHTTPMultipartUpload; + json = await performHTTPMultipartUpload( + url, + cookie, + sessionID, + input, + options, + ); } else { const mergedData: RequestData = { input }; mergedData.cookie = cookie ? cookie : null; diff --git a/lib/keyserver-conn/upload-blob.js b/lib/keyserver-conn/multipart-upload.js rename from lib/keyserver-conn/upload-blob.js rename to lib/keyserver-conn/multipart-upload.js --- a/lib/keyserver-conn/upload-blob.js +++ b/lib/keyserver-conn/multipart-upload.js @@ -9,7 +9,7 @@ } from './call-single-keyserver-endpoint.js'; import { getConfig } from '../utils/config.js'; -function uploadBlob( +function defaultPerformHTTPMultipartUpload( url: string, cookie: ?string, sessionID: ?string, @@ -111,6 +111,7 @@ return responsePromise; } -export type UploadBlob = typeof uploadBlob; +export type PerformHTTPMultipartUpload = + typeof defaultPerformHTTPMultipartUpload; -export { uploadBlob }; +export { defaultPerformHTTPMultipartUpload }; diff --git a/native/input/input-state-container.react.js b/native/input/input-state-container.react.js --- a/native/input/input-state-container.react.js +++ b/native/input/input-state-container.react.js @@ -922,7 +922,7 @@ 'uploading', percent, ), - uploadBlob: this.uploadBlob, + performHTTPMultipartUpload: this.performHTTPMultipartUpload, }, ); @@ -947,7 +947,7 @@ thumbHash: processedMedia.thumbHash, }, { - uploadBlob: this.uploadBlob, + performHTTPMultipartUpload: this.performHTTPMultipartUpload, }, ); })(); @@ -1174,7 +1174,7 @@ }); } - uploadBlob = async ( + performHTTPMultipartUpload = async ( url: string, cookie: ?string, sessionID: ?string, @@ -1188,14 +1188,14 @@ input.multimedia.length === 1 && input.multimedia[0] && typeof input.multimedia[0] === 'object', - 'InputStateContainer.uploadBlob sent incorrect input', + 'InputStateContainer.performHTTPMultipartUpload sent incorrect input', ); const { uri, name, type } = input.multimedia[0]; invariant( typeof uri === 'string' && typeof name === 'string' && typeof type === 'string', - 'InputStateContainer.uploadBlob sent incorrect input', + 'InputStateContainer.performHTTPMultipartUpload sent incorrect input', ); const parameters: { [key: string]: mixed } = {}; @@ -1214,7 +1214,8 @@ const value = input[key]; invariant( typeof value === 'string', - 'blobUpload calls can only handle string values for non-multimedia keys', + 'performHTTPMultipartUpload calls can only handle string values for ' + + 'non-multimedia keys', ); parameters[key] = value; }