mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2025-08-02 10:35:22 +00:00
Merge branch 'org' of git@github.com:Stirling-Tools/Stirling-PDF.git into org
This commit is contained in:
commit
7af18cb10c
1
.github/labeler-config-srvaroa.yml
vendored
1
.github/labeler-config-srvaroa.yml
vendored
@ -78,6 +78,7 @@ labels:
|
|||||||
- 'app/core/src/main/resources/banner.txt'
|
- 'app/core/src/main/resources/banner.txt'
|
||||||
- 'app/core/src/main/resources/static/python/png_to_webp.py'
|
- 'app/core/src/main/resources/static/python/png_to_webp.py'
|
||||||
- 'app/core/src/main/resources/static/python/split_photos.py'
|
- 'app/core/src/main/resources/static/python/split_photos.py'
|
||||||
|
- 'app/core/src/main/resources/static/pipeline/defaultWebUIConfigs/**'
|
||||||
- 'application.properties'
|
- 'application.properties'
|
||||||
|
|
||||||
- label: 'Security'
|
- label: 'Security'
|
||||||
|
@ -3,7 +3,6 @@ FROM alpine:3.22.1@sha256:4bcff63911fcb4448bd4fdacec207030997caf25e9bea4045fa6c8
|
|||||||
|
|
||||||
# Copy necessary files
|
# Copy necessary files
|
||||||
COPY scripts /scripts
|
COPY scripts /scripts
|
||||||
COPY pipeline /pipeline
|
|
||||||
COPY app/core/src/main/resources/static/fonts/*.ttf /usr/share/fonts/opentype/noto/
|
COPY app/core/src/main/resources/static/fonts/*.ttf /usr/share/fonts/opentype/noto/
|
||||||
COPY app/core/build/libs/*.jar app.jar
|
COPY app/core/build/libs/*.jar app.jar
|
||||||
|
|
||||||
|
@ -26,7 +26,6 @@ FROM alpine:3.22.1@sha256:4bcff63911fcb4448bd4fdacec207030997caf25e9bea4045fa6c8
|
|||||||
|
|
||||||
# Copy necessary files
|
# Copy necessary files
|
||||||
COPY scripts /scripts
|
COPY scripts /scripts
|
||||||
COPY pipeline /pipeline
|
|
||||||
COPY app/core/src/main/resources/static/fonts/*.ttf /usr/share/fonts/opentype/noto/
|
COPY app/core/src/main/resources/static/fonts/*.ttf /usr/share/fonts/opentype/noto/
|
||||||
# first /app directory is for the build stage, second is for the final image
|
# first /app directory is for the build stage, second is for the final image
|
||||||
COPY --from=build /app/app/core/build/libs/*.jar app.jar
|
COPY --from=build /app/app/core/build/libs/*.jar app.jar
|
||||||
|
@ -21,7 +21,6 @@ ENV DISABLE_ADDITIONAL_FEATURES=true \
|
|||||||
COPY scripts/download-security-jar.sh /scripts/download-security-jar.sh
|
COPY scripts/download-security-jar.sh /scripts/download-security-jar.sh
|
||||||
COPY scripts/init-without-ocr.sh /scripts/init-without-ocr.sh
|
COPY scripts/init-without-ocr.sh /scripts/init-without-ocr.sh
|
||||||
COPY scripts/installFonts.sh /scripts/installFonts.sh
|
COPY scripts/installFonts.sh /scripts/installFonts.sh
|
||||||
COPY pipeline /pipeline
|
|
||||||
COPY app/core/build/libs/*.jar app.jar
|
COPY app/core/build/libs/*.jar app.jar
|
||||||
|
|
||||||
# Set up necessary directories and permissions
|
# Set up necessary directories and permissions
|
||||||
@ -39,10 +38,10 @@ RUN echo "@testing https://dl-cdn.alpinelinux.org/alpine/edge/main" | tee -a /et
|
|||||||
su-exec \
|
su-exec \
|
||||||
openjdk21-jre && \
|
openjdk21-jre && \
|
||||||
# User permissions
|
# User permissions
|
||||||
mkdir -p /configs /logs /customFiles /usr/share/fonts/opentype/noto /tmp/stirling-pdf && \
|
mkdir -p /configs /logs /customFiles /usr/share/fonts/opentype/noto /tmp/stirling-pdf /pipeline/watchedFolders /pipeline/finishedFolders && \
|
||||||
chmod +x /scripts/*.sh && \
|
chmod +x /scripts/*.sh && \
|
||||||
addgroup -S stirlingpdfgroup && adduser -S stirlingpdfuser -G stirlingpdfgroup && \
|
addgroup -S stirlingpdfgroup && adduser -S stirlingpdfuser -G stirlingpdfgroup && \
|
||||||
chown -R stirlingpdfuser:stirlingpdfgroup $HOME /scripts /configs /customFiles /pipeline /tmp/stirling-pdf && \
|
chown -R stirlingpdfuser:stirlingpdfgroup $HOME /scripts /pipeline /configs /customFiles /tmp/stirling-pdf && \
|
||||||
chown stirlingpdfuser:stirlingpdfgroup /app.jar
|
chown stirlingpdfuser:stirlingpdfgroup /app.jar
|
||||||
|
|
||||||
# Set environment variables
|
# Set environment variables
|
||||||
|
@ -15,6 +15,7 @@ public class InstallationPathConfig {
|
|||||||
private static final String CUSTOM_FILES_PATH;
|
private static final String CUSTOM_FILES_PATH;
|
||||||
private static final String CLIENT_WEBUI_PATH;
|
private static final String CLIENT_WEBUI_PATH;
|
||||||
private static final String SCRIPTS_PATH;
|
private static final String SCRIPTS_PATH;
|
||||||
|
private static final String PIPELINE_PATH;
|
||||||
|
|
||||||
// Config paths
|
// Config paths
|
||||||
private static final String SETTINGS_PATH;
|
private static final String SETTINGS_PATH;
|
||||||
@ -33,6 +34,7 @@ public class InstallationPathConfig {
|
|||||||
CONFIG_PATH = BASE_PATH + "configs" + File.separator;
|
CONFIG_PATH = BASE_PATH + "configs" + File.separator;
|
||||||
CUSTOM_FILES_PATH = BASE_PATH + "customFiles" + File.separator;
|
CUSTOM_FILES_PATH = BASE_PATH + "customFiles" + File.separator;
|
||||||
CLIENT_WEBUI_PATH = BASE_PATH + "clientWebUI" + File.separator;
|
CLIENT_WEBUI_PATH = BASE_PATH + "clientWebUI" + File.separator;
|
||||||
|
PIPELINE_PATH = BASE_PATH + "pipeline" + File.separator;
|
||||||
|
|
||||||
// Initialize config paths
|
// Initialize config paths
|
||||||
SETTINGS_PATH = CONFIG_PATH + "settings.yml";
|
SETTINGS_PATH = CONFIG_PATH + "settings.yml";
|
||||||
@ -95,6 +97,10 @@ public class InstallationPathConfig {
|
|||||||
return SCRIPTS_PATH;
|
return SCRIPTS_PATH;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getPipelinePath() {
|
||||||
|
return PIPELINE_PATH;
|
||||||
|
}
|
||||||
|
|
||||||
public static String getSettingsPath() {
|
public static String getSettingsPath() {
|
||||||
return SETTINGS_PATH;
|
return SETTINGS_PATH;
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ import java.util.Arrays;
|
|||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.springframework.core.io.ClassPathResource;
|
import org.springframework.core.io.ClassPathResource;
|
||||||
@ -34,8 +35,16 @@ import stirling.software.common.configuration.InstallationPathConfig;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class GeneralUtils {
|
public class GeneralUtils {
|
||||||
|
|
||||||
private static final List<String> DEFAULT_VALID_SCRIPTS =
|
private static final Set<String> DEFAULT_VALID_SCRIPTS =
|
||||||
List.of("png_to_webp.py", "split_photos.py");
|
Set.of("png_to_webp.py", "split_photos.py");
|
||||||
|
private static final Set<String> DEFAULT_VALID_PIPELINE =
|
||||||
|
Set.of(
|
||||||
|
"OCR images.json",
|
||||||
|
"Prepare-pdfs-for-email.json",
|
||||||
|
"split-rotate-auto-rename.json");
|
||||||
|
|
||||||
|
private static final String DEFAULT_WEBUI_CONFIGS_DIR = "defaultWebUIConfigs";
|
||||||
|
private static final String PYTHON_SCRIPTS_DIR = "python";
|
||||||
|
|
||||||
public static File convertMultipartFileToFile(MultipartFile multipartFile) throws IOException {
|
public static File convertMultipartFileToFile(MultipartFile multipartFile) throws IOException {
|
||||||
String customTempDir = System.getenv("STIRLING_TEMPFILES_DIRECTORY");
|
String customTempDir = System.getenv("STIRLING_TEMPFILES_DIRECTORY");
|
||||||
@ -446,6 +455,48 @@ public class GeneralUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extracts the default pipeline configurations from the classpath to the installation path.
|
||||||
|
* Creates directories if needed and copies default JSON files.
|
||||||
|
*
|
||||||
|
* <p>Existing files will be overwritten atomically (when supported). In case of unsupported
|
||||||
|
* atomic moves, falls back to non-atomic replace.
|
||||||
|
*
|
||||||
|
* @throws IOException if an I/O error occurs during file operations
|
||||||
|
*/
|
||||||
|
public static void extractPipeline() throws IOException {
|
||||||
|
Path pipelineDir =
|
||||||
|
Paths.get(InstallationPathConfig.getPipelinePath(), DEFAULT_WEBUI_CONFIGS_DIR);
|
||||||
|
Files.createDirectories(pipelineDir);
|
||||||
|
|
||||||
|
for (String name : DEFAULT_VALID_PIPELINE) {
|
||||||
|
if (!Paths.get(name).getFileName().toString().equals(name)) {
|
||||||
|
log.error("Invalid pipeline file name: {}", name);
|
||||||
|
throw new IllegalArgumentException("Invalid pipeline file name: " + name);
|
||||||
|
}
|
||||||
|
Path target = pipelineDir.resolve(name);
|
||||||
|
ClassPathResource res =
|
||||||
|
new ClassPathResource(
|
||||||
|
"static/pipeline/" + DEFAULT_WEBUI_CONFIGS_DIR + "/" + name);
|
||||||
|
if (!res.exists()) {
|
||||||
|
log.error("Resource not found: {}", res.getPath());
|
||||||
|
throw new IOException("Resource not found: " + res.getPath());
|
||||||
|
}
|
||||||
|
copyResourceToFile(res, target);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extracts the specified Python script from the classpath to the installation path. Validates
|
||||||
|
* name and copies file atomically when possible, overwriting existing.
|
||||||
|
*
|
||||||
|
* <p>Existing files will be overwritten atomically (when supported).
|
||||||
|
*
|
||||||
|
* @param scriptName the name of the script to extract
|
||||||
|
* @return the path to the extracted script
|
||||||
|
* @throws IllegalArgumentException if the script name is invalid or not allowed
|
||||||
|
* @throws IOException if an I/O error occurs
|
||||||
|
*/
|
||||||
public static Path extractScript(String scriptName) throws IOException {
|
public static Path extractScript(String scriptName) throws IOException {
|
||||||
// Validate input
|
// Validate input
|
||||||
if (scriptName == null || scriptName.trim().isEmpty()) {
|
if (scriptName == null || scriptName.trim().isEmpty()) {
|
||||||
@ -455,26 +506,71 @@ public class GeneralUtils {
|
|||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"scriptName must not contain path traversal characters");
|
"scriptName must not contain path traversal characters");
|
||||||
}
|
}
|
||||||
|
if (!Paths.get(scriptName).getFileName().toString().equals(scriptName)) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"scriptName must not contain path traversal characters");
|
||||||
|
}
|
||||||
|
|
||||||
if (!DEFAULT_VALID_SCRIPTS.contains(scriptName)) {
|
if (!DEFAULT_VALID_SCRIPTS.contains(scriptName)) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"scriptName must be either 'png_to_webp.py' or 'split_photos.py'");
|
"scriptName must be either 'png_to_webp.py' or 'split_photos.py'");
|
||||||
}
|
}
|
||||||
|
|
||||||
Path scriptsDir = Paths.get(InstallationPathConfig.getScriptsPath(), "python");
|
Path scriptsDir = Paths.get(InstallationPathConfig.getScriptsPath(), PYTHON_SCRIPTS_DIR);
|
||||||
Files.createDirectories(scriptsDir);
|
Files.createDirectories(scriptsDir);
|
||||||
|
|
||||||
Path scriptFile = scriptsDir.resolve(scriptName);
|
Path target = scriptsDir.resolve(scriptName);
|
||||||
if (!Files.exists(scriptFile)) {
|
ClassPathResource res =
|
||||||
ClassPathResource resource = new ClassPathResource("static/python/" + scriptName);
|
new ClassPathResource("static/" + PYTHON_SCRIPTS_DIR + "/" + scriptName);
|
||||||
try (InputStream in = resource.getInputStream()) {
|
if (!res.exists()) {
|
||||||
Files.copy(in, scriptFile, StandardCopyOption.REPLACE_EXISTING);
|
log.error("Resource not found: {}", res.getPath());
|
||||||
|
throw new IOException("Resource not found: " + res.getPath());
|
||||||
|
}
|
||||||
|
copyResourceToFile(res, target);
|
||||||
|
return target;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copies a resource from the classpath to a specified target file.
|
||||||
|
*
|
||||||
|
* @param resource the ClassPathResource to copy
|
||||||
|
* @param target the target Path where the resource will be copied
|
||||||
|
* @throws IOException if an I/O error occurs during the copy operation
|
||||||
|
*/
|
||||||
|
private static void copyResourceToFile(ClassPathResource resource, Path target)
|
||||||
|
throws IOException {
|
||||||
|
Path dir = target.getParent();
|
||||||
|
Path tmp = Files.createTempFile(dir, target.getFileName().toString(), ".tmp");
|
||||||
|
try (InputStream in = resource.getInputStream()) {
|
||||||
|
Files.copy(in, tmp, StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
try {
|
||||||
|
Files.move(tmp, target, StandardCopyOption.ATOMIC_MOVE);
|
||||||
|
} catch (AtomicMoveNotSupportedException e) {
|
||||||
|
log.warn(
|
||||||
|
"Atomic move not supported, falling back to non-atomic move for {}",
|
||||||
|
target,
|
||||||
|
e);
|
||||||
|
Files.move(tmp, target, StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
}
|
||||||
|
} catch (FileAlreadyExistsException e) {
|
||||||
|
log.debug("File already exists at {}, attempting to replace it.", target);
|
||||||
|
Files.move(tmp, target, StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
} catch (AccessDeniedException e) {
|
||||||
|
log.error("Access denied while attempting to copy resource to {}", target, e);
|
||||||
|
throw e;
|
||||||
|
} catch (FileSystemException e) {
|
||||||
|
log.error("File system error occurred while copying resource to {}", target, e);
|
||||||
|
throw e;
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error("Failed to copy resource to {}", target, e);
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
Files.deleteIfExists(tmp);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.error("Failed to extract Python script", e);
|
log.warn("Failed to delete temporary file {}", tmp, e);
|
||||||
throw e;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return scriptFile;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isVersionHigher(String currentVersion, String compareVersion) {
|
public static boolean isVersionHigher(String currentVersion, String compareVersion) {
|
||||||
|
3
app/core/.gitignore
vendored
3
app/core/.gitignore
vendored
@ -16,8 +16,7 @@ local.properties
|
|||||||
version.properties
|
version.properties
|
||||||
|
|
||||||
#### Stirling-PDF Files ###
|
#### Stirling-PDF Files ###
|
||||||
pipeline/watchedFolders/
|
pipeline/*
|
||||||
pipeline/finishedFolders/
|
|
||||||
customFiles/
|
customFiles/
|
||||||
configs/
|
configs/
|
||||||
watchedFolders/
|
watchedFolders/
|
||||||
|
@ -35,6 +35,7 @@ public class InitialSetup {
|
|||||||
initEnableCSRFSecurity();
|
initEnableCSRFSecurity();
|
||||||
initLegalUrls();
|
initLegalUrls();
|
||||||
initSetAppVersion();
|
initSetAppVersion();
|
||||||
|
GeneralUtils.extractPipeline();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initUUIDKey() throws IOException {
|
public void initUUIDKey() throws IOException {
|
||||||
|
@ -82,55 +82,62 @@ document.querySelector("#navbarSearchInput").addEventListener("input", function
|
|||||||
resultsBox.style.width = window.navItemMaxWidth + "px";
|
resultsBox.style.width = window.navItemMaxWidth + "px";
|
||||||
});
|
});
|
||||||
|
|
||||||
|
document.addEventListener('DOMContentLoaded', function () {
|
||||||
|
const searchDropdown = document.getElementById('searchDropdown');
|
||||||
|
const searchInput = document.getElementById('navbarSearchInput');
|
||||||
|
|
||||||
const searchDropdown = document.getElementById('searchDropdown');
|
// Check if elements are missing and skip initialization if necessary
|
||||||
const searchInput = document.getElementById('navbarSearchInput');
|
if (!searchDropdown || !searchInput) {
|
||||||
|
console.warn('Search dropdown or input not found. Skipping initialization.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const dropdownMenu = searchDropdown.querySelector('.dropdown-menu');
|
||||||
|
if (!dropdownMenu) {
|
||||||
|
console.warn('Dropdown menu not found within the search dropdown. Skipping initialization.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Check if elements exist before proceeding
|
// Create a single dropdown instance
|
||||||
if (searchDropdown && searchInput) {
|
const dropdownInstance = new bootstrap.Dropdown(searchDropdown);
|
||||||
const dropdownMenu = searchDropdown.querySelector('.dropdown-menu');
|
|
||||||
|
|
||||||
// Create a single dropdown instance
|
// Handle click for mobile
|
||||||
const dropdownInstance = new bootstrap.Dropdown(searchDropdown);
|
searchDropdown.addEventListener('click', function (e) {
|
||||||
|
e.preventDefault();
|
||||||
// Handle click for mobile
|
const isOpen = dropdownMenu.classList.contains('show');
|
||||||
searchDropdown.addEventListener('click', function (e) {
|
// Close all other open dropdowns
|
||||||
e.preventDefault();
|
document.querySelectorAll('.navbar-nav .dropdown-menu.show').forEach((menu) => {
|
||||||
const isOpen = dropdownMenu.classList.contains('show');
|
if (menu !== dropdownMenu) {
|
||||||
// Close all other open dropdowns
|
const parentDropdown = menu.closest('.dropdown');
|
||||||
document.querySelectorAll('.navbar-nav .dropdown-menu.show').forEach((menu) => {
|
if (parentDropdown) {
|
||||||
if (menu !== dropdownMenu) {
|
const parentToggle = parentDropdown.querySelector('[data-bs-toggle="dropdown"]');
|
||||||
const parentDropdown = menu.closest('.dropdown');
|
if (parentToggle) {
|
||||||
if (parentDropdown) {
|
let instance = bootstrap.Dropdown.getInstance(parentToggle);
|
||||||
const parentToggle = parentDropdown.querySelector('[data-bs-toggle="dropdown"]');
|
if (!instance) {
|
||||||
if (parentToggle) {
|
instance = new bootstrap.Dropdown(parentToggle);
|
||||||
let instance = bootstrap.Dropdown.getInstance(parentToggle);
|
|
||||||
if (!instance) {
|
|
||||||
instance = new bootstrap.Dropdown(parentToggle);
|
|
||||||
}
|
|
||||||
instance.hide();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
instance.hide();
|
||||||
if (!isOpen) {
|
}
|
||||||
dropdownInstance.show();
|
|
||||||
setTimeout(() => searchInput.focus(), 150);
|
|
||||||
} else {
|
|
||||||
dropdownInstance.hide();
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
if (!isOpen) {
|
||||||
|
dropdownInstance.show();
|
||||||
|
setTimeout(() => searchInput.focus(), 150);
|
||||||
|
} else {
|
||||||
|
dropdownInstance.hide();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Hide dropdown if it's open and user clicks outside
|
// Hide dropdown if it's open and user clicks outside
|
||||||
document.addEventListener('click', function(e) {
|
document.addEventListener('click', function (e) {
|
||||||
if (!searchDropdown.contains(e.target) && dropdownMenu.classList.contains('show')) {
|
if (!searchDropdown.contains(e.target) && dropdownMenu.classList.contains('show')) {
|
||||||
dropdownInstance.hide();
|
dropdownInstance.hide();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Keep dropdown open if search input is clicked
|
// Keep dropdown open if search input is clicked
|
||||||
searchInput.addEventListener('click', function (e) {
|
searchInput.addEventListener('click', function (e) {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
});
|
||||||
|
@ -57,7 +57,7 @@ repositories {
|
|||||||
|
|
||||||
allprojects {
|
allprojects {
|
||||||
group = 'stirling.software'
|
group = 'stirling.software'
|
||||||
version = '1.1.0'
|
version = '1.1.1'
|
||||||
|
|
||||||
configurations.configureEach {
|
configurations.configureEach {
|
||||||
exclude group: 'commons-logging', module: 'commons-logging'
|
exclude group: 'commons-logging', module: 'commons-logging'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user