diff --git a/ts/types/Attachment.ts b/ts/types/Attachment.ts index 5d4af1c1695..c9c9be9cf58 100644 --- a/ts/types/Attachment.ts +++ b/ts/types/Attachment.ts @@ -38,6 +38,7 @@ import { import { missingCaseError } from '../util/missingCaseError.js'; import type { MakeVideoScreenshotResultType } from './VisualAttachment.js'; import type { MessageAttachmentType } from './AttachmentDownload.js'; +import { strictAssert } from '../util/assert.js'; const { isNumber, @@ -541,6 +542,11 @@ export async function captureDimensionsAndScreenshot( const localUrl = getLocalAttachmentUrl(attachment); if (GoogleChrome.isImageTypeSupported(contentType)) { + // Already generated thumbnail / width / height + if (attachment.thumbnail?.path) { + return attachment; + } + try { const { width, height } = await getImageDimensionsFromURL({ objectUrl: localUrl, @@ -586,6 +592,16 @@ export async function captureDimensionsAndScreenshot( } } + strictAssert( + GoogleChrome.isVideoTypeSupported(contentType), + 'enforced by early return' + ); + + // Already generated screenshot / width / height + if (attachment.screenshot?.path) { + return attachment; + } + let screenshotObjectUrl: string | undefined; try { const { blob, duration } = await makeVideoScreenshot({