Skip to content

Commit f90f22a

Browse files
author
Steve Salas
committed
Add setting to adjust maximum file upload size
The new setting is cp.userSettings.maxFileUploadSizeMebibytes. Restart Code Pulse after editing maxFileUploadSizeMebibytes in codepulseSettings.conf.
1 parent 4673deb commit f90f22a

File tree

5 files changed

+45
-23
lines changed

5 files changed

+45
-23
lines changed

codepulse/src/main/resources/application.conf

+3-2
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@ cp {
1818
codedxLoggingLevel = "INFO"
1919
bootstrapLoggingLevel = "INFO"
2020
liftwebLoggingLevel = "WARN"
21-
}
21+
},
22+
maxFileUploadSizeMebibytes = 500
2223
},
2324
systemSettings {
2425
symbolService {
2526
binary = "SymbolService.exe"
2627
location = "dotnet-symbol-service/publish/"
2728
}
2829
}
29-
}
30+
}

codepulse/src/main/resources/toserve/pages/ProjectInputForm/ProjectInputForm.js

+19-10
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,24 @@ $(document).ready(function(){
8282
url: uploadUrl,
8383
dropZone: fileDropzone,
8484
add: function(e, data){
85-
if (data.files[0].size > 524288000) {
86-
alert('The file you specified exceeds the maximum file size (500 MB).');
87-
projectFile.set(null);
88-
return
89-
}
90-
91-
// use this `data` as the current file data.
92-
// this will be used once the form is submitted.
93-
projectFile.set(data)
85+
86+
$.ajax('/api/user-settings', {
87+
error: function(xhr, status){
88+
alert('Unable to fetch user settings that affect file upload')
89+
projectFile.set(null)
90+
},
91+
success: function(userSettings){
92+
if (data.files[0].size > userSettings.maxFileUploadSizeBytes) {
93+
alert('The file you specified exceeds the maximum file size (' + userSettings.maxFileUploadSizeBytes / (1024*1024) + ' MB).')
94+
projectFile.set(null)
95+
return
96+
}
97+
98+
// use this `data` as the current file data.
99+
// this will be used once the form is submitted.
100+
projectFile.set(data)
101+
}
102+
})
94103
},
95104
formData: function(){
96105
var name = projectName.get()
@@ -398,4 +407,4 @@ $(document).ready(function(){
398407
}
399408
}
400409

401-
})
410+
})

codepulse/src/main/scala/bootstrap/liftweb/FileUploadSetup.scala

+5-7
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,23 @@ package bootstrap.liftweb
2222
import java.io.File
2323
import java.io.IOException
2424

25-
import scala.util.control.Exception.catching
25+
import com.secdec.codepulse.userSettings
2626

27+
import scala.util.control.Exception.catching
2728
import org.apache.commons.fileupload.FileUploadBase.SizeLimitExceededException
2829
import org.apache.commons.io.FileUtils
2930
import org.apache.commons.io.FilenameUtils
3031
import org.apache.commons.io.IOUtils
31-
3232
import net.liftweb.common.Loggable
3333
import net.liftweb.http.JsonResponse
3434
import net.liftweb.http.LiftRules
3535
import net.liftweb.http.LiftRulesMocker.toLiftRules
3636
import net.liftweb.json.JsonDSL.pair2jvalue
3737
import net.liftweb.json.JsonDSL.string2jvalue
38-
3938
import com.secdec.codepulse.util.ManualOnDiskFileParamHolder
4039

4140
object FileUploadSetup extends Loggable {
4241

43-
val MaxFileSize = 500 * 1024 * 1024
44-
4542
def init(liftRules: LiftRules) = {
4643
setupMimeHandler(liftRules)
4744
setupUploadProgress(liftRules)
@@ -56,8 +53,9 @@ object FileUploadSetup extends Loggable {
5653

5754
def setupMimeHandler(liftRules: LiftRules) = {
5855

59-
liftRules.maxMimeFileSize = MaxFileSize
60-
liftRules.maxMimeSize = MaxFileSize
56+
val size = userSettings.maxFileUploadSizeBytes
57+
liftRules.maxMimeFileSize = size
58+
liftRules.maxMimeSize = size
6159

6260
// Send uploaded files to a temp folder instead of putting them in memory
6361
liftRules.handleMimeFile = (fieldName, contentType, fileName, stream) => {

codepulse/src/main/scala/com/secdec/codepulse/package.scala

+14-4
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,16 @@ package com.secdec
2121

2222
import java.text.SimpleDateFormat
2323
import java.util.Properties
24+
2425
import scala.collection.JavaConverters.propertiesAsScalaMapConverter
2526
import scala.util.Try
2627
import com.secdec.codepulse.util.ApplicationData
2728
import com.secdec.codepulse.util.Implicits._
28-
import com.typesafe.config.Config
29-
import com.typesafe.config.ConfigFactory
29+
import com.typesafe.config.{Config, ConfigException, ConfigFactory, ConfigRenderOptions, ConfigValueFactory}
3030
import java.io.File
31-
import com.typesafe.config.ConfigRenderOptions
3231
import java.io.FileWriter
32+
3333
import ch.qos.logback.classic.Level
34-
import com.typesafe.config.ConfigValueFactory
3534

3635
/** @author dylanh
3736
*
@@ -91,6 +90,17 @@ package object codepulse {
9190
newPort
9291
}
9392

93+
def maxFileUploadSizeBytes: Int = {
94+
val mebibytes = 1024 * 1024
95+
val defaultMaxSizeBytes = 500 * mebibytes
96+
try {
97+
val sizeMebibytes = config.getInt("cp.userSettings.maxFileUploadSizeMebibytes")
98+
if (sizeMebibytes > 0) sizeMebibytes * mebibytes else defaultMaxSizeBytes
99+
} catch {
100+
case _: com.typesafe.config.ConfigException.Missing => defaultMaxSizeBytes
101+
}
102+
}
103+
94104
def symbolServicePort = config.getString("cp.userSettings.symbolService.port")
95105

96106
def skipUserAcknowledgment = config.getBoolean("cp.userSettings.skipUserAcknowledgment")

codepulse/src/main/scala/com/secdec/codepulse/tracer/APIServer.scala

+4
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,10 @@ class APIServer(manager: ProjectManager, treeBuilderManager: TreeBuilderManager,
460460
case _ => PlainTextResponse("Unknown error.", 500)
461461
}
462462

463+
case List("api", "user-settings") Get req =>
464+
val settings: JObject = "maxFileUploadSizeBytes" -> userSettings.maxFileUploadSizeBytes
465+
JsonResponse(settings)
466+
463467
// GET the agent string
464468
case List("api", "agent-string") Get req =>
465469
PlainTextResponse(ConnectionHelp.traceAgentCommand)

0 commit comments

Comments
 (0)