fix: Import size should use larger of AWS_S3_UPLOAD_MAX_SIZE and MAX_IMPORT_SIZE

closes #4899
This commit is contained in:
Tom Moor
2023-02-19 19:18:31 -05:00
parent f63441c15d
commit 667ffdeaf1
2 changed files with 14 additions and 12 deletions

View File

@@ -253,15 +253,6 @@ export class Environment {
process.env.ENABLE_UPDATES ?? process.env.TELEMETRY ?? "true"
);
/**
* Because imports can be much larger than regular file attachments and are
* deleted automatically we allow an optional separate limit on the size of
* imports.
*/
@IsNumber()
public MAXIMUM_IMPORT_SIZE =
this.toOptionalNumber(process.env.MAXIMUM_IMPORT_SIZE) ?? 5120000;
/**
* An optional comma separated list of allowed domains.
*/
@@ -562,7 +553,7 @@ export class Environment {
@IsOptional()
@IsNumber()
public AWS_S3_UPLOAD_MAX_SIZE =
this.toOptionalNumber(process.env.AWS_S3_UPLOAD_MAX_SIZE) ?? 10000000000;
this.toOptionalNumber(process.env.AWS_S3_UPLOAD_MAX_SIZE) ?? 100000000;
/**
* Set default AWS S3 ACL for file attachments.
@@ -570,6 +561,17 @@ export class Environment {
@IsOptional()
public AWS_S3_ACL = process.env.AWS_S3_ACL ?? "private";
/**
* Because imports can be much larger than regular file attachments and are
* deleted automatically we allow an optional separate limit on the size of
* imports.
*/
@IsNumber()
public MAXIMUM_IMPORT_SIZE = Math.max(
this.toOptionalNumber(process.env.MAXIMUM_IMPORT_SIZE) ?? 100000000,
this.AWS_S3_UPLOAD_MAX_SIZE
);
/**
* The product name
*/

View File

@@ -65,10 +65,10 @@ export default class AttachmentHelper {
*/
static presetToMaxUploadSize(preset: AttachmentPreset) {
switch (preset) {
case AttachmentPreset.Avatar:
return Math.min(1024 * 1024 * 5, env.AWS_S3_UPLOAD_MAX_SIZE);
case AttachmentPreset.Import:
return env.MAXIMUM_IMPORT_SIZE;
case AttachmentPreset.Avatar:
case AttachmentPreset.DocumentAttachment:
default:
return env.AWS_S3_UPLOAD_MAX_SIZE;
}