From f109695d0ed4e61d7eae983cb46b82265d0a624b Mon Sep 17 00:00:00 2001 From: Tom Richards Date: Wed, 18 Dec 2024 22:42:41 +0000 Subject: [PATCH] make upload size limit optional and configurable --- .../gu/mediaservice/lib/config/CommonConfig.scala | 2 ++ .../app/controllers/ImageLoaderController.scala | 4 ++-- kahuna/app/views/main.scala.html | 1 + kahuna/public/js/upload/manager.js | 13 ++++++++----- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/common-lib/src/main/scala/com/gu/mediaservice/lib/config/CommonConfig.scala b/common-lib/src/main/scala/com/gu/mediaservice/lib/config/CommonConfig.scala index 7d72097b7d..ce25eec81e 100644 --- a/common-lib/src/main/scala/com/gu/mediaservice/lib/config/CommonConfig.scala +++ b/common-lib/src/main/scala/com/gu/mediaservice/lib/config/CommonConfig.scala @@ -54,6 +54,8 @@ abstract class CommonConfig(resources: GridConfigResources) extends AwsClientV1B val maybeIngestBucket: Option[String] = stringOpt("s3.ingest.bucket") val maybeFailBucket: Option[String] = stringOpt("s3.fail.bucket") + val maybeUploadLimitInBytes: Option[Int] = intOpt("upload.limit.mb").map(_ * 1_000_000) + // Note: had to make these lazy to avoid init order problems ;_; val domainRoot: String = string("domain.root") val domainRootOverride: Option[String] = stringOpt("domain.root-override") diff --git a/image-loader/app/controllers/ImageLoaderController.scala b/image-loader/app/controllers/ImageLoaderController.scala index 725023183f..14f311c62f 100644 --- a/image-loader/app/controllers/ImageLoaderController.scala +++ b/image-loader/app/controllers/ImageLoaderController.scala @@ -141,8 +141,8 @@ class ImageLoaderController(auth: Authentication, val approximateReceiveCount = getApproximateReceiveCount(sqsMessage) - if(s3IngestObject.contentLength > 500000000){ // 500MB - val errorMessage = s"File size exceeds the maximum allowed size (500MB). Moving to fail bucket." + if(config.maybeUploadLimitInBytes.exists(_ < s3IngestObject.contentLength)){ + val errorMessage = s"File size exceeds the maximum allowed size (${config.maybeUploadLimitInBytes.get / 1_000_000}MB). Moving to fail bucket." logger.warn(logMarker, errorMessage) store.moveObjectToFailedBucket(s3IngestObject.key) s3IngestObject.maybeMediaIdFromUiUpload foreach { imageId => diff --git a/kahuna/app/views/main.scala.html b/kahuna/app/views/main.scala.html index d579854688..c9878299b0 100644 --- a/kahuna/app/views/main.scala.html +++ b/kahuna/app/views/main.scala.html @@ -85,6 +85,7 @@ permissionsDefault: "@kahunaConfig.permissionsDefault", defaultShouldBlurGraphicImages: @kahunaConfig.defaultShouldBlurGraphicImages, shouldUploadStraightToBucket: @kahunaConfig.shouldUploadStraightToBucket, + maybeUploadLimitInBytes: @kahunaConfig.maybeUploadLimitInBytes, announcements: @Html(announcements), imageTypes: @Html(imageTypes), } diff --git a/kahuna/public/js/upload/manager.js b/kahuna/public/js/upload/manager.js index e4baff2a8b..6de5cf698a 100644 --- a/kahuna/public/js/upload/manager.js +++ b/kahuna/public/js/upload/manager.js @@ -33,15 +33,18 @@ upload.factory('uploadManager', async function createJobItems(_files){ - const filesAboveSizeLimit = _files.filter(file => file.size > 500000000); // 500MB + const maybeUploadLimitInBytes = window._clientConfig.maybeUploadLimitInBytes; + const maybeFilesAboveSizeLimit = maybeUploadLimitInBytes && _files.filter(file => file.size > maybeUploadLimitInBytes); - if (filesAboveSizeLimit.length > 0){ - alert(`The following files will be skipped as they are above the size limit of 500MB:\n ${ - filesAboveSizeLimit.map(file => file.name).join("\n") + if (maybeFilesAboveSizeLimit && maybeFilesAboveSizeLimit.length > 0){ + alert(`The following files will be skipped as they are above the size limit of ${maybeUploadLimitInBytes * 1_000_000}MB:\n ${ + maybeFilesAboveSizeLimit.map(file => file.name).join("\n") }`); } - const files = _files.filter(file => !filesAboveSizeLimit.includes(file)); + const files = maybeFilesAboveSizeLimit && maybeFilesAboveSizeLimit.length > 0 + ? _files.filter(file => !maybeFilesAboveSizeLimit.includes(file)) + : _files; if (window._clientConfig.shouldUploadStraightToBucket) { const mediaIdToFileMap = Object.fromEntries(