More lenient attachment v2 migration

This commit is contained in:
Fedor Indutny 2024-07-15 14:27:54 -07:00 committed by GitHub
parent 12b57601ac
commit 3f9032035f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 72 additions and 43 deletions

View file

@ -466,21 +466,26 @@ const toVersion12 = _withSchemaVersion({
const result = { ...message };
const logId = `Message2.toVersion12(${message.sent_at})`;
if (attachments?.length) {
result.attachments = await Promise.all(
attachments.map(async attachment => {
const copy = await encryptLegacyAttachment(attachment, context);
attachments.map(async (attachment, i) => {
const copy = await encryptLegacyAttachment(attachment, {
...context,
logId: `${logId}.attachments[${i}]`,
});
if (copy.thumbnail) {
copy.thumbnail = await encryptLegacyAttachment(
copy.thumbnail,
context
);
copy.thumbnail = await encryptLegacyAttachment(copy.thumbnail, {
...context,
logId: `${logId}.attachments[${i}].thumbnail`,
});
}
if (copy.screenshot) {
copy.screenshot = await encryptLegacyAttachment(
copy.screenshot,
context
);
copy.screenshot = await encryptLegacyAttachment(copy.screenshot, {
...context,
logId: `${logId}.attachments[${i}].screenshot`,
});
}
return copy;
})
@ -488,31 +493,27 @@ const toVersion12 = _withSchemaVersion({
}
if (quote && quote.attachments?.length) {
try {
result.quote = {
...quote,
attachments: await Promise.all(
quote.attachments.map(async quoteAttachment => {
return {
...quoteAttachment,
thumbnail:
quoteAttachment.thumbnail &&
(await encryptLegacyAttachment(
quoteAttachment.thumbnail,
context
)),
};
})
),
};
} catch (error) {
context.logger.error(`Failed to migrate quote for ${message.id}`);
}
result.quote = {
...quote,
attachments: await Promise.all(
quote.attachments.map(async (quoteAttachment, i) => {
return {
...quoteAttachment,
thumbnail:
quoteAttachment.thumbnail &&
(await encryptLegacyAttachment(quoteAttachment.thumbnail, {
...context,
logId: `${logId}.quote[${i}].thumbnail`,
})),
};
})
),
};
}
if (contact?.length) {
result.contact = await Promise.all(
contact.map(async c => {
contact.map(async (c, i) => {
if (!c.avatar?.avatar) {
return c;
}
@ -521,7 +522,10 @@ const toVersion12 = _withSchemaVersion({
...c,
avatar: {
...c.avatar,
avatar: await encryptLegacyAttachment(c.avatar.avatar, context),
avatar: await encryptLegacyAttachment(c.avatar.avatar, {
...context,
logId: `${logId}.contact[${i}].avatar`,
}),
},
};
})
@ -530,14 +534,17 @@ const toVersion12 = _withSchemaVersion({
if (preview?.length) {
result.preview = await Promise.all(
preview.map(async p => {
preview.map(async (p, i) => {
if (!p.image) {
return p;
}
return {
...p,
image: await encryptLegacyAttachment(p.image, context),
image: await encryptLegacyAttachment(p.image, {
...context,
logId: `${logId}.preview[${i}].image`,
}),
};
})
);
@ -547,10 +554,16 @@ const toVersion12 = _withSchemaVersion({
result.sticker = {
...sticker,
data: sticker.data && {
...(await encryptLegacyAttachment(sticker.data, context)),
...(await encryptLegacyAttachment(sticker.data, {
...context,
logId: `${logId}.sticker.data`,
})),
thumbnail:
sticker.data.thumbnail &&
(await encryptLegacyAttachment(sticker.data.thumbnail, context)),
(await encryptLegacyAttachment(sticker.data.thumbnail, {
...context,
logId: `${logId}.sticker.thumbnail`,
})),
},
};
}

View file

@ -1009,6 +1009,7 @@ async function encryptLegacySticker(
window.Signal.Migrations;
const updated = await encryptLegacyAttachment(sticker, {
logId: 'sticker',
readAttachmentData: readStickerData,
writeNewAttachmentData: writeNewStickerData,
disposition: AttachmentDisposition.Sticker,