Skip to content

Commit 7fc7c58

Browse files
committed
chore: skip avatar/attach dl when env var is set
1 parent c37ff42 commit 7fc7c58

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-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/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)