"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "js/modules/types/attachment.js" between
Signal-Desktop-1.35.2.tar.gz and Signal-Desktop-1.36.1.tar.gz

About: Signal-Desktop is a cross-platform encrypted messaging service (also available for mobile devices).

attachment.js  (Signal-Desktop-1.35.2):attachment.js  (Signal-Desktop-1.36.1)
const is = require('@sindresorhus/is'); const is = require('@sindresorhus/is');
const AttachmentTS = require('../../../ts/types/Attachment');
const GoogleChrome = require('../../../ts/util/GoogleChrome');
const MIME = require('../../../ts/types/MIME');
const { toLogFormat } = require('./errors');
const { const {
arrayBufferToBlob, arrayBufferToBlob,
blobToArrayBuffer, blobToArrayBuffer,
dataURLToBlob, dataURLToBlob,
} = require('blob-util'); } = 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 { autoOrientImage } = require('../auto_orient_image'); const { autoOrientImage } = require('../auto_orient_image');
const { const {
migrateDataToFileSystem, migrateDataToFileSystem,
} = require('./attachment/migrate_data_to_file_system'); } = require('./attachment/migrate_data_to_file_system');
// // Incoming message attachment fields // // Incoming message attachment fields
// { // {
// id: string // id: string
// contentType: MIMEType // contentType: MIMEType
// data: ArrayBuffer // data: ArrayBuffer
skipping to change at line 76 skipping to change at line 76
attachment.contentType attachment.contentType
); );
const newDataBlob = await dataURLToBlob(await autoOrientImage(dataBlob)); const newDataBlob = await dataURLToBlob(await autoOrientImage(dataBlob));
const newDataArrayBuffer = await blobToArrayBuffer(newDataBlob); const newDataArrayBuffer = await blobToArrayBuffer(newDataBlob);
// IMPORTANT: We overwrite the existing `data` `ArrayBuffer` losing the origin al // IMPORTANT: We overwrite the existing `data` `ArrayBuffer` losing the origin al
// image data. Ideally, we’d preserve the original image data for users who wa nt to // image data. Ideally, we’d preserve the original image data for users who wa nt to
// retain it but due to reports of data loss, we don’t want to overburden Inde xedDB // retain it but due to reports of data loss, we don’t want to overburden Inde xedDB
// by potentially doubling stored image data. // by potentially doubling stored image data.
// See: https://github.com/signalapp/Signal-Desktop/issues/1589 // See: https://github.com/signalapp/Signal-Desktop/issues/1589
const newAttachment = Object.assign({}, attachment, { const newAttachment = {
...attachment,
data: newDataArrayBuffer, data: newDataArrayBuffer,
size: newDataArrayBuffer.byteLength, size: newDataArrayBuffer.byteLength,
}); };
// `digest` is no longer valid for auto-oriented image data, so we discard it: // `digest` is no longer valid for auto-oriented image data, so we discard it:
delete newAttachment.digest; delete newAttachment.digest;
return newAttachment; return newAttachment;
}; };
const UNICODE_LEFT_TO_RIGHT_OVERRIDE = '\u202D'; const UNICODE_LEFT_TO_RIGHT_OVERRIDE = '\u202D';
const UNICODE_RIGHT_TO_LEFT_OVERRIDE = '\u202E'; const UNICODE_RIGHT_TO_LEFT_OVERRIDE = '\u202E';
const UNICODE_REPLACEMENT_CHARACTER = '\uFFFD'; const UNICODE_REPLACEMENT_CHARACTER = '\uFFFD';
skipping to change at line 106 skipping to change at line 107
// https://github.com/leebyron/testcheck-js/issues/45 // https://github.com/leebyron/testcheck-js/issues/45
exports._replaceUnicodeOrderOverridesSync = attachment => { exports._replaceUnicodeOrderOverridesSync = attachment => {
if (!is.string(attachment.fileName)) { if (!is.string(attachment.fileName)) {
return attachment; return attachment;
} }
const normalizedFilename = attachment.fileName.replace( const normalizedFilename = attachment.fileName.replace(
INVALID_CHARACTERS_PATTERN, INVALID_CHARACTERS_PATTERN,
UNICODE_REPLACEMENT_CHARACTER UNICODE_REPLACEMENT_CHARACTER
); );
const newAttachment = Object.assign({}, attachment, { const newAttachment = { ...attachment, fileName: normalizedFilename };
fileName: normalizedFilename,
});
return newAttachment; return newAttachment;
}; };
exports.replaceUnicodeOrderOverrides = async attachment => exports.replaceUnicodeOrderOverrides = async attachment =>
exports._replaceUnicodeOrderOverridesSync(attachment); exports._replaceUnicodeOrderOverridesSync(attachment);
// \u202A-\u202E is LRE, RLE, PDF, LRO, RLO // \u202A-\u202E is LRE, RLE, PDF, LRO, RLO
// \u2066-\u2069 is LRI, RLI, FSI, PDI // \u2066-\u2069 is LRI, RLI, FSI, PDI
// \u200E is LRM // \u200E is LRM
skipping to change at line 148 skipping to change at line 147
exports.removeSchemaVersion = ({ attachment, logger }) => { exports.removeSchemaVersion = ({ attachment, logger }) => {
if (!exports.isValid(attachment)) { if (!exports.isValid(attachment)) {
logger.error( logger.error(
'Attachment.removeSchemaVersion: Invalid input attachment:', 'Attachment.removeSchemaVersion: Invalid input attachment:',
attachment attachment
); );
return attachment; return attachment;
} }
const attachmentWithoutSchemaVersion = Object.assign({}, attachment); const attachmentWithoutSchemaVersion = { ...attachment };
delete attachmentWithoutSchemaVersion.schemaVersion; delete attachmentWithoutSchemaVersion.schemaVersion;
return attachmentWithoutSchemaVersion; return attachmentWithoutSchemaVersion;
}; };
exports.migrateDataToFileSystem = migrateDataToFileSystem; exports.migrateDataToFileSystem = migrateDataToFileSystem;
// hasData :: Attachment -> Boolean // hasData :: Attachment -> Boolean
exports.hasData = attachment => exports.hasData = attachment =>
attachment.data instanceof ArrayBuffer || ArrayBuffer.isView(attachment.data); attachment.data instanceof ArrayBuffer || ArrayBuffer.isView(attachment.data);
skipping to change at line 182 skipping to change at line 181
const isAlreadyLoaded = exports.hasData(attachment); const isAlreadyLoaded = exports.hasData(attachment);
if (isAlreadyLoaded) { if (isAlreadyLoaded) {
return attachment; return attachment;
} }
if (!is.string(attachment.path)) { if (!is.string(attachment.path)) {
throw new TypeError("'attachment.path' is required"); throw new TypeError("'attachment.path' is required");
} }
const data = await readAttachmentData(attachment.path); const data = await readAttachmentData(attachment.path);
return Object.assign({}, attachment, { data, size: data.byteLength }); return { ...attachment, data, size: data.byteLength };
}; };
}; };
// deleteData :: (RelativePath -> IO Unit) // deleteData :: (RelativePath -> IO Unit)
// Attachment -> // Attachment ->
// IO Unit // IO Unit
exports.deleteData = deleteOnDisk => { exports.deleteData = deleteOnDisk => {
if (!is.function(deleteOnDisk)) { if (!is.function(deleteOnDisk)) {
throw new TypeError('deleteData: deleteOnDisk must be a function'); throw new TypeError('deleteData: deleteOnDisk must be a function');
} }
skipping to change at line 214 skipping to change at line 213
if (thumbnail && is.string(thumbnail.path)) { if (thumbnail && is.string(thumbnail.path)) {
await deleteOnDisk(thumbnail.path); await deleteOnDisk(thumbnail.path);
} }
if (screenshot && is.string(screenshot.path)) { if (screenshot && is.string(screenshot.path)) {
await deleteOnDisk(screenshot.path); await deleteOnDisk(screenshot.path);
} }
}; };
}; };
exports.isImage = AttachmentTS.isImage;
exports.isVideo = AttachmentTS.isVideo;
exports.isAudio = AttachmentTS.isAudio;
exports.isVoiceMessage = AttachmentTS.isVoiceMessage; exports.isVoiceMessage = AttachmentTS.isVoiceMessage;
exports.save = AttachmentTS.save; exports.save = AttachmentTS.save;
const THUMBNAIL_SIZE = 150; const THUMBNAIL_SIZE = 150;
const THUMBNAIL_CONTENT_TYPE = 'image/png'; const THUMBNAIL_CONTENT_TYPE = 'image/png';
exports.captureDimensionsAndScreenshot = async ( exports.captureDimensionsAndScreenshot = async (
attachment, attachment,
{ {
writeNewAttachmentData, writeNewAttachmentData,
 End of changes. 8 change blocks. 
11 lines changed or deleted 13 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)