From 45425c158d0106325310e2f4f274b6548be062ca Mon Sep 17 00:00:00 2001 From: automated-signal <37887102+automated-signal@users.noreply.github.com> Date: Thu, 11 Jul 2024 17:59:40 -0500 Subject: [PATCH] Restart input stream on retried request Co-authored-by: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com> --- ts/textsecure/WebAPI.ts | 8 ++++---- ts/util/uploadAttachment.ts | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ts/textsecure/WebAPI.ts b/ts/textsecure/WebAPI.ts index 328599b2e57..7553766d164 100644 --- a/ts/textsecure/WebAPI.ts +++ b/ts/textsecure/WebAPI.ts @@ -169,7 +169,7 @@ type PromiseAjaxOptionsType = { basicAuth?: string; certificateAuthority?: string; contentType?: string; - data?: Uint8Array | Readable | string; + data?: Uint8Array | (() => Readable) | string; disableRetries?: boolean; disableSessionResumption?: boolean; headers?: HeaderListType; @@ -299,7 +299,7 @@ async function getFetchOptions( const fetchOptions = { method: options.type, - body: options.data, + body: typeof options.data === 'function' ? options.data() : options.data, headers: { 'User-Agent': getUserAgent(options.version), 'X-Signal-Agent': 'OWD', @@ -1303,7 +1303,7 @@ export type WebAPIType = { elements: VerifyServiceIdRequestType ) => Promise; putEncryptedAttachment: ( - encryptedBin: Uint8Array | Readable, + encryptedBin: Uint8Array | (() => Readable), uploadForm: AttachmentV3ResponseType ) => Promise; putProfile: ( @@ -3530,7 +3530,7 @@ export function initialize({ } async function putEncryptedAttachment( - encryptedBin: Uint8Array | Readable, + encryptedBin: Uint8Array | (() => Readable), uploadForm: AttachmentV3ResponseType ) { const { signedUploadLocation, headers } = uploadForm; diff --git a/ts/util/uploadAttachment.ts b/ts/util/uploadAttachment.ts index 3ef5ae29b37..ca2492f2c4e 100644 --- a/ts/util/uploadAttachment.ts +++ b/ts/util/uploadAttachment.ts @@ -146,7 +146,7 @@ export async function uploadFile({ }); } else { await server.putEncryptedAttachment( - createReadStream(absoluteCiphertextPath), + () => createReadStream(absoluteCiphertextPath), uploadForm ); }