signal-desktop/ts/util/resolveDraftAttachmentOnDisk.ts

73 lines
1.5 KiB
TypeScript
Raw Normal View History

2021-09-24 16:02:30 -04:00
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { createLogger } from '../logging/log.js';
import type { AttachmentDraftType } from '../types/Attachment.js';
import { isVideoAttachment } from '../types/Attachment.js';
2024-07-11 12:44:09 -07:00
import {
getLocalAttachmentUrl,
AttachmentDisposition,
} from './getLocalAttachmentUrl.js';
2021-09-24 16:02:30 -04:00
2025-06-16 11:59:31 -07:00
const log = createLogger('resolveDraftAttachmentOnDisk');
export function resolveDraftAttachmentOnDisk(
attachment: AttachmentDraftType
): AttachmentDraftType {
2021-09-24 16:02:30 -04:00
let url = '';
if (attachment.pending) {
return attachment;
}
if (attachment.screenshotPath) {
2024-07-11 12:44:09 -07:00
// Legacy
2021-09-24 16:02:30 -04:00
url = window.Signal.Migrations.getAbsoluteDraftPath(
attachment.screenshotPath
);
2024-07-11 12:44:09 -07:00
} else if (attachment.screenshot?.path) {
url = getLocalAttachmentUrl(attachment.screenshot, {
disposition: AttachmentDisposition.Draft,
});
} else if (!isVideoAttachment(attachment) && attachment.path) {
2024-07-11 12:44:09 -07:00
url = getLocalAttachmentUrl(attachment, {
disposition: AttachmentDisposition.Draft,
});
2021-09-24 16:02:30 -04:00
} else {
log.warn(
'resolveOnDiskAttachment: Attachment was missing both screenshotPath and path fields'
);
}
2024-07-11 12:44:09 -07:00
const {
blurHash,
caption,
clientUuid,
contentType,
fileName,
flags,
path,
size,
width,
height,
version,
localKey,
} = attachment;
2021-09-24 16:02:30 -04:00
return {
2024-07-11 12:44:09 -07:00
blurHash,
caption,
clientUuid,
contentType,
fileName,
flags,
path,
size,
width,
height,
version,
localKey,
2021-09-24 16:02:30 -04:00
pending: false,
url,
};
}