drop support for old file server avatar download

pull/1624/head
Audric Ackermann 4 years ago
parent 88036edd38
commit 7d73f9a593
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4

@ -35,21 +35,14 @@ export async function downloadAttachment(attachment: any) {
} }
window?.log?.info('Download v2 file server attachment'); window?.log?.info('Download v2 file server attachment');
res = await FSv2.downloadFileFromFSv2(attachmentId); res = await FSv2.downloadFileFromFSv2(attachmentId);
} else if (!defaultFileserver) { } else {
// TODO: we need attachments to remember which API should be used to retrieve them window.log.warn(
const serverAPI = await window.lokiPublicChatAPI.findOrCreateServer(serverUrl); 'downloadAttachment attachment is neither opengroup attachment nor fsv2... Dropping it'
);
if (serverAPI) { throw new Error('Attachment url is not opengroupv2 nor fileserver v2. Unsupported');
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);
} }
if (res.byteLength === 0) { if (!res?.byteLength) {
window?.log?.error('Failed to download attachment. Length is 0'); window?.log?.error('Failed to download attachment. Length is 0');
throw new Error(`Failed to download attachment. Length is 0 for ${attachment.url}`); throw new Error(`Failed to download attachment. Length is 0 for ${attachment.url}`);
} }

@ -50,38 +50,43 @@ async function updateProfile(
const needsUpdate = !prevPointer || !_.isEqual(prevPointer, profile.profilePicture); const needsUpdate = !prevPointer || !_.isEqual(prevPointer, profile.profilePicture);
if (needsUpdate) { if (needsUpdate) {
const downloaded = await downloadAttachment({ try {
url: profile.profilePicture, const downloaded = await downloadAttachment({
isRaw: true, url: profile.profilePicture,
}); isRaw: true,
});
// null => use placeholder with color and first letter
let path = null; // null => use placeholder with color and first letter
if (profileKey) { let path = null;
// Convert profileKey to ArrayBuffer, if needed if (profileKey) {
const encoding = typeof profileKey === 'string' ? 'base64' : null; // Convert profileKey to ArrayBuffer, if needed
try { const encoding = typeof profileKey === 'string' ? 'base64' : null;
const profileKeyArrayBuffer = dcodeIO.ByteBuffer.wrap( try {
profileKey, const profileKeyArrayBuffer = dcodeIO.ByteBuffer.wrap(
encoding profileKey,
).toArrayBuffer(); encoding
const decryptedData = await textsecure.crypto.decryptProfile( ).toArrayBuffer();
downloaded.data, const decryptedData = await textsecure.crypto.decryptProfile(
profileKeyArrayBuffer downloaded.data,
); profileKeyArrayBuffer
const upgraded = await Signal.Migrations.processNewAttachment({ );
...downloaded, const upgraded = await Signal.Migrations.processNewAttachment({
data: decryptedData, ...downloaded,
}); data: decryptedData,
// Only update the convo if the download and decrypt is a success });
conversation.set('avatarPointer', profile.profilePicture); // Only update the convo if the download and decrypt is a success
conversation.set('profileKey', profileKey); conversation.set('avatarPointer', profile.profilePicture);
({ path } = upgraded); conversation.set('profileKey', profileKey);
} catch (e) { ({ path } = upgraded);
window?.log?.error(`Could not decrypt profile image: ${e}`); } 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 { } else {
newProfile.avatar = null; newProfile.avatar = null;

Loading…
Cancel
Save