2021-06-17 17:15:10 +00:00
|
|
|
// Copyright 2019-2021 Signal Messenger, LLC
|
2020-10-30 20:34:04 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2021-07-28 21:37:09 +00:00
|
|
|
import { isNumber, omit } from 'lodash';
|
2021-06-17 17:15:10 +00:00
|
|
|
import { v4 as getGuid } from 'uuid';
|
|
|
|
|
|
|
|
import dataInterface from '../sql/Client';
|
2021-08-26 14:10:58 +00:00
|
|
|
import * as durations from '../util/durations';
|
2021-06-17 17:15:10 +00:00
|
|
|
import { downloadAttachment } from '../util/downloadAttachment';
|
2021-09-24 00:49:05 +00:00
|
|
|
import * as Bytes from '../Bytes';
|
2021-06-17 17:15:10 +00:00
|
|
|
import {
|
|
|
|
AttachmentDownloadJobType,
|
|
|
|
AttachmentDownloadJobTypeType,
|
|
|
|
} from '../sql/Interface';
|
|
|
|
|
|
|
|
import { MessageModel } from '../models/messages';
|
|
|
|
import { AttachmentType } from '../types/Attachment';
|
2021-09-17 18:27:53 +00:00
|
|
|
import { LoggerType } from '../types/Logging';
|
|
|
|
import * as log from '../logging/log';
|
2019-01-30 20:15:07 +00:00
|
|
|
|
|
|
|
const {
|
|
|
|
getMessageById,
|
|
|
|
getNextAttachmentDownloadJobs,
|
|
|
|
removeAttachmentDownloadJob,
|
|
|
|
resetAttachmentDownloadPending,
|
|
|
|
saveAttachmentDownloadJob,
|
|
|
|
saveMessage,
|
|
|
|
setAttachmentDownloadJobPending,
|
2021-06-17 17:15:10 +00:00
|
|
|
} = dataInterface;
|
2019-01-30 20:15:07 +00:00
|
|
|
|
|
|
|
const MAX_ATTACHMENT_JOB_PARALLELISM = 3;
|
|
|
|
|
2021-08-26 14:10:58 +00:00
|
|
|
const TICK_INTERVAL = durations.MINUTE;
|
2019-01-30 20:15:07 +00:00
|
|
|
|
2021-06-17 17:15:10 +00:00
|
|
|
const RETRY_BACKOFF: Record<number, number> = {
|
2021-08-26 14:10:58 +00:00
|
|
|
1: 30 * durations.SECOND,
|
|
|
|
2: 30 * durations.MINUTE,
|
|
|
|
3: 6 * durations.HOUR,
|
2019-01-30 20:15:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
let enabled = false;
|
2021-06-17 17:15:10 +00:00
|
|
|
let timeout: NodeJS.Timeout | null;
|
|
|
|
let logger: LoggerType;
|
|
|
|
const _activeAttachmentDownloadJobs: Record<
|
|
|
|
string,
|
|
|
|
Promise<void> | undefined
|
|
|
|
> = {};
|
|
|
|
|
|
|
|
type StartOptionsType = {
|
|
|
|
logger: LoggerType;
|
|
|
|
};
|
2019-01-30 20:15:07 +00:00
|
|
|
|
2021-06-17 17:15:10 +00:00
|
|
|
export async function start(options: StartOptionsType): Promise<void> {
|
2021-07-28 21:37:09 +00:00
|
|
|
({ logger } = options);
|
2019-01-30 20:15:07 +00:00
|
|
|
if (!logger) {
|
|
|
|
throw new Error('attachment_downloads/start: logger must be provided!');
|
|
|
|
}
|
|
|
|
|
2020-06-09 22:33:37 +00:00
|
|
|
logger.info('attachment_downloads/start: enabling');
|
2019-01-30 20:15:07 +00:00
|
|
|
enabled = true;
|
|
|
|
await resetAttachmentDownloadPending();
|
|
|
|
|
|
|
|
_tick();
|
|
|
|
}
|
|
|
|
|
2021-06-17 17:15:10 +00:00
|
|
|
export async function stop(): Promise<void> {
|
2021-05-06 21:32:23 +00:00
|
|
|
// If `.start()` wasn't called - the `logger` is `undefined`
|
|
|
|
if (logger) {
|
|
|
|
logger.info('attachment_downloads/stop: disabling');
|
|
|
|
}
|
2019-01-30 20:15:07 +00:00
|
|
|
enabled = false;
|
|
|
|
if (timeout) {
|
|
|
|
clearTimeout(timeout);
|
|
|
|
timeout = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-17 17:15:10 +00:00
|
|
|
export async function addJob(
|
|
|
|
attachment: AttachmentType,
|
|
|
|
job: { messageId: string; type: AttachmentDownloadJobTypeType; index: number }
|
|
|
|
): Promise<AttachmentType> {
|
2019-01-30 20:15:07 +00:00
|
|
|
if (!attachment) {
|
|
|
|
throw new Error('attachments_download/addJob: attachment is required');
|
|
|
|
}
|
|
|
|
|
|
|
|
const { messageId, type, index } = job;
|
|
|
|
if (!messageId) {
|
|
|
|
throw new Error('attachments_download/addJob: job.messageId is required');
|
|
|
|
}
|
|
|
|
if (!type) {
|
|
|
|
throw new Error('attachments_download/addJob: job.type is required');
|
|
|
|
}
|
|
|
|
if (!isNumber(index)) {
|
|
|
|
throw new Error('attachments_download/addJob: index must be a number');
|
|
|
|
}
|
|
|
|
|
|
|
|
const id = getGuid();
|
|
|
|
const timestamp = Date.now();
|
2021-06-17 17:15:10 +00:00
|
|
|
const toSave: AttachmentDownloadJobType = {
|
2019-01-30 20:15:07 +00:00
|
|
|
...job,
|
|
|
|
id,
|
|
|
|
attachment,
|
|
|
|
timestamp,
|
|
|
|
pending: 0,
|
|
|
|
attempts: 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
await saveAttachmentDownloadJob(toSave);
|
|
|
|
|
|
|
|
_maybeStartJob();
|
|
|
|
|
|
|
|
return {
|
|
|
|
...attachment,
|
|
|
|
pending: true,
|
|
|
|
downloadJobId: id,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-06-17 17:15:10 +00:00
|
|
|
async function _tick(): Promise<void> {
|
2019-06-24 20:39:37 +00:00
|
|
|
if (timeout) {
|
|
|
|
clearTimeout(timeout);
|
|
|
|
timeout = null;
|
|
|
|
}
|
|
|
|
|
2019-01-30 20:15:07 +00:00
|
|
|
_maybeStartJob();
|
|
|
|
timeout = setTimeout(_tick, TICK_INTERVAL);
|
|
|
|
}
|
|
|
|
|
2021-06-17 17:15:10 +00:00
|
|
|
async function _maybeStartJob(): Promise<void> {
|
2019-01-30 20:15:07 +00:00
|
|
|
if (!enabled) {
|
2020-06-09 22:33:37 +00:00
|
|
|
logger.info('attachment_downloads/_maybeStartJob: not enabled, returning');
|
2019-01-30 20:15:07 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const jobCount = getActiveJobCount();
|
|
|
|
const limit = MAX_ATTACHMENT_JOB_PARALLELISM - jobCount;
|
|
|
|
if (limit <= 0) {
|
2021-06-01 17:13:10 +00:00
|
|
|
logger.info(
|
|
|
|
'attachment_downloads/_maybeStartJob: reached active job limit, waiting'
|
|
|
|
);
|
2019-01-30 20:15:07 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const nextJobs = await getNextAttachmentDownloadJobs(limit);
|
|
|
|
if (nextJobs.length <= 0) {
|
2021-06-01 17:13:10 +00:00
|
|
|
logger.info(
|
|
|
|
'attachment_downloads/_maybeStartJob: no attachment jobs to run'
|
|
|
|
);
|
2019-01-30 20:15:07 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// To prevent the race condition caused by two parallel database calls, eached kicked
|
|
|
|
// off because the jobCount wasn't at the max.
|
|
|
|
const secondJobCount = getActiveJobCount();
|
|
|
|
const needed = MAX_ATTACHMENT_JOB_PARALLELISM - secondJobCount;
|
|
|
|
if (needed <= 0) {
|
2021-06-01 17:13:10 +00:00
|
|
|
logger.info(
|
|
|
|
'attachment_downloads/_maybeStartJob: reached active job limit after ' +
|
|
|
|
'db query, waiting'
|
|
|
|
);
|
2019-01-30 20:15:07 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const jobs = nextJobs.slice(0, Math.min(needed, nextJobs.length));
|
2021-06-01 17:13:10 +00:00
|
|
|
|
|
|
|
logger.info(
|
|
|
|
`attachment_downloads/_maybeStartJob: starting ${jobs.length} jobs`
|
|
|
|
);
|
|
|
|
|
2019-01-30 20:15:07 +00:00
|
|
|
for (let i = 0, max = jobs.length; i < max; i += 1) {
|
|
|
|
const job = jobs[i];
|
2019-09-17 21:09:01 +00:00
|
|
|
const existing = _activeAttachmentDownloadJobs[job.id];
|
|
|
|
if (existing) {
|
|
|
|
logger.warn(`_maybeStartJob: Job ${job.id} is already running`);
|
|
|
|
} else {
|
|
|
|
_activeAttachmentDownloadJobs[job.id] = _runJob(job);
|
|
|
|
}
|
2019-01-30 20:15:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-17 17:15:10 +00:00
|
|
|
async function _runJob(job?: AttachmentDownloadJobType): Promise<void> {
|
|
|
|
if (!job) {
|
2021-09-17 18:27:53 +00:00
|
|
|
log.warn('_runJob: Job was missing!');
|
2021-06-17 17:15:10 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const { id, messageId, attachment, type, index, attempts } = job;
|
2019-01-30 20:15:07 +00:00
|
|
|
let message;
|
|
|
|
|
|
|
|
try {
|
|
|
|
if (!job || !attachment || !messageId) {
|
|
|
|
throw new Error(
|
|
|
|
`_runJob: Key information required for job was missing. Job id: ${id}`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-06-09 22:33:37 +00:00
|
|
|
logger.info(`attachment_downloads/_runJob for job id ${id}`);
|
|
|
|
|
2019-09-26 19:56:31 +00:00
|
|
|
const found =
|
2021-06-17 17:15:10 +00:00
|
|
|
window.MessageController.getById(messageId) ||
|
2019-09-26 19:56:31 +00:00
|
|
|
(await getMessageById(messageId, {
|
2021-06-17 17:15:10 +00:00
|
|
|
Message: window.Whisper.Message,
|
2019-09-26 19:56:31 +00:00
|
|
|
}));
|
2019-03-26 01:10:30 +00:00
|
|
|
if (!found) {
|
2019-01-30 20:15:07 +00:00
|
|
|
logger.error('_runJob: Source message not found, deleting job');
|
2019-03-26 01:10:30 +00:00
|
|
|
await _finishJob(null, id);
|
2019-01-30 20:15:07 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-06-17 17:15:10 +00:00
|
|
|
message = window.MessageController.register(found.id, found);
|
2019-01-30 20:15:07 +00:00
|
|
|
|
|
|
|
const pending = true;
|
|
|
|
await setAttachmentDownloadJobPending(id, pending);
|
|
|
|
|
2020-07-07 00:39:55 +00:00
|
|
|
const downloaded = await downloadAttachment(attachment);
|
|
|
|
|
|
|
|
if (!downloaded) {
|
|
|
|
logger.warn(
|
|
|
|
`_runJob: Got 404 from server for CDN ${
|
|
|
|
attachment.cdnNumber
|
2020-11-18 15:15:42 +00:00
|
|
|
}, marking attachment ${
|
|
|
|
attachment.cdnId || attachment.cdnKey
|
|
|
|
} from message ${message.idForLogging()} as permanent error`
|
2020-07-07 00:39:55 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
await _finishJob(message, id);
|
|
|
|
await _addAttachmentToMessage(
|
|
|
|
message,
|
|
|
|
_markAttachmentAsError(attachment),
|
|
|
|
{ type, index }
|
|
|
|
);
|
|
|
|
return;
|
2019-01-30 20:15:07 +00:00
|
|
|
}
|
|
|
|
|
2021-06-17 17:15:10 +00:00
|
|
|
const upgradedAttachment = await window.Signal.Migrations.processNewAttachment(
|
2019-01-30 20:15:07 +00:00
|
|
|
downloaded
|
|
|
|
);
|
|
|
|
|
|
|
|
await _addAttachmentToMessage(message, upgradedAttachment, { type, index });
|
|
|
|
|
|
|
|
await _finishJob(message, id);
|
|
|
|
} catch (error) {
|
2021-06-17 17:15:10 +00:00
|
|
|
const logId = message ? message.idForLogging() : id || '<no id>';
|
2019-01-30 20:15:07 +00:00
|
|
|
const currentAttempt = (attempts || 0) + 1;
|
|
|
|
|
|
|
|
if (currentAttempt >= 3) {
|
|
|
|
logger.error(
|
2021-09-23 21:07:51 +00:00
|
|
|
`_runJob: ${currentAttempt} failed attempts, marking attachment ${id} from message ${logId} as permanent error:`,
|
2019-01-30 20:15:07 +00:00
|
|
|
error && error.stack ? error.stack : error
|
|
|
|
);
|
|
|
|
|
|
|
|
await _finishJob(message, id);
|
|
|
|
await _addAttachmentToMessage(
|
|
|
|
message,
|
|
|
|
_markAttachmentAsError(attachment),
|
|
|
|
{ type, index }
|
|
|
|
);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
logger.error(
|
2021-06-17 17:15:10 +00:00
|
|
|
`_runJob: Failed to download attachment type ${type} for message ${logId}, attempt ${currentAttempt}:`,
|
2019-01-30 20:15:07 +00:00
|
|
|
error && error.stack ? error.stack : error
|
|
|
|
);
|
|
|
|
|
|
|
|
const failedJob = {
|
|
|
|
...job,
|
|
|
|
pending: 0,
|
|
|
|
attempts: currentAttempt,
|
2021-06-17 17:15:10 +00:00
|
|
|
timestamp:
|
|
|
|
Date.now() + (RETRY_BACKOFF[currentAttempt] || RETRY_BACKOFF[3]),
|
2019-01-30 20:15:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
await saveAttachmentDownloadJob(failedJob);
|
|
|
|
delete _activeAttachmentDownloadJobs[id];
|
|
|
|
_maybeStartJob();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-17 17:15:10 +00:00
|
|
|
async function _finishJob(
|
|
|
|
message: MessageModel | null | undefined,
|
|
|
|
id: string
|
|
|
|
): Promise<void> {
|
2019-01-30 20:15:07 +00:00
|
|
|
if (message) {
|
2020-06-09 22:33:37 +00:00
|
|
|
logger.info(`attachment_downloads/_finishJob for job id: ${id}`);
|
2021-07-19 20:45:18 +00:00
|
|
|
await saveMessage(message.attributes);
|
2019-01-30 20:15:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
await removeAttachmentDownloadJob(id);
|
|
|
|
delete _activeAttachmentDownloadJobs[id];
|
|
|
|
_maybeStartJob();
|
|
|
|
}
|
|
|
|
|
2021-06-17 17:15:10 +00:00
|
|
|
function getActiveJobCount(): number {
|
2019-01-30 20:15:07 +00:00
|
|
|
return Object.keys(_activeAttachmentDownloadJobs).length;
|
|
|
|
}
|
|
|
|
|
2021-06-17 17:15:10 +00:00
|
|
|
function _markAttachmentAsError(attachment: AttachmentType): AttachmentType {
|
2019-01-30 20:15:07 +00:00
|
|
|
return {
|
|
|
|
...omit(attachment, ['key', 'digest', 'id']),
|
|
|
|
error: true,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-06-17 17:15:10 +00:00
|
|
|
async function _addAttachmentToMessage(
|
|
|
|
message: MessageModel | null | undefined,
|
|
|
|
attachment: AttachmentType,
|
|
|
|
{ type, index }: { type: AttachmentDownloadJobTypeType; index: number }
|
|
|
|
): Promise<void> {
|
2019-01-30 20:15:07 +00:00
|
|
|
if (!message) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-02-22 01:16:37 +00:00
|
|
|
const logPrefix = `${message.idForLogging()} (type: ${type}, index: ${index})`;
|
|
|
|
|
2019-03-13 20:38:28 +00:00
|
|
|
if (type === 'long-message') {
|
|
|
|
try {
|
2021-06-17 17:15:10 +00:00
|
|
|
const { data } = await window.Signal.Migrations.loadAttachmentData(
|
|
|
|
attachment
|
|
|
|
);
|
2019-03-13 20:38:28 +00:00
|
|
|
message.set({
|
2021-09-24 00:49:05 +00:00
|
|
|
body: attachment.error ? message.get('body') : Bytes.toString(data),
|
2019-03-13 20:38:28 +00:00
|
|
|
bodyPending: false,
|
|
|
|
});
|
|
|
|
} finally {
|
2021-06-17 17:15:10 +00:00
|
|
|
if (attachment.path) {
|
|
|
|
window.Signal.Migrations.deleteAttachmentData(attachment.path);
|
|
|
|
}
|
2019-03-13 20:38:28 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-01-30 20:15:07 +00:00
|
|
|
if (type === 'attachment') {
|
|
|
|
const attachments = message.get('attachments');
|
|
|
|
if (!attachments || attachments.length <= index) {
|
|
|
|
throw new Error(
|
|
|
|
`_addAttachmentToMessage: attachments didn't exist or ${index} was too large`
|
|
|
|
);
|
|
|
|
}
|
2021-06-17 17:15:10 +00:00
|
|
|
_checkOldAttachment(attachments, index.toString(), logPrefix);
|
2019-09-04 00:07:47 +00:00
|
|
|
|
|
|
|
const newAttachments = [...attachments];
|
|
|
|
newAttachments[index] = attachment;
|
|
|
|
|
|
|
|
message.set({ attachments: newAttachments });
|
|
|
|
|
2019-01-30 20:15:07 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type === 'preview') {
|
|
|
|
const preview = message.get('preview');
|
|
|
|
if (!preview || preview.length <= index) {
|
|
|
|
throw new Error(
|
|
|
|
`_addAttachmentToMessage: preview didn't exist or ${index} was too large`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
const item = preview[index];
|
|
|
|
if (!item) {
|
|
|
|
throw new Error(`_addAttachmentToMessage: preview ${index} was falsey`);
|
|
|
|
}
|
2019-09-04 00:07:47 +00:00
|
|
|
|
2021-06-17 17:15:10 +00:00
|
|
|
_checkOldAttachment(item, 'image', logPrefix);
|
2019-09-04 00:07:47 +00:00
|
|
|
|
|
|
|
const newPreview = [...preview];
|
|
|
|
newPreview[index] = {
|
|
|
|
...preview[index],
|
|
|
|
image: attachment,
|
|
|
|
};
|
|
|
|
|
|
|
|
message.set({ preview: newPreview });
|
|
|
|
|
2019-01-30 20:15:07 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type === 'contact') {
|
|
|
|
const contact = message.get('contact');
|
|
|
|
if (!contact || contact.length <= index) {
|
|
|
|
throw new Error(
|
|
|
|
`_addAttachmentToMessage: contact didn't exist or ${index} was too large`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
const item = contact[index];
|
|
|
|
if (item && item.avatar && item.avatar.avatar) {
|
2021-06-17 17:15:10 +00:00
|
|
|
_checkOldAttachment(item.avatar, 'avatar', logPrefix);
|
2019-09-04 00:07:47 +00:00
|
|
|
|
|
|
|
const newContact = [...contact];
|
|
|
|
newContact[index] = {
|
2021-06-17 17:15:10 +00:00
|
|
|
...item,
|
2019-09-04 00:07:47 +00:00
|
|
|
avatar: {
|
2021-06-17 17:15:10 +00:00
|
|
|
...item.avatar,
|
2019-09-04 00:07:47 +00:00
|
|
|
avatar: attachment,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
message.set({ contact: newContact });
|
2019-01-30 20:15:07 +00:00
|
|
|
} else {
|
|
|
|
logger.warn(
|
|
|
|
`_addAttachmentToMessage: Couldn't update contact with avatar attachment for message ${message.idForLogging()}`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type === 'quote') {
|
|
|
|
const quote = message.get('quote');
|
|
|
|
if (!quote) {
|
|
|
|
throw new Error("_addAttachmentToMessage: quote didn't exist");
|
|
|
|
}
|
|
|
|
const { attachments } = quote;
|
|
|
|
if (!attachments || attachments.length <= index) {
|
|
|
|
throw new Error(
|
|
|
|
`_addAttachmentToMessage: quote attachments didn't exist or ${index} was too large`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
const item = attachments[index];
|
|
|
|
if (!item) {
|
|
|
|
throw new Error(
|
2019-09-04 00:07:47 +00:00
|
|
|
`_addAttachmentToMessage: quote attachment ${index} was falsey`
|
2019-01-30 20:15:07 +00:00
|
|
|
);
|
|
|
|
}
|
2019-09-04 00:07:47 +00:00
|
|
|
|
2021-06-17 17:15:10 +00:00
|
|
|
_checkOldAttachment(item, 'thumbnail', logPrefix);
|
2019-09-04 00:07:47 +00:00
|
|
|
|
|
|
|
const newAttachments = [...attachments];
|
|
|
|
newAttachments[index] = {
|
|
|
|
...attachments[index],
|
|
|
|
thumbnail: attachment,
|
|
|
|
};
|
|
|
|
|
|
|
|
const newQuote = {
|
|
|
|
...quote,
|
|
|
|
attachments: newAttachments,
|
|
|
|
};
|
|
|
|
|
|
|
|
message.set({ quote: newQuote });
|
|
|
|
|
2019-01-30 20:15:07 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-05-16 22:32:11 +00:00
|
|
|
if (type === 'sticker') {
|
|
|
|
const sticker = message.get('sticker');
|
|
|
|
if (!sticker) {
|
|
|
|
throw new Error("_addAttachmentToMessage: sticker didn't exist");
|
|
|
|
}
|
|
|
|
|
2019-08-22 22:04:14 +00:00
|
|
|
message.set({
|
|
|
|
sticker: {
|
|
|
|
...sticker,
|
|
|
|
data: attachment,
|
|
|
|
},
|
|
|
|
});
|
2019-01-30 20:15:07 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new Error(
|
|
|
|
`_addAttachmentToMessage: Unknown job type ${type} for message ${message.idForLogging()}`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-06-17 17:15:10 +00:00
|
|
|
function _checkOldAttachment(
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
|
|
object: any,
|
|
|
|
key: string,
|
|
|
|
logPrefix: string
|
|
|
|
): void {
|
2019-01-30 20:15:07 +00:00
|
|
|
const oldAttachment = object[key];
|
|
|
|
if (oldAttachment && oldAttachment.path) {
|
2019-09-04 00:07:47 +00:00
|
|
|
logger.error(
|
|
|
|
`_checkOldAttachment: ${logPrefix} - old attachment already had path, not replacing`
|
|
|
|
);
|
|
|
|
throw new Error(
|
|
|
|
'_checkOldAttachment: old attachment already had path, not replacing'
|
2019-01-30 20:15:07 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|