Cleanup after rotating images
This commit is contained in:
parent
238812382b
commit
0aad09682d
4 changed files with 39 additions and 1 deletions
ts
|
@ -247,6 +247,7 @@ export function initializeMigrations({
|
||||||
getImageDimensions,
|
getImageDimensions,
|
||||||
makeImageThumbnail,
|
makeImageThumbnail,
|
||||||
makeVideoScreenshot,
|
makeVideoScreenshot,
|
||||||
|
deleteOnDisk,
|
||||||
logger,
|
logger,
|
||||||
}),
|
}),
|
||||||
processNewSticker: (stickerData: Uint8Array) =>
|
processNewSticker: (stickerData: Uint8Array) =>
|
||||||
|
@ -282,6 +283,7 @@ export function initializeMigrations({
|
||||||
maxVersion,
|
maxVersion,
|
||||||
getAbsoluteStickerPath,
|
getAbsoluteStickerPath,
|
||||||
writeNewStickerData,
|
writeNewStickerData,
|
||||||
|
deleteOnDisk,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
writeMessageAttachments: MessageType.createAttachmentDataWriter({
|
writeMessageAttachments: MessageType.createAttachmentDataWriter({
|
||||||
|
|
|
@ -73,6 +73,7 @@ describe('Message', () => {
|
||||||
writeNewAttachmentData: async (_data: Uint8Array) =>
|
writeNewAttachmentData: async (_data: Uint8Array) =>
|
||||||
'fake-attachment-path',
|
'fake-attachment-path',
|
||||||
writeNewStickerData: async (_data: Uint8Array) => 'fake-sticker-path',
|
writeNewStickerData: async (_data: Uint8Array) => 'fake-sticker-path',
|
||||||
|
deleteOnDisk: async (_path: string) => undefined,
|
||||||
...props,
|
...props,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,6 +72,7 @@ export type ContextType = {
|
||||||
revokeObjectUrl: (objectUrl: string) => void;
|
revokeObjectUrl: (objectUrl: string) => void;
|
||||||
writeNewAttachmentData: (data: Uint8Array) => Promise<string>;
|
writeNewAttachmentData: (data: Uint8Array) => Promise<string>;
|
||||||
writeNewStickerData: (data: Uint8Array) => Promise<string>;
|
writeNewStickerData: (data: Uint8Array) => Promise<string>;
|
||||||
|
deleteOnDisk: (path: string) => Promise<void>;
|
||||||
};
|
};
|
||||||
|
|
||||||
type WriteExistingAttachmentDataType = (
|
type WriteExistingAttachmentDataType = (
|
||||||
|
@ -373,7 +374,26 @@ const toVersion0 = async (
|
||||||
) => initializeSchemaVersion({ message, logger: context.logger });
|
) => initializeSchemaVersion({ message, logger: context.logger });
|
||||||
const toVersion1 = _withSchemaVersion({
|
const toVersion1 = _withSchemaVersion({
|
||||||
schemaVersion: 1,
|
schemaVersion: 1,
|
||||||
upgrade: _mapAttachments(autoOrientJPEG),
|
upgrade: _mapAttachments(
|
||||||
|
async (
|
||||||
|
attachment: AttachmentType,
|
||||||
|
context,
|
||||||
|
options
|
||||||
|
): Promise<AttachmentType> => {
|
||||||
|
const { deleteOnDisk } = context;
|
||||||
|
const rotatedAttachment = await autoOrientJPEG(
|
||||||
|
attachment,
|
||||||
|
context,
|
||||||
|
options
|
||||||
|
);
|
||||||
|
|
||||||
|
if (attachment.path) {
|
||||||
|
await deleteOnDisk(attachment.path);
|
||||||
|
}
|
||||||
|
|
||||||
|
return rotatedAttachment;
|
||||||
|
}
|
||||||
|
),
|
||||||
});
|
});
|
||||||
const toVersion2 = _withSchemaVersion({
|
const toVersion2 = _withSchemaVersion({
|
||||||
schemaVersion: 2,
|
schemaVersion: 2,
|
||||||
|
@ -479,6 +499,7 @@ export const upgradeSchema = async (
|
||||||
makeImageThumbnail,
|
makeImageThumbnail,
|
||||||
makeVideoScreenshot,
|
makeVideoScreenshot,
|
||||||
writeNewStickerData,
|
writeNewStickerData,
|
||||||
|
deleteOnDisk,
|
||||||
logger,
|
logger,
|
||||||
maxVersion = CURRENT_SCHEMA_VERSION,
|
maxVersion = CURRENT_SCHEMA_VERSION,
|
||||||
}: ContextType
|
}: ContextType
|
||||||
|
@ -516,6 +537,9 @@ export const upgradeSchema = async (
|
||||||
if (!isFunction(writeNewStickerData)) {
|
if (!isFunction(writeNewStickerData)) {
|
||||||
throw new TypeError('context.writeNewStickerData is required');
|
throw new TypeError('context.writeNewStickerData is required');
|
||||||
}
|
}
|
||||||
|
if (!isFunction(deleteOnDisk)) {
|
||||||
|
throw new TypeError('context.deleteOnDisk is required');
|
||||||
|
}
|
||||||
|
|
||||||
let message = rawMessage;
|
let message = rawMessage;
|
||||||
for (let index = 0, max = VERSIONS.length; index < max; index += 1) {
|
for (let index = 0, max = VERSIONS.length; index < max; index += 1) {
|
||||||
|
@ -539,6 +563,7 @@ export const upgradeSchema = async (
|
||||||
getAbsoluteStickerPath,
|
getAbsoluteStickerPath,
|
||||||
getRegionCode,
|
getRegionCode,
|
||||||
writeNewStickerData,
|
writeNewStickerData,
|
||||||
|
deleteOnDisk,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -557,6 +582,7 @@ export const processNewAttachment = async (
|
||||||
getImageDimensions,
|
getImageDimensions,
|
||||||
makeImageThumbnail,
|
makeImageThumbnail,
|
||||||
makeVideoScreenshot,
|
makeVideoScreenshot,
|
||||||
|
deleteOnDisk,
|
||||||
logger,
|
logger,
|
||||||
}: Pick<
|
}: Pick<
|
||||||
ContextType,
|
ContextType,
|
||||||
|
@ -568,6 +594,7 @@ export const processNewAttachment = async (
|
||||||
| 'makeImageThumbnail'
|
| 'makeImageThumbnail'
|
||||||
| 'makeVideoScreenshot'
|
| 'makeVideoScreenshot'
|
||||||
| 'logger'
|
| 'logger'
|
||||||
|
| 'deleteOnDisk'
|
||||||
>
|
>
|
||||||
): Promise<AttachmentType> => {
|
): Promise<AttachmentType> => {
|
||||||
if (!isFunction(writeNewAttachmentData)) {
|
if (!isFunction(writeNewAttachmentData)) {
|
||||||
|
@ -612,6 +639,10 @@ export const processNewAttachment = async (
|
||||||
writeNewAttachmentData,
|
writeNewAttachmentData,
|
||||||
logger,
|
logger,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (attachment.path) {
|
||||||
|
await deleteOnDisk(attachment.path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const finalAttachment = await captureDimensionsAndScreenshot(
|
const finalAttachment = await captureDimensionsAndScreenshot(
|
||||||
|
|
|
@ -78,10 +78,14 @@ export async function autoOrientJPEG(
|
||||||
// retain it but due to reports of data loss, we don’t want to overburden IndexedDB
|
// retain it but due to reports of data loss, we don’t want to overburden IndexedDB
|
||||||
// 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
|
||||||
|
// We also clear out the attachment path because we're changing
|
||||||
|
// the attachment data so it no longer matches the old path.
|
||||||
|
// Path and data should always be in agreement.
|
||||||
const xcodedAttachment = {
|
const xcodedAttachment = {
|
||||||
...attachment,
|
...attachment,
|
||||||
data: new Uint8Array(xcodedDataArrayBuffer),
|
data: new Uint8Array(xcodedDataArrayBuffer),
|
||||||
size: xcodedDataArrayBuffer.byteLength,
|
size: xcodedDataArrayBuffer.byteLength,
|
||||||
|
path: undefined,
|
||||||
};
|
};
|
||||||
|
|
||||||
return xcodedAttachment;
|
return xcodedAttachment;
|
||||||
|
|
Loading…
Add table
Reference in a new issue