New attachment storage system

This commit is contained in:
Fedor Indutny 2024-07-11 12:44:09 -07:00 committed by GitHub
parent 273e1ccb15
commit 28664a606f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
161 changed files with 2418 additions and 1562 deletions

View file

@ -1,11 +1,13 @@
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { pick } from 'lodash';
import * as log from '../logging/log';
import type { AttachmentDraftType } from '../types/Attachment';
import { isVideoAttachment } from '../types/Attachment';
import {
getLocalAttachmentUrl,
AttachmentDisposition,
} from './getLocalAttachmentUrl';
export function resolveDraftAttachmentOnDisk(
attachment: AttachmentDraftType
@ -16,29 +18,52 @@ export function resolveDraftAttachmentOnDisk(
}
if (attachment.screenshotPath) {
// Legacy
url = window.Signal.Migrations.getAbsoluteDraftPath(
attachment.screenshotPath
);
} else if (attachment.screenshot?.path) {
url = getLocalAttachmentUrl(attachment.screenshot, {
disposition: AttachmentDisposition.Draft,
});
} else if (!isVideoAttachment(attachment) && attachment.path) {
url = window.Signal.Migrations.getAbsoluteDraftPath(attachment.path);
url = getLocalAttachmentUrl(attachment, {
disposition: AttachmentDisposition.Draft,
});
} else {
log.warn(
'resolveOnDiskAttachment: Attachment was missing both screenshotPath and path fields'
);
}
const {
blurHash,
caption,
clientUuid,
contentType,
fileName,
flags,
path,
size,
width,
height,
version,
localKey,
} = attachment;
return {
...pick(attachment, [
'blurHash',
'caption',
'clientUuid',
'contentType',
'fileName',
'flags',
'path',
'size',
'width',
'height',
]),
blurHash,
caption,
clientUuid,
contentType,
fileName,
flags,
path,
size,
width,
height,
version,
localKey,
pending: false,
url,
};