Skip to content

Commit

Permalink
make upload size limit optional and configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
twrichards committed Dec 19, 2024
1 parent 760cccd commit f109695
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions image-loader/app/controllers/ImageLoaderController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
Expand Down
1 change: 1 addition & 0 deletions kahuna/app/views/main.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
permissionsDefault: "@kahunaConfig.permissionsDefault",
defaultShouldBlurGraphicImages: @kahunaConfig.defaultShouldBlurGraphicImages,
shouldUploadStraightToBucket: @kahunaConfig.shouldUploadStraightToBucket,
maybeUploadLimitInBytes: @kahunaConfig.maybeUploadLimitInBytes,
announcements: @Html(announcements),
imageTypes: @Html(imageTypes),
}
Expand Down
13 changes: 8 additions & 5 deletions kahuna/public/js/upload/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit f109695

Please sign in to comment.