From 7d73f9a593e7d32bb2cb9d7d1b81e9f02994eeb9 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Wed, 26 May 2021 14:14:14 +1000 Subject: [PATCH] drop support for old file server avatar download --- ts/receiver/attachments.ts | 19 ++++------- ts/receiver/dataMessage.ts | 65 ++++++++++++++++++++------------------ 2 files changed, 41 insertions(+), 43 deletions(-) diff --git a/ts/receiver/attachments.ts b/ts/receiver/attachments.ts index 92d1a7772..57d845009 100644 --- a/ts/receiver/attachments.ts +++ b/ts/receiver/attachments.ts @@ -35,21 +35,14 @@ export async function downloadAttachment(attachment: any) { } window?.log?.info('Download v2 file server attachment'); res = await FSv2.downloadFileFromFSv2(attachmentId); - } else if (!defaultFileserver) { - // TODO: we need attachments to remember which API should be used to retrieve them - const serverAPI = await window.lokiPublicChatAPI.findOrCreateServer(serverUrl); - - if (serverAPI) { - res = await serverAPI.downloadAttachment(attachment.url); - } - } - - // Fallback to using the default fileserver - if (defaultFileserver || !res || res.byteLength === 0) { - res = await window.lokiFileServerAPI.downloadAttachment(attachment.url); + } else { + window.log.warn( + 'downloadAttachment attachment is neither opengroup attachment nor fsv2... Dropping it' + ); + throw new Error('Attachment url is not opengroupv2 nor fileserver v2. Unsupported'); } - if (res.byteLength === 0) { + if (!res?.byteLength) { window?.log?.error('Failed to download attachment. Length is 0'); throw new Error(`Failed to download attachment. Length is 0 for ${attachment.url}`); } diff --git a/ts/receiver/dataMessage.ts b/ts/receiver/dataMessage.ts index 8584c20da..31e609a63 100644 --- a/ts/receiver/dataMessage.ts +++ b/ts/receiver/dataMessage.ts @@ -50,38 +50,43 @@ async function updateProfile( const needsUpdate = !prevPointer || !_.isEqual(prevPointer, profile.profilePicture); if (needsUpdate) { - const downloaded = await downloadAttachment({ - url: profile.profilePicture, - isRaw: true, - }); - - // null => use placeholder with color and first letter - let path = null; - if (profileKey) { - // Convert profileKey to ArrayBuffer, if needed - const encoding = typeof profileKey === 'string' ? 'base64' : null; - try { - const profileKeyArrayBuffer = dcodeIO.ByteBuffer.wrap( - profileKey, - encoding - ).toArrayBuffer(); - const decryptedData = await textsecure.crypto.decryptProfile( - downloaded.data, - profileKeyArrayBuffer - ); - const upgraded = await Signal.Migrations.processNewAttachment({ - ...downloaded, - data: decryptedData, - }); - // Only update the convo if the download and decrypt is a success - conversation.set('avatarPointer', profile.profilePicture); - conversation.set('profileKey', profileKey); - ({ path } = upgraded); - } catch (e) { - window?.log?.error(`Could not decrypt profile image: ${e}`); + try { + const downloaded = await downloadAttachment({ + url: profile.profilePicture, + isRaw: true, + }); + + // null => use placeholder with color and first letter + let path = null; + if (profileKey) { + // Convert profileKey to ArrayBuffer, if needed + const encoding = typeof profileKey === 'string' ? 'base64' : null; + try { + const profileKeyArrayBuffer = dcodeIO.ByteBuffer.wrap( + profileKey, + encoding + ).toArrayBuffer(); + const decryptedData = await textsecure.crypto.decryptProfile( + downloaded.data, + profileKeyArrayBuffer + ); + const upgraded = await Signal.Migrations.processNewAttachment({ + ...downloaded, + data: decryptedData, + }); + // Only update the convo if the download and decrypt is a success + conversation.set('avatarPointer', profile.profilePicture); + conversation.set('profileKey', profileKey); + ({ path } = upgraded); + } catch (e) { + window?.log?.error(`Could not decrypt profile image: ${e}`); + } } + newProfile.avatar = path; + } catch (e) { + window.log.warn('Failed to download attachment at', profile.profilePicture); + return; } - newProfile.avatar = path; } } else { newProfile.avatar = null;