From ff67d9178b4d8286729872e745cf0712166e17ea Mon Sep 17 00:00:00 2001 From: Josh Perez <60019601+josh-signal@users.noreply.github.com> Date: Wed, 7 Jul 2021 13:06:01 -0400 Subject: [PATCH] Transcode all supported image types --- js/modules/types/attachment.js | 3 +-- ts/types/Attachment.ts | 9 +++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/js/modules/types/attachment.js b/js/modules/types/attachment.js index 712d5a6c95..7881b3909a 100644 --- a/js/modules/types/attachment.js +++ b/js/modules/types/attachment.js @@ -6,7 +6,6 @@ const is = require('@sindresorhus/is'); const { arrayBufferToBlob, blobToArrayBuffer } = require('blob-util'); const AttachmentTS = require('../../../ts/types/Attachment'); const GoogleChrome = require('../../../ts/util/GoogleChrome'); -const MIME = require('../../../ts/types/MIME'); const { toLogFormat } = require('./errors'); const { scaleImageToLevel } = require('../../../ts/util/scaleImageToLevel'); const { @@ -51,7 +50,7 @@ exports.isValid = rawAttachment => { // NOTE: This step strips all EXIF metadata from JPEG images as // part of re-encoding the image: exports.autoOrientJPEG = async (attachment, _, message) => { - if (!MIME.isJPEG(attachment.contentType)) { + if (!AttachmentTS.canBeTranscoded(attachment)) { return attachment; } diff --git a/ts/types/Attachment.ts b/ts/types/Attachment.ts index e32713cadb..f3e3234cfd 100644 --- a/ts/types/Attachment.ts +++ b/ts/types/Attachment.ts @@ -181,6 +181,15 @@ export function isImageAttachment( isImageTypeSupported(attachment.contentType) ); } + +export function canBeTranscoded( + attachment?: AttachmentType +): attachment is AttachmentType { + return Boolean( + isImageAttachment(attachment) && !MIME.isGif(attachment.contentType) + ); +} + export function hasImage( attachments?: Array ): string | boolean | undefined {