Skip to content

Commit e85c73e

Browse files
committed
chore: skip avatar/attach dl when env var is set
1 parent 132737b commit e85c73e

File tree

4 files changed

+22
-0
lines changed

4 files changed

+22
-0
lines changed

ts/session/utils/AttachmentsDownload.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { getAttachmentMetadata } from '../../types/message/initializeAttachmentM
1010
import { AttachmentDownloadMessageDetails } from '../../types/sqlSharedTypes';
1111
import { was404Error } from '../apis/snode_api/onions';
1212
import * as Constants from '../constants';
13+
import { skipAttachmentsDownloads } from '../../shared/env_vars';
1314

1415
// 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
1516
const MAX_ATTACHMENT_JOB_PARALLELISM = 3;
@@ -140,6 +141,10 @@ async function _maybeStartJob() {
140141
async function _runJob(job: any) {
141142
const { id, messageId, attachment, type, index, attempts, isOpenGroupV2, openGroupV2Details } =
142143
job || {};
144+
if (skipAttachmentsDownloads()) {
145+
await _finishJob(null, id);
146+
return;
147+
}
143148
let found: MessageModel | undefined | null;
144149
try {
145150
if (!job || !attachment || !messageId) {

ts/session/utils/job_runners/jobs/AvatarDownloadJob.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { processAvatarData } from '../../../../util/avatar/processAvatarData';
1616
import { downloadAttachmentFs } from '../../../../receiver/attachments';
1717
import { extractDetailsFromUrlFragment } from '../../../url';
1818
import { MultiEncryptWrapperActions } from '../../../../webworker/workers/browser/libsession_worker_interface';
19+
import { skipAttachmentsDownloads } from '../../../../shared/env_vars';
1920

2021
const defaultMsBetweenRetries = 10000;
2122
const defaultMaxAttempts = 3;
@@ -89,6 +90,10 @@ class AvatarDownloadJob extends PersistedJob<AvatarDownloadPersistedData> {
8990
}
9091

9192
public async run(): Promise<RunJobResult> {
93+
if (skipAttachmentsDownloads()) {
94+
return RunJobResult.Success;
95+
}
96+
9297
const convoId = this.persistedData.conversationId;
9398

9499
window.log.debug(

ts/session/utils/job_runners/jobs/AvatarMigrateJob.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { processAvatarData } from '../../../../util/avatar/processAvatarData';
1313
import { DecryptedAttachmentsManager } from '../../../crypto/DecryptedAttachmentsManager';
1414
import { IMAGE_JPEG } from '../../../../types/MIME';
1515
import { NetworkTime } from '../../../../util/NetworkTime';
16+
import { skipAttachmentsDownloads } from '../../../../shared/env_vars';
1617

1718
const defaultMsBetweenRetries = 10000;
1819
const defaultMaxAttempts = 3;
@@ -85,6 +86,9 @@ class AvatarMigrateJob extends PersistedJob<AvatarMigratePersistedData> {
8586
}
8687

8788
public async run(): Promise<RunJobResult> {
89+
if (skipAttachmentsDownloads()) {
90+
return RunJobResult.Success;
91+
}
8892
const convoId = this.persistedData.conversationId;
8993

9094
window.log.debug(`running job ${this.persistedData.jobType} with conversationId:"${convoId}"`);

ts/shared/env_vars.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,11 @@ export function isUnitTest() {
3232
export function isDebugMode() {
3333
return !!process.env.SESSION_DEV;
3434
}
35+
36+
/**
37+
* Returns true when any kind of avatars/attachments should not be downloaded.
38+
* This is for our users with an issue with sharp that makes the app crashes.
39+
*/
40+
export function skipAttachmentsDownloads() {
41+
return !!process.env.SESSION_SKIP_ATTACHMENTS_DOWNLOADS;
42+
}

0 commit comments

Comments
 (0)