2024-01-03 17:59:04 +00:00
|
|
|
package stirling.software.SPDF.config;
|
|
|
|
|
2024-01-09 21:13:35 -05:00
|
|
|
import java.io.IOException;
|
2024-01-09 22:39:21 +00:00
|
|
|
import java.nio.file.Files;
|
2024-05-25 00:22:01 +08:00
|
|
|
import java.nio.file.Path;
|
2024-01-09 22:39:21 +00:00
|
|
|
import java.nio.file.Paths;
|
2024-01-09 21:13:35 -05:00
|
|
|
import java.util.Properties;
|
2024-05-25 00:22:01 +08:00
|
|
|
import java.util.function.Predicate;
|
2024-01-09 21:13:35 -05:00
|
|
|
|
2024-01-03 17:59:04 +00:00
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
2024-04-21 22:16:39 +02:00
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
|
2024-04-27 11:03:57 +01:00
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
2024-01-03 17:59:04 +00:00
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
2024-04-27 11:03:57 +01:00
|
|
|
import org.springframework.context.annotation.Lazy;
|
2024-01-09 21:13:35 -05:00
|
|
|
import org.springframework.core.io.ClassPathResource;
|
|
|
|
import org.springframework.core.io.Resource;
|
2024-04-27 11:03:57 +01:00
|
|
|
import org.springframework.core.io.ResourceLoader;
|
|
|
|
import org.thymeleaf.spring6.SpringTemplateEngine;
|
2024-01-03 17:59:04 +00:00
|
|
|
|
|
|
|
import stirling.software.SPDF.model.ApplicationProperties;
|
|
|
|
|
|
|
|
@Configuration
|
2024-04-27 11:03:57 +01:00
|
|
|
@Lazy
|
2024-01-03 17:59:04 +00:00
|
|
|
public class AppConfig {
|
|
|
|
|
|
|
|
@Autowired ApplicationProperties applicationProperties;
|
|
|
|
|
2024-04-27 11:03:57 +01:00
|
|
|
@Bean
|
|
|
|
@ConditionalOnProperty(
|
|
|
|
name = "system.customHTMLFiles",
|
|
|
|
havingValue = "true",
|
|
|
|
matchIfMissing = false)
|
|
|
|
public SpringTemplateEngine templateEngine(ResourceLoader resourceLoader) {
|
|
|
|
SpringTemplateEngine templateEngine = new SpringTemplateEngine();
|
|
|
|
templateEngine.addTemplateResolver(new FileFallbackTemplateResolver(resourceLoader));
|
|
|
|
return templateEngine;
|
|
|
|
}
|
|
|
|
|
2024-01-03 17:59:04 +00:00
|
|
|
@Bean(name = "loginEnabled")
|
|
|
|
public boolean loginEnabled() {
|
|
|
|
return applicationProperties.getSecurity().getEnableLogin();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Bean(name = "appName")
|
|
|
|
public String appName() {
|
|
|
|
String homeTitle = applicationProperties.getUi().getAppName();
|
|
|
|
return (homeTitle != null) ? homeTitle : "Stirling PDF";
|
|
|
|
}
|
|
|
|
|
|
|
|
@Bean(name = "appVersion")
|
|
|
|
public String appVersion() {
|
2024-01-09 21:13:35 -05:00
|
|
|
Resource resource = new ClassPathResource("version.properties");
|
|
|
|
Properties props = new Properties();
|
|
|
|
try {
|
|
|
|
props.load(resource.getInputStream());
|
|
|
|
return props.getProperty("version");
|
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
return "0.0.0";
|
2024-01-03 17:59:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Bean(name = "homeText")
|
|
|
|
public String homeText() {
|
|
|
|
return (applicationProperties.getUi().getHomeDescription() != null)
|
|
|
|
? applicationProperties.getUi().getHomeDescription()
|
|
|
|
: "null";
|
|
|
|
}
|
|
|
|
|
|
|
|
@Bean(name = "navBarText")
|
|
|
|
public String navBarText() {
|
|
|
|
String defaultNavBar =
|
|
|
|
applicationProperties.getUi().getAppNameNavbar() != null
|
|
|
|
? applicationProperties.getUi().getAppNameNavbar()
|
|
|
|
: applicationProperties.getUi().getAppName();
|
|
|
|
return (defaultNavBar != null) ? defaultNavBar : "Stirling PDF";
|
|
|
|
}
|
|
|
|
|
|
|
|
@Bean(name = "enableAlphaFunctionality")
|
|
|
|
public boolean enableAlphaFunctionality() {
|
|
|
|
return applicationProperties.getSystem().getEnableAlphaFunctionality() != null
|
|
|
|
? applicationProperties.getSystem().getEnableAlphaFunctionality()
|
|
|
|
: false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Bean(name = "rateLimit")
|
|
|
|
public boolean rateLimit() {
|
|
|
|
String appName = System.getProperty("rateLimit");
|
|
|
|
if (appName == null) appName = System.getenv("rateLimit");
|
|
|
|
return (appName != null) ? Boolean.valueOf(appName) : false;
|
|
|
|
}
|
2024-01-09 22:39:21 +00:00
|
|
|
|
|
|
|
@Bean(name = "RunningInDocker")
|
|
|
|
public boolean runningInDocker() {
|
|
|
|
return Files.exists(Paths.get("/.dockerenv"));
|
|
|
|
}
|
|
|
|
|
2024-02-10 00:00:07 +00:00
|
|
|
@Bean(name = "bookAndHtmlFormatsInstalled")
|
|
|
|
public boolean bookAndHtmlFormatsInstalled() {
|
2024-03-04 20:51:49 +00:00
|
|
|
String installOps = System.getProperty("INSTALL_BOOK_AND_ADVANCED_HTML_OPS");
|
|
|
|
if (installOps == null) {
|
|
|
|
installOps = System.getenv("INSTALL_BOOK_AND_ADVANCED_HTML_OPS");
|
|
|
|
}
|
|
|
|
return "true".equalsIgnoreCase(installOps);
|
2024-01-09 22:39:21 +00:00
|
|
|
}
|
2024-04-21 22:16:39 +02:00
|
|
|
|
|
|
|
@ConditionalOnMissingClass("stirling.software.SPDF.config.security.SecurityConfiguration")
|
|
|
|
@Bean(name = "activSecurity")
|
|
|
|
public boolean missingActivSecurity() {
|
|
|
|
return false;
|
|
|
|
}
|
2024-05-25 00:22:01 +08:00
|
|
|
|
|
|
|
@Bean(name = "watchedFoldersDir")
|
|
|
|
public String watchedFoldersDir() {
|
|
|
|
return "./pipeline/watchedFolders/";
|
|
|
|
}
|
|
|
|
|
|
|
|
@Bean(name = "finishedFoldersDir")
|
|
|
|
public String finishedFoldersDir() {
|
|
|
|
return "./pipeline/finishedFolders/";
|
|
|
|
}
|
|
|
|
|
|
|
|
@Bean(name = "directoryFilter")
|
|
|
|
public Predicate<Path> processPDFOnlyFilter() {
|
|
|
|
return path -> {
|
|
|
|
if (Files.isDirectory(path)) {
|
|
|
|
return !path.toString()
|
|
|
|
.contains(
|
|
|
|
"processing");
|
|
|
|
} else {
|
|
|
|
String fileName = path.getFileName().toString();
|
|
|
|
return fileName.endsWith(".pdf");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2024-01-03 17:59:04 +00:00
|
|
|
}
|