2021-09-24 20:02:30 +00:00
|
|
|
// Copyright 2021 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import { pick } from 'lodash';
|
|
|
|
|
|
|
|
import * as log from '../logging/log';
|
2021-11-15 21:54:33 +00:00
|
|
|
import type { AttachmentDraftType } from '../types/Attachment';
|
|
|
|
import { isVideoAttachment } from '../types/Attachment';
|
2021-09-24 20:02:30 +00:00
|
|
|
|
2021-11-15 21:54:33 +00:00
|
|
|
export function resolveDraftAttachmentOnDisk(
|
|
|
|
attachment: AttachmentDraftType
|
|
|
|
): AttachmentDraftType {
|
2021-09-24 20:02:30 +00:00
|
|
|
let url = '';
|
|
|
|
if (attachment.pending) {
|
|
|
|
return attachment;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (attachment.screenshotPath) {
|
|
|
|
url = window.Signal.Migrations.getAbsoluteDraftPath(
|
|
|
|
attachment.screenshotPath
|
|
|
|
);
|
2021-11-15 21:54:33 +00:00
|
|
|
} else if (!isVideoAttachment(attachment) && attachment.path) {
|
2021-09-24 20:02:30 +00:00
|
|
|
url = window.Signal.Migrations.getAbsoluteDraftPath(attachment.path);
|
|
|
|
} else {
|
|
|
|
log.warn(
|
|
|
|
'resolveOnDiskAttachment: Attachment was missing both screenshotPath and path fields'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
...pick(attachment, [
|
|
|
|
'blurHash',
|
|
|
|
'caption',
|
|
|
|
'contentType',
|
|
|
|
'fileName',
|
2023-03-02 20:55:40 +00:00
|
|
|
'flags',
|
2021-09-24 20:02:30 +00:00
|
|
|
'path',
|
|
|
|
'size',
|
2021-11-30 23:32:55 +00:00
|
|
|
'width',
|
|
|
|
'height',
|
2021-09-24 20:02:30 +00:00
|
|
|
]),
|
|
|
|
pending: false,
|
|
|
|
url,
|
|
|
|
};
|
|
|
|
}
|