Cleanup attachment download flow
This commit is contained in:
parent
9ad0e5064d
commit
ff5ecd8bf3
4 changed files with 16 additions and 25 deletions
|
@ -31,6 +31,7 @@ import {
|
||||||
getMaximumIncomingAttachmentSizeInKb,
|
getMaximumIncomingAttachmentSizeInKb,
|
||||||
getMaximumIncomingTextAttachmentSizeInKb,
|
getMaximumIncomingTextAttachmentSizeInKb,
|
||||||
} from '../types/AttachmentSize';
|
} from '../types/AttachmentSize';
|
||||||
|
import { redactCdnKey } from '../util/privacy';
|
||||||
|
|
||||||
const {
|
const {
|
||||||
getMessageById,
|
getMessageById,
|
||||||
|
@ -221,7 +222,6 @@ async function _maybeStartJob(): Promise<void> {
|
||||||
const logId = `attachment_downloads/_maybeStartJob/postProcess/${job.id}`;
|
const logId = `attachment_downloads/_maybeStartJob/postProcess/${job.id}`;
|
||||||
try {
|
try {
|
||||||
await promise;
|
await promise;
|
||||||
log.info(`${logId}: job has finished running`);
|
|
||||||
if (_activeAttachmentDownloadJobs[job.id]) {
|
if (_activeAttachmentDownloadJobs[job.id]) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`${logId}: Active attachments jobs list still has this job!`
|
`${logId}: Active attachments jobs list still has this job!`
|
||||||
|
@ -269,12 +269,18 @@ async function _runJob(job?: AttachmentDownloadJobType): Promise<void> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info(`attachment_downloads/_runJob(${id}): starting`);
|
|
||||||
|
|
||||||
const pending = true;
|
const pending = true;
|
||||||
await setAttachmentDownloadJobPending(id, pending);
|
await setAttachmentDownloadJobPending(id, pending);
|
||||||
|
|
||||||
message = await _getMessageById(id, messageId);
|
message = await _getMessageById(id, messageId);
|
||||||
|
logger.info(
|
||||||
|
'attachment_downloads/_runJob' +
|
||||||
|
`(jobId: ${id}, type: ${type}, index: ${index},` +
|
||||||
|
` cdnKey: ${
|
||||||
|
attachment.cdnKey ? redactCdnKey(attachment.cdnKey) : null
|
||||||
|
},` +
|
||||||
|
` messageTimestamp: ${message?.attributes.timestamp}): starting`
|
||||||
|
);
|
||||||
|
|
||||||
if (!message) {
|
if (!message) {
|
||||||
return;
|
return;
|
||||||
|
@ -475,10 +481,6 @@ async function _finishJob(
|
||||||
await saveMessage(message.attributes, {
|
await saveMessage(message.attributes, {
|
||||||
ourAci: window.textsecure.storage.user.getCheckedAci(),
|
ourAci: window.textsecure.storage.user.getCheckedAci(),
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
logger.info(
|
|
||||||
`attachment_downloads/_finishJob for job id: ${id} without message`
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await removeAttachmentDownloadJob(id);
|
await removeAttachmentDownloadJob(id);
|
||||||
|
@ -525,8 +527,6 @@ async function _addAttachmentToMessage(
|
||||||
const logPrefix = `${message.idForLogging()} (type: ${type}, index: ${index})`;
|
const logPrefix = `${message.idForLogging()} (type: ${type}, index: ${index})`;
|
||||||
const attachmentSignature = getAttachmentSignature(attachment);
|
const attachmentSignature = getAttachmentSignature(attachment);
|
||||||
|
|
||||||
log.info(`${logPrefix}: _addAttachmentToMessage: starting`);
|
|
||||||
|
|
||||||
if (type === 'long-message') {
|
if (type === 'long-message') {
|
||||||
let handledAnywhere = false;
|
let handledAnywhere = false;
|
||||||
let attachmentData: Uint8Array | undefined;
|
let attachmentData: Uint8Array | undefined;
|
||||||
|
@ -612,7 +612,6 @@ async function _addAttachmentToMessage(
|
||||||
`${logPrefix}: Long message attachment found no matching place to apply`
|
`${logPrefix}: Long message attachment found no matching place to apply`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
log.info(`${logPrefix}: _addAttachmentToMessage finished`);
|
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ import {
|
||||||
import type { ProcessedAttachment } from './Types.d';
|
import type { ProcessedAttachment } from './Types.d';
|
||||||
import type { WebAPIType } from './WebAPI';
|
import type { WebAPIType } from './WebAPI';
|
||||||
import { createName, getRelativePath } from '../windows/attachments';
|
import { createName, getRelativePath } from '../windows/attachments';
|
||||||
|
import { redactCdnKey } from '../util/privacy';
|
||||||
|
|
||||||
export function getCdn(attachment: ProcessedAttachment): string {
|
export function getCdn(attachment: ProcessedAttachment): string {
|
||||||
const { cdnId, cdnKey } = attachment;
|
const { cdnId, cdnKey } = attachment;
|
||||||
|
@ -89,7 +90,7 @@ export async function downloadAttachmentV2(
|
||||||
): Promise<AttachmentType> {
|
): Promise<AttachmentType> {
|
||||||
const { cdnNumber, contentType, digest, key, size } = attachment;
|
const { cdnNumber, contentType, digest, key, size } = attachment;
|
||||||
const cdn = getCdn(attachment);
|
const cdn = getCdn(attachment);
|
||||||
const logId = `downloadAttachmentV2(${cdn}):`;
|
const logId = `downloadAttachmentV2(${redactCdnKey(cdn)}:`;
|
||||||
|
|
||||||
strictAssert(digest, `${logId}: missing digest`);
|
strictAssert(digest, `${logId}: missing digest`);
|
||||||
strictAssert(key, `${logId}: missing key`);
|
strictAssert(key, `${logId}: missing key`);
|
||||||
|
@ -100,11 +101,8 @@ export async function downloadAttachmentV2(
|
||||||
dropNull(cdnNumber),
|
dropNull(cdnNumber),
|
||||||
options
|
options
|
||||||
);
|
);
|
||||||
log.info(`${logId} got download stream`);
|
|
||||||
|
|
||||||
const cipherTextRelativePath = await downloadToDisk({ downloadStream, size });
|
const cipherTextRelativePath = await downloadToDisk({ downloadStream, size });
|
||||||
log.info(`${logId} downloaded encrypted file to disk`);
|
|
||||||
|
|
||||||
const cipherTextAbsolutePath =
|
const cipherTextAbsolutePath =
|
||||||
window.Signal.Migrations.getAbsoluteAttachmentPath(cipherTextRelativePath);
|
window.Signal.Migrations.getAbsoluteAttachmentPath(cipherTextRelativePath);
|
||||||
|
|
||||||
|
@ -115,7 +113,6 @@ export async function downloadAttachmentV2(
|
||||||
size,
|
size,
|
||||||
theirDigest: Bytes.fromBase64(digest),
|
theirDigest: Bytes.fromBase64(digest),
|
||||||
});
|
});
|
||||||
log.info(`${logId} successfully decrypted`);
|
|
||||||
|
|
||||||
safeUnlinkSync(cipherTextAbsolutePath);
|
safeUnlinkSync(cipherTextAbsolutePath);
|
||||||
|
|
||||||
|
|
|
@ -413,19 +413,15 @@ export async function captureDimensionsAndScreenshot(
|
||||||
if (!attachment.path) {
|
if (!attachment.path) {
|
||||||
return attachment;
|
return attachment;
|
||||||
}
|
}
|
||||||
logger.info('captureDimensionsAndScreenshot: starting');
|
|
||||||
|
|
||||||
const absolutePath = getAbsoluteAttachmentPath(attachment.path);
|
const absolutePath = getAbsoluteAttachmentPath(attachment.path);
|
||||||
|
|
||||||
if (GoogleChrome.isImageTypeSupported(contentType)) {
|
if (GoogleChrome.isImageTypeSupported(contentType)) {
|
||||||
try {
|
try {
|
||||||
logger.info('captureDimensionsAndScreenshot: getting image dimensions');
|
|
||||||
const { width, height } = await getImageDimensionsFromURL({
|
const { width, height } = await getImageDimensionsFromURL({
|
||||||
objectUrl: absolutePath,
|
objectUrl: absolutePath,
|
||||||
logger,
|
logger,
|
||||||
});
|
});
|
||||||
|
|
||||||
logger.info('captureDimensionsAndScreenshot: generating thumbnail');
|
|
||||||
const thumbnailBuffer = await blobToArrayBuffer(
|
const thumbnailBuffer = await blobToArrayBuffer(
|
||||||
await makeImageThumbnail({
|
await makeImageThumbnail({
|
||||||
size: THUMBNAIL_SIZE,
|
size: THUMBNAIL_SIZE,
|
||||||
|
@ -434,7 +430,7 @@ export async function captureDimensionsAndScreenshot(
|
||||||
logger,
|
logger,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
logger.info('captureDimensionsAndScreenshot: writing thumbnail');
|
|
||||||
const thumbnailPath = await writeNewAttachmentData(
|
const thumbnailPath = await writeNewAttachmentData(
|
||||||
new Uint8Array(thumbnailBuffer)
|
new Uint8Array(thumbnailBuffer)
|
||||||
);
|
);
|
||||||
|
@ -461,7 +457,6 @@ export async function captureDimensionsAndScreenshot(
|
||||||
|
|
||||||
let screenshotObjectUrl: string | undefined;
|
let screenshotObjectUrl: string | undefined;
|
||||||
try {
|
try {
|
||||||
logger.info('captureDimensionsAndScreenshot: making video screenshot');
|
|
||||||
const screenshotBuffer = await blobToArrayBuffer(
|
const screenshotBuffer = await blobToArrayBuffer(
|
||||||
await makeVideoScreenshot({
|
await makeVideoScreenshot({
|
||||||
objectUrl: absolutePath,
|
objectUrl: absolutePath,
|
||||||
|
@ -473,17 +468,14 @@ export async function captureDimensionsAndScreenshot(
|
||||||
screenshotBuffer,
|
screenshotBuffer,
|
||||||
THUMBNAIL_CONTENT_TYPE
|
THUMBNAIL_CONTENT_TYPE
|
||||||
);
|
);
|
||||||
logger.info('captureDimensionsAndScreenshot: getting image dimensions');
|
|
||||||
const { width, height } = await getImageDimensionsFromURL({
|
const { width, height } = await getImageDimensionsFromURL({
|
||||||
objectUrl: screenshotObjectUrl,
|
objectUrl: screenshotObjectUrl,
|
||||||
logger,
|
logger,
|
||||||
});
|
});
|
||||||
logger.info('captureDimensionsAndScreenshot: writing attachment data');
|
|
||||||
const screenshotPath = await writeNewAttachmentData(
|
const screenshotPath = await writeNewAttachmentData(
|
||||||
new Uint8Array(screenshotBuffer)
|
new Uint8Array(screenshotBuffer)
|
||||||
);
|
);
|
||||||
|
|
||||||
logger.info('captureDimensionsAndScreenshot: making thumbnail');
|
|
||||||
const thumbnailBuffer = await blobToArrayBuffer(
|
const thumbnailBuffer = await blobToArrayBuffer(
|
||||||
await makeImageThumbnail({
|
await makeImageThumbnail({
|
||||||
size: THUMBNAIL_SIZE,
|
size: THUMBNAIL_SIZE,
|
||||||
|
@ -493,7 +485,6 @@ export async function captureDimensionsAndScreenshot(
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
logger.info('captureDimensionsAndScreenshot: writing thumbnail');
|
|
||||||
const thumbnailPath = await writeNewAttachmentData(
|
const thumbnailPath = await writeNewAttachmentData(
|
||||||
new Uint8Array(thumbnailBuffer)
|
new Uint8Array(thumbnailBuffer)
|
||||||
);
|
);
|
||||||
|
|
|
@ -163,6 +163,10 @@ export const redactCallLinkRootKeys = (text: string): string => {
|
||||||
return text.replace(CALL_LINK_ROOT_KEY_PATTERN, `${REDACTION_PLACEHOLDER}$1`);
|
return text.replace(CALL_LINK_ROOT_KEY_PATTERN, `${REDACTION_PLACEHOLDER}$1`);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const redactCdnKey = (cdnKey: string): string => {
|
||||||
|
return `${REDACTION_PLACEHOLDER}${cdnKey.slice(-3)}`;
|
||||||
|
};
|
||||||
|
|
||||||
const createRedactSensitivePaths = (
|
const createRedactSensitivePaths = (
|
||||||
paths: ReadonlyArray<string>
|
paths: ReadonlyArray<string>
|
||||||
): RedactFunction => {
|
): RedactFunction => {
|
||||||
|
|
Loading…
Reference in a new issue