feat: increase max upload size to 10MB
This commit is contained in:
parent
8584edf302
commit
bb0112c6c5
|
@ -408,7 +408,7 @@ export class SessionConversation extends React.Component<Props, State> {
|
|||
blob: file,
|
||||
});
|
||||
|
||||
if (blob.blob.size >= MAX_ATTACHMENT_FILESIZE_BYTES) {
|
||||
if (blob.blob.size > MAX_ATTACHMENT_FILESIZE_BYTES) {
|
||||
ToastUtils.pushFileSizeErrorAsByte(MAX_ATTACHMENT_FILESIZE_BYTES);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -113,6 +113,8 @@ export async function shutdown() {
|
|||
|
||||
// No outstanding jobs, return immediately
|
||||
if (jobKeys.length === 0) {
|
||||
window?.log?.info('data.shutdown: No outstanding jobs');
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -246,6 +248,8 @@ function removeJob(id: number) {
|
|||
|
||||
if (_shutdownCallback) {
|
||||
const keys = Object.keys(jobs);
|
||||
window?.log?.info(`removeJob: _shutdownCallback and we still have ${keys.length} jobs to run`);
|
||||
|
||||
if (keys.length === 0) {
|
||||
_shutdownCallback();
|
||||
}
|
||||
|
|
|
@ -690,7 +690,7 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
|
|||
height: height || 0,
|
||||
path,
|
||||
fileName,
|
||||
fileSize: size ? filesize(size) : null,
|
||||
fileSize: size ? filesize(size, { base: 10 }) : null,
|
||||
isVoiceMessage: isVoiceMessageBool,
|
||||
pending: Boolean(pending),
|
||||
url: path ? getAbsoluteAttachmentPath(path) : '',
|
||||
|
|
|
@ -41,9 +41,12 @@ export const CONVERSATION = {
|
|||
MAX_VOICE_MESSAGE_DURATION: 300,
|
||||
MAX_UNREAD_COUNT: 9999,
|
||||
};
|
||||
// Max attachment size: 6 MB
|
||||
|
||||
export const MAX_ATTACHMENT_FILESIZE_BYTES = 6 * 1000 * 1000; // 6MB
|
||||
/**
|
||||
* The file server and onion request max upload size is 10MB precisely.
|
||||
* 10MB is still ok, but one byte more is not.
|
||||
*/
|
||||
export const MAX_ATTACHMENT_FILESIZE_BYTES = 10 * 1000 * 1000;
|
||||
|
||||
export const VALIDATION = {
|
||||
MAX_GROUP_NAME_LENGTH: 30,
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import { MAX_ATTACHMENT_FILESIZE_BYTES } from '../constants';
|
||||
|
||||
/**
|
||||
* This file is used to pad message buffer and attachments
|
||||
*/
|
||||
|
@ -73,10 +75,17 @@ export function addAttachmentPadding(data: ArrayBuffer): ArrayBuffer {
|
|||
const originalUInt = new Uint8Array(data);
|
||||
window?.log?.info('Adding attachment padding...');
|
||||
|
||||
const paddedSize = Math.max(
|
||||
let paddedSize = Math.max(
|
||||
541,
|
||||
Math.floor(Math.pow(1.05, Math.ceil(Math.log(originalUInt.length) / Math.log(1.05))))
|
||||
);
|
||||
|
||||
if (
|
||||
paddedSize > MAX_ATTACHMENT_FILESIZE_BYTES &&
|
||||
originalUInt.length <= MAX_ATTACHMENT_FILESIZE_BYTES
|
||||
) {
|
||||
paddedSize = MAX_ATTACHMENT_FILESIZE_BYTES;
|
||||
}
|
||||
const paddedData = new ArrayBuffer(paddedSize);
|
||||
const paddedUInt = new Uint8Array(paddedData);
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ import {
|
|||
getUnpaddedAttachment,
|
||||
removeMessagePadding,
|
||||
} from '../../../../session/crypto/BufferPadding';
|
||||
import { MAX_ATTACHMENT_FILESIZE_BYTES } from '../../../../session/constants';
|
||||
chai.use(chaiAsPromised as any);
|
||||
chai.should();
|
||||
|
||||
|
@ -30,6 +31,41 @@ describe('Padding', () => {
|
|||
);
|
||||
});
|
||||
|
||||
it('no padding if attachment has the max size', () => {
|
||||
//if the attachment is already of the max size, we do not pad it more
|
||||
const bufferIn = new Uint8Array(MAX_ATTACHMENT_FILESIZE_BYTES);
|
||||
const paddedBuffer = addAttachmentPadding(bufferIn);
|
||||
expect(paddedBuffer.byteLength).to.equal(MAX_ATTACHMENT_FILESIZE_BYTES);
|
||||
expect(new Uint8Array(paddedBuffer)).to.equalBytes(bufferIn);
|
||||
});
|
||||
|
||||
it('add padding is limited to max attachment size', () => {
|
||||
// there is only enough room to add one byte as padding.
|
||||
const bufferIn = new Uint8Array(MAX_ATTACHMENT_FILESIZE_BYTES - 1);
|
||||
const paddedBuffer = addAttachmentPadding(bufferIn);
|
||||
expect(paddedBuffer.byteLength).to.equal(MAX_ATTACHMENT_FILESIZE_BYTES);
|
||||
expect(new Uint8Array(paddedBuffer.slice(0, bufferIn.length))).to.equalBytes(bufferIn);
|
||||
// this makes sure that the padding is just the 0 bytes
|
||||
expect(paddedBuffer.slice(bufferIn.length).byteLength).to.eq(1);
|
||||
expect(new Uint8Array(paddedBuffer.slice(bufferIn.length))).to.equalBytes(
|
||||
new Uint8Array([0])
|
||||
);
|
||||
});
|
||||
|
||||
it('add padding if the attachment is already too big', () => {
|
||||
// we just want to make sure we do not overide attachment data. The file upload will fail, but at least make sure to keep the user data.
|
||||
const bufferIn = new Uint8Array(MAX_ATTACHMENT_FILESIZE_BYTES + 1);
|
||||
const paddedBuffer = addAttachmentPadding(bufferIn);
|
||||
const expectedPaddedSize = Math.floor(
|
||||
Math.pow(1.05, Math.ceil(Math.log(bufferIn.length) / Math.log(1.05)))
|
||||
);
|
||||
expect(new Uint8Array(paddedBuffer.slice(0, bufferIn.length))).to.equalBytes(bufferIn);
|
||||
// this makes sure that the padding is just the 0 bytes
|
||||
expect(new Uint8Array(paddedBuffer.slice(bufferIn.length))).to.equalBytes(
|
||||
new Uint8Array(expectedPaddedSize - bufferIn.length)
|
||||
);
|
||||
});
|
||||
|
||||
it('remove padding', () => {
|
||||
// padding can be anything after the expected size
|
||||
const expectedSize = 10;
|
||||
|
|
Loading…
Reference in New Issue