mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2025-12-24 20:26:24 +00:00
More lenient attachment v2 migration
This commit is contained in:
@@ -2,10 +2,12 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import LRU from 'lru-cache';
|
||||
|
||||
import type {
|
||||
AddressableAttachmentType,
|
||||
LocalAttachmentV2Type,
|
||||
} from '../types/Attachment';
|
||||
import * as log from '../logging/log';
|
||||
import { AttachmentDisposition } from './getLocalAttachmentUrl';
|
||||
|
||||
let setCheck = false;
|
||||
@@ -15,6 +17,7 @@ const lru = new LRU<string, Promise<LocalAttachmentV2Type>>({
|
||||
});
|
||||
|
||||
export type EncryptLegacyAttachmentOptionsType = Readonly<{
|
||||
logId: string;
|
||||
disposition?: AttachmentDisposition;
|
||||
readAttachmentData: (
|
||||
attachment: Partial<AddressableAttachmentType>
|
||||
@@ -43,12 +46,18 @@ export async function encryptLegacyAttachment<
|
||||
promise = doEncrypt(attachment, options);
|
||||
lru.set(cacheKey, promise);
|
||||
}
|
||||
const modern = await promise;
|
||||
try {
|
||||
const modern = await promise;
|
||||
|
||||
return {
|
||||
...attachment,
|
||||
...modern,
|
||||
};
|
||||
return {
|
||||
...attachment,
|
||||
...modern,
|
||||
};
|
||||
} catch (error) {
|
||||
const { logId } = options;
|
||||
log.error(`${logId}: migration failed, falling back to original`, error);
|
||||
return attachment;
|
||||
}
|
||||
}
|
||||
|
||||
async function doEncrypt<T extends Partial<AddressableAttachmentType>>(
|
||||
|
||||
Reference in New Issue
Block a user