From 3b18df1c4fa379da6a1735899d5ce190636b7292 Mon Sep 17 00:00:00 2001 From: Anthony Stirling <77850077+Frooodle@users.noreply.github.com.> Date: Fri, 9 May 2025 13:48:47 +0100 Subject: [PATCH] pixel changes, redact color fix, version bump --- build.gradle | 2 +- .../software/SPDF/EE/EEAppConfig.java | 5 +++ .../software/SPDF/config/AppConfig.java | 37 +++++++++++++++++++ .../api/security/RedactController.java | 11 +++--- .../model/api/security/RedactPdfRequest.java | 2 +- .../resources/templates/fragments/common.html | 10 ++++- 6 files changed, 58 insertions(+), 9 deletions(-) diff --git a/build.gradle b/build.gradle index 76277cc99..cf642dae6 100644 --- a/build.gradle +++ b/build.gradle @@ -29,7 +29,7 @@ ext { } group = "stirling.software" -version = "0.46.0" +version = "0.46.1" java { // 17 is lowest but we support and recommend 21 diff --git a/src/main/java/stirling/software/SPDF/EE/EEAppConfig.java b/src/main/java/stirling/software/SPDF/EE/EEAppConfig.java index a83b17090..0bbb531ef 100644 --- a/src/main/java/stirling/software/SPDF/EE/EEAppConfig.java +++ b/src/main/java/stirling/software/SPDF/EE/EEAppConfig.java @@ -33,6 +33,11 @@ public class EEAppConfig { public boolean runningProOrHigher() { return licenseKeyChecker.getPremiumLicenseEnabledResult() != License.NORMAL; } + + @Bean(name = "license") + public String licenseType() { + return licenseKeyChecker.getPremiumLicenseEnabledResult().name(); + } @Bean(name = "runningEE") public boolean runningEnterprise() { diff --git a/src/main/java/stirling/software/SPDF/config/AppConfig.java b/src/main/java/stirling/software/SPDF/config/AppConfig.java index f07368527..5b52ed3a5 100644 --- a/src/main/java/stirling/software/SPDF/config/AppConfig.java +++ b/src/main/java/stirling/software/SPDF/config/AppConfig.java @@ -5,6 +5,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.List; +import java.util.Locale; import java.util.Properties; import java.util.function.Predicate; @@ -15,6 +16,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Scope; +import org.springframework.core.env.Environment; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceLoader; @@ -33,6 +35,8 @@ public class AppConfig { private final ApplicationProperties applicationProperties; + private final Environment env; + @Bean @ConditionalOnProperty(name = "system.customHTMLFiles", havingValue = "true") public SpringTemplateEngine templateEngine(ResourceLoader resourceLoader) { @@ -193,4 +197,37 @@ public class AppConfig { public String uuid() { return applicationProperties.getAutomaticallyGenerated().getUUID(); } + + @Bean(name = "disablePixel") + public boolean disablePixel() { + return Boolean.getBoolean(env.getProperty("DISABLE_PIXEL")); + } + + @Bean(name = "machineType") + public String determineMachineType() { + try { + boolean isDocker = runningInDocker(); + boolean isKubernetes = System.getenv("KUBERNETES_SERVICE_HOST") != null; + boolean isBrowserOpen = "true".equalsIgnoreCase(env.getProperty("BROWSER_OPEN")); + + if (isKubernetes) { + return "Kubernetes"; + } else if (isDocker) { + return "Docker"; + } else if (isBrowserOpen) { + String os = System.getProperty("os.name").toLowerCase(Locale.ROOT); + if (os.contains("win")) { + return "Client-windows"; + } else if (os.contains("mac")) { + return "Client-mac"; + } else { + return "Client-unix"; + } + } else { + return "Server-jar"; + } + } catch (Exception e) { + return "Unknown"; + } + } } diff --git a/src/main/java/stirling/software/SPDF/controller/api/security/RedactController.java b/src/main/java/stirling/software/SPDF/controller/api/security/RedactController.java index 0c8a7f7e6..df5e2499e 100644 --- a/src/main/java/stirling/software/SPDF/controller/api/security/RedactController.java +++ b/src/main/java/stirling/software/SPDF/controller/api/security/RedactController.java @@ -170,16 +170,17 @@ public class RedactController { } private Color decodeOrDefault(String hex, Color defaultColor) { - Color color = null; try { - color = Color.decode(hex); + if (hex != null && !hex.startsWith("#")) { + hex = "#" + hex; + } + return Color.decode(hex); } catch (Exception e) { - color = defaultColor; + return defaultColor; } - - return color; } + private List getPageNumbers(ManualRedactPdfRequest request, int pagesCount) { String pageNumbersInput = request.getPageNumbers(); String[] parsedPageNumbers = diff --git a/src/main/java/stirling/software/SPDF/model/api/security/RedactPdfRequest.java b/src/main/java/stirling/software/SPDF/model/api/security/RedactPdfRequest.java index 54c6a0aad..e92ae7c5a 100644 --- a/src/main/java/stirling/software/SPDF/model/api/security/RedactPdfRequest.java +++ b/src/main/java/stirling/software/SPDF/model/api/security/RedactPdfRequest.java @@ -23,7 +23,7 @@ public class RedactPdfRequest extends PDFFile { @Schema(description = "Whether to use whole word search", defaultValue = "false") private boolean wholeWordSearch; - @Schema(description = "The color for redaction", defaultValue = "#000000") + @Schema(description = "Hexadecimal color code for redaction, e.g. #FF0000 or 000000", defaultValue = "#000000") private String redactColor = "#000000"; @Schema(description = "Custom padding for redaction", type = "number") diff --git a/src/main/resources/templates/fragments/common.html b/src/main/resources/templates/fragments/common.html index 7fd26c777..3daebf03b 100644 --- a/src/main/resources/templates/fragments/common.html +++ b/src/main/resources/templates/fragments/common.html @@ -41,8 +41,14 @@ - - + +