Skip to content

Commit d815827

Browse files
committed
make upload size limit optional and configurable
1 parent 7e98a00 commit d815827

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

common-lib/src/main/scala/com/gu/mediaservice/lib/config/CommonConfig.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ abstract class CommonConfig(resources: GridConfigResources) extends AwsClientV1B
5454
val maybeIngestBucket: Option[String] = stringOpt("s3.ingest.bucket")
5555
val maybeFailBucket: Option[String] = stringOpt("s3.fail.bucket")
5656

57+
val maybeUploadLimitInBytes: Option[Int] = intOpt("upload.limit.mb").map(_ * 1_000_000)
58+
5759
// Note: had to make these lazy to avoid init order problems ;_;
5860
val domainRoot: String = string("domain.root")
5961
val domainRootOverride: Option[String] = stringOpt("domain.root-override")

image-loader/app/controllers/ImageLoaderController.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ class ImageLoaderController(auth: Authentication,
141141

142142
val approximateReceiveCount = getApproximateReceiveCount(sqsMessage)
143143

144-
if(s3IngestObject.contentLength > 500000000){ // 500MB
145-
val errorMessage = s"File size exceeds the maximum allowed size (500MB). Moving to fail bucket."
144+
if(config.maybeUploadLimitInBytes.exists(_ < s3IngestObject.contentLength)){
145+
val errorMessage = s"File size exceeds the maximum allowed size (${config.maybeUploadLimitInBytes.get / 1_000_000}MB). Moving to fail bucket."
146146
logger.warn(logMarker, errorMessage)
147147
store.moveObjectToFailedBucket(s3IngestObject.key)
148148
s3IngestObject.maybeMediaIdFromUiUpload foreach { imageId =>

kahuna/app/views/main.scala.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
permissionsDefault: "@kahunaConfig.permissionsDefault",
8686
defaultShouldBlurGraphicImages: @kahunaConfig.defaultShouldBlurGraphicImages,
8787
shouldUploadStraightToBucket: @kahunaConfig.shouldUploadStraightToBucket,
88+
maybeUploadLimitInBytes: @kahunaConfig.maybeUploadLimitInBytes,
8889
announcements: @Html(announcements),
8990
imageTypes: @Html(imageTypes),
9091
}

kahuna/public/js/upload/manager.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,18 @@ upload.factory('uploadManager',
3333

3434
async function createJobItems(_files){
3535

36-
const filesAboveSizeLimit = _files.filter(file => file.size > 500000000); // 500MB
36+
const maybeUploadLimitInBytes = window._clientConfig.maybeUploadLimitInBytes;
37+
const maybeFilesAboveSizeLimit = maybeUploadLimitInBytes && _files.filter(file => file.size > maybeUploadLimitInBytes);
3738

38-
if (filesAboveSizeLimit.length > 0){
39-
alert(`The following files will be skipped as they are above the size limit of 500MB:\n ${
40-
filesAboveSizeLimit.map(file => file.name).join("\n")
39+
if (maybeFilesAboveSizeLimit && maybeFilesAboveSizeLimit.length > 0){
40+
alert(`The following files will be skipped as they are above the size limit of ${maybeUploadLimitInBytes / 1_000_000}MB:\n${
41+
maybeFilesAboveSizeLimit.map(file => file.name).join("\n")
4142
}`);
4243
}
4344

44-
const files = _files.filter(file => !filesAboveSizeLimit.includes(file));
45+
const files = maybeFilesAboveSizeLimit && maybeFilesAboveSizeLimit.length > 0
46+
? _files.filter(file => !maybeFilesAboveSizeLimit.includes(file))
47+
: _files;
4548

4649
if (window._clientConfig.shouldUploadStraightToBucket) {
4750
const mediaIdToFileMap = Object.fromEntries(

0 commit comments

Comments
 (0)