mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2025-06-06 18:30:57 +00:00
Create the upload limit config
This commit is contained in:
parent
b024fb3ede
commit
56a8fea5d3
@ -20,6 +20,8 @@ import org.springframework.core.io.Resource;
|
|||||||
import org.springframework.core.io.ResourceLoader;
|
import org.springframework.core.io.ResourceLoader;
|
||||||
import org.thymeleaf.spring6.SpringTemplateEngine;
|
import org.thymeleaf.spring6.SpringTemplateEngine;
|
||||||
|
|
||||||
|
import com.posthog.java.shaded.kotlin.text.Regex;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import stirling.software.SPDF.model.ApplicationProperties;
|
import stirling.software.SPDF.model.ApplicationProperties;
|
||||||
@ -107,6 +109,32 @@ public class AppConfig {
|
|||||||
return (rateLimit != null) ? Boolean.valueOf(rateLimit) : false;
|
return (rateLimit != null) ? Boolean.valueOf(rateLimit) : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Bean(name = "uploadLimit")
|
||||||
|
public long uploadLimit() {
|
||||||
|
boolean uploadLimit = applicationProperties.getSystem().getUploadLimit().getEnabled() != null
|
||||||
|
? applicationProperties.getSystem().getUploadLimit().getEnabled()
|
||||||
|
: false;
|
||||||
|
String maxUploadSize = applicationProperties.getSystem().getUploadLimit().getMaxSize();
|
||||||
|
if (new Regex("^[1-9][0-9]{0,2}[K|M|G]B$").matches(maxUploadSize)) {
|
||||||
|
log.error("Invalid maxUploadSize format. Expected format: {1,3}[0-9][K|M|G]B, but got: {}",
|
||||||
|
maxUploadSize);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (!uploadLimit || maxUploadSize == null || maxUploadSize.isEmpty()) {
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
String number = maxUploadSize.replaceAll("[^0-9]", "");
|
||||||
|
String unit = maxUploadSize.replaceAll("[KB|MB|GB]", "");
|
||||||
|
long size = Long.parseLong(number);
|
||||||
|
return switch (unit) {
|
||||||
|
case "KB" -> size * 1024;
|
||||||
|
case "MB" -> size * 1024 * 1024;
|
||||||
|
case "GB" -> size * 1024 * 1024 * 1024;
|
||||||
|
default -> 0;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Bean(name = "RunningInDocker")
|
@Bean(name = "RunningInDocker")
|
||||||
public boolean runningInDocker() {
|
public boolean runningInDocker() {
|
||||||
return Files.exists(Paths.get("/.dockerenv"));
|
return Files.exists(Paths.get("/.dockerenv"));
|
||||||
|
@ -290,12 +290,19 @@ public class ApplicationProperties {
|
|||||||
private Boolean disableSanitize;
|
private Boolean disableSanitize;
|
||||||
private Boolean enableUrlToPDF;
|
private Boolean enableUrlToPDF;
|
||||||
private CustomPaths customPaths = new CustomPaths();
|
private CustomPaths customPaths = new CustomPaths();
|
||||||
|
private UploadLimit uploadLimit;
|
||||||
|
|
||||||
public boolean isAnalyticsEnabled() {
|
public boolean isAnalyticsEnabled() {
|
||||||
return this.getEnableAnalytics() != null && this.getEnableAnalytics();
|
return this.getEnableAnalytics() != null && this.getEnableAnalytics();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class UploadLimit {
|
||||||
|
private Boolean enabled;
|
||||||
|
private String maxSize;
|
||||||
|
}
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public static class CustomPaths {
|
public static class CustomPaths {
|
||||||
private Pipeline pipeline = new Pipeline();
|
private Pipeline pipeline = new Pipeline();
|
||||||
|
@ -107,6 +107,9 @@ system:
|
|||||||
operations:
|
operations:
|
||||||
weasyprint: "" #Defaults to /opt/venv/bin/weasyprint
|
weasyprint: "" #Defaults to /opt/venv/bin/weasyprint
|
||||||
unoconvert: "" #Defaults to /opt/venv/bin/unoconvert
|
unoconvert: "" #Defaults to /opt/venv/bin/unoconvert
|
||||||
|
uploadLimit:
|
||||||
|
enableUploadSizeLimit: false # Set to 'true' to enforce a size limit on files uploaded
|
||||||
|
limit: "" # Defaults to '0MB'. Set a number, between 0 and 999, followed by one of the following strings to set a limit. "KB", "MB", "GB".
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user