Skip to content

Commit

Permalink
Merge pull request oxen-io#3094 from Aerilym/change_max_avatar_size
Browse files Browse the repository at this point in the history
Change max avatar size to match other platforms
  • Loading branch information
Bilb authored May 3, 2024
2 parents 6303288 + c0bb39d commit 009bc18
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
9 changes: 9 additions & 0 deletions ts/session/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ export const DURATION = {
WEEKS: days * 7,
};

export const FILESIZE = {
/** 1KB */
KB: 1024,
/** 1MB */
MB: 1024 * 1024,
/** 1GB */
GB: 1024 * 1024 * 1024,
};

export const TTL_DEFAULT = {
/** 20 seconds */
TYPING_MESSAGE: 20 * DURATION.SECONDS,
Expand Down
9 changes: 5 additions & 4 deletions ts/util/attachmentsUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import imageType from 'image-type';

import { arrayBufferToBlob } from 'blob-util';
import loadImage from 'blueimp-load-image';
import fileSize from 'filesize';
import { StagedAttachmentType } from '../components/conversation/composition/CompositionBox';
import { SignalService } from '../protobuf';
import { getDecryptedMediaUrl } from '../session/crypto/DecryptedAttachmentsManager';
Expand All @@ -12,7 +13,7 @@ import { IMAGE_GIF, IMAGE_JPEG, IMAGE_PNG, IMAGE_TIFF, IMAGE_UNKNOWN } from '../
import { getAbsoluteAttachmentPath, processNewAttachment } from '../types/MessageAttachment';
import { THUMBNAIL_SIDE } from '../types/attachments/VisualAttachment';

import { MAX_ATTACHMENT_FILESIZE_BYTES } from '../session/constants';
import { FILESIZE, MAX_ATTACHMENT_FILESIZE_BYTES } from '../session/constants';
import { perfEnd, perfStart } from '../session/utils/Performance';

/**
Expand Down Expand Up @@ -53,7 +54,7 @@ export async function autoScaleForAvatar<T extends { contentType: string; blob:
) {
const maxMeasurements = {
maxSide: AVATAR_MAX_SIDE,
maxSize: 1000 * 1024,
maxSize: 5 * FILESIZE.MB,
};

// we can only upload jpeg, gif, or png as avatar/opengroup
Expand All @@ -79,7 +80,7 @@ export async function autoScaleForAvatar<T extends { contentType: string; blob:
export async function autoScaleForIncomingAvatar(incomingAvatar: ArrayBuffer) {
const maxMeasurements = {
maxSide: AVATAR_MAX_SIDE,
maxSize: 1000 * 1024,
maxSize: 5 * FILESIZE.MB,
};

// the avatar url send in a message does not contain anything related to the avatar MIME type, so
Expand Down Expand Up @@ -186,7 +187,7 @@ export async function autoScale<T extends { contentType: string; blob: Blob }>(
}

if (blob.type === IMAGE_GIF && blob.size > maxSize) {
throw new Error(`GIF is too large, required size is ${maxSize}`);
throw new Error(`GIF is too large. Max size: ${fileSize(maxSize, { base: 10, round: 0 })}`);
}

perfStart(`loadimage-*${blob.size}`);
Expand Down

0 comments on commit 009bc18

Please sign in to comment.