From 58c7af6c6043932aeecd3bd872b10dc74936a3db Mon Sep 17 00:00:00 2001 From: automated-signal <37887102+automated-signal@users.noreply.github.com> Date: Fri, 3 Oct 2025 11:43:16 -0500 Subject: [PATCH] Avoid regenerating thumbnail or screenshot on edit --- ts/types/Attachment.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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({