More lenient attachment v2 migration
This commit is contained in:
parent
12b57601ac
commit
3f9032035f
4 changed files with 72 additions and 43 deletions
|
@ -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>>(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue