diff --git a/ts/session/utils/AttachmentsDownload.ts b/ts/session/utils/AttachmentsDownload.ts index 801768c13..f53afebd8 100644 --- a/ts/session/utils/AttachmentsDownload.ts +++ b/ts/session/utils/AttachmentsDownload.ts @@ -10,6 +10,7 @@ import { getAttachmentMetadata } from '../../types/message/initializeAttachmentM import { AttachmentDownloadMessageDetails } from '../../types/sqlSharedTypes'; import { was404Error } from '../apis/snode_api/onions'; import * as Constants from '../constants'; +import { skipAttachmentsDownloads } from '../../shared/env_vars'; // this may cause issues if we increment that value to > 1, but only having one job will block the whole queue while one attachment is downloading const MAX_ATTACHMENT_JOB_PARALLELISM = 3; @@ -140,6 +141,10 @@ async function _maybeStartJob() { async function _runJob(job: any) { const { id, messageId, attachment, type, index, attempts, isOpenGroupV2, openGroupV2Details } = job || {}; + if (skipAttachmentsDownloads()) { + await _finishJob(null, id); + return; + } let found: MessageModel | undefined | null; try { if (!job || !attachment || !messageId) { diff --git a/ts/session/utils/job_runners/jobs/AvatarDownloadJob.ts b/ts/session/utils/job_runners/jobs/AvatarDownloadJob.ts index 868b972c6..9e62f9ffa 100644 --- a/ts/session/utils/job_runners/jobs/AvatarDownloadJob.ts +++ b/ts/session/utils/job_runners/jobs/AvatarDownloadJob.ts @@ -16,6 +16,7 @@ import { processAvatarData } from '../../../../util/avatar/processAvatarData'; import { downloadAttachmentFs } from '../../../../receiver/attachments'; import { extractDetailsFromUrlFragment } from '../../../url'; import { MultiEncryptWrapperActions } from '../../../../webworker/workers/browser/libsession_worker_interface'; +import { skipAttachmentsDownloads } from '../../../../shared/env_vars'; const defaultMsBetweenRetries = 10000; const defaultMaxAttempts = 3; @@ -89,6 +90,10 @@ class AvatarDownloadJob extends PersistedJob { } public async run(): Promise { + if (skipAttachmentsDownloads()) { + return RunJobResult.Success; + } + const convoId = this.persistedData.conversationId; window.log.debug( diff --git a/ts/session/utils/job_runners/jobs/AvatarMigrateJob.ts b/ts/session/utils/job_runners/jobs/AvatarMigrateJob.ts index ec476cade..cbc478d8b 100644 --- a/ts/session/utils/job_runners/jobs/AvatarMigrateJob.ts +++ b/ts/session/utils/job_runners/jobs/AvatarMigrateJob.ts @@ -13,6 +13,7 @@ import { processAvatarData } from '../../../../util/avatar/processAvatarData'; import { DecryptedAttachmentsManager } from '../../../crypto/DecryptedAttachmentsManager'; import { IMAGE_JPEG } from '../../../../types/MIME'; import { NetworkTime } from '../../../../util/NetworkTime'; +import { skipAttachmentsDownloads } from '../../../../shared/env_vars'; const defaultMsBetweenRetries = 10000; const defaultMaxAttempts = 3; @@ -85,6 +86,9 @@ class AvatarMigrateJob extends PersistedJob { } public async run(): Promise { + if (skipAttachmentsDownloads()) { + return RunJobResult.Success; + } const convoId = this.persistedData.conversationId; window.log.debug(`running job ${this.persistedData.jobType} with conversationId:"${convoId}"`); diff --git a/ts/shared/env_vars.ts b/ts/shared/env_vars.ts index a829ad227..11c597c12 100644 --- a/ts/shared/env_vars.ts +++ b/ts/shared/env_vars.ts @@ -32,3 +32,11 @@ export function isUnitTest() { export function isDebugMode() { return !!process.env.SESSION_DEV; } + +/** + * Returns true when any kind of avatars/attachments should not be downloaded. + * This is for our users with an issue with sharp that makes the app crashes. + */ +export function skipAttachmentsDownloads() { + return !!process.env.SESSION_SKIP_ATTACHMENTS_DOWNLOADS; +}