Don't transcode incoming attachments

This commit is contained in:
Fedor Indutny
2021-07-20 13:09:13 -07:00
committed by GitHub
parent 60ac4f1711
commit ff3b36d37b
3 changed files with 17 additions and 4 deletions

View File

@@ -5,6 +5,7 @@ const is = require('@sindresorhus/is');
const { arrayBufferToBlob, blobToArrayBuffer } = require('blob-util');
const AttachmentTS = require('../../../ts/types/Attachment');
const MIME = require('../../../ts/types/MIME');
const GoogleChrome = require('../../../ts/util/GoogleChrome');
const { toLogFormat } = require('./errors');
const { scaleImageToLevel } = require('../../../ts/util/scaleImageToLevel');
@@ -49,7 +50,15 @@ exports.isValid = rawAttachment => {
// Upgrade steps
// NOTE: This step strips all EXIF metadata from JPEG images as
// part of re-encoding the image:
exports.autoOrientJPEG = async (attachment, _, message) => {
exports.autoOrientJPEG = async (
attachment,
_,
{ sendHQImages = false, isIncoming = false } = {}
) => {
if (isIncoming && !MIME.isJPEG(attachment.contentType)) {
return attachment;
}
if (!AttachmentTS.canBeTranscoded(attachment)) {
return attachment;
}
@@ -65,7 +74,7 @@ exports.autoOrientJPEG = async (attachment, _, message) => {
);
const xcodedDataBlob = await scaleImageToLevel(
dataBlob,
message ? message.sendHQImages : false
sendHQImages || isIncoming
);
const xcodedDataArrayBuffer = await blobToArrayBuffer(xcodedDataBlob);

View File

@@ -458,7 +458,11 @@ exports.processNewAttachment = async (
throw new TypeError('context.logger is required');
}
const rotatedAttachment = await Attachment.autoOrientJPEG(attachment);
const rotatedAttachment = await Attachment.autoOrientJPEG(
attachment,
undefined,
{ isIncoming: true }
);
const onDiskAttachment = await Attachment.migrateDataToFileSystem(
rotatedAttachment,
{ writeNewAttachmentData }

View File

@@ -3672,7 +3672,7 @@ Whisper.ConversationView = Whisper.View.extend({
}
},
async sendStickerMessage(options: any = {}) {
async sendStickerMessage(options: { packId: string; stickerId: number }) {
const { model }: { model: ConversationModel } = this;
try {