diff --git a/.github/labeler-config-srvaroa.yml b/.github/labeler-config-srvaroa.yml index bdc48da53..44a234e3b 100644 --- a/.github/labeler-config-srvaroa.yml +++ b/.github/labeler-config-srvaroa.yml @@ -76,8 +76,8 @@ labels: - 'app/core/src/main/resources/settings.yml.template' - 'app/core/src/main/resources/application.properties' - 'app/core/src/main/resources/banner.txt' - - 'scripts/png_to_webp.py' - - 'split_photos.py' + - 'app/core/src/main/resources/static/python/png_to_webp.py' + - 'app/core/src/main/resources/static/python/split_photos.py' - 'application.properties' - label: 'Security' @@ -95,8 +95,8 @@ labels: - 'app/core/src/main/java/stirling/software/SPDF/model/api/.*' - 'app/core/src/main/java/stirling/software/SPDF/service/ApiDocService.java' - 'app/proprietary/src/main/java/stirling/software/proprietary/security/controller/api/.*' - - 'scripts/png_to_webp.py' - - 'split_photos.py' + - 'app/core/src/main/resources/static/python/png_to_webp.py' + - 'app/core/src/main/resources/static/python/split_photos.py' - '.github/workflows/swagger.yml' - label: 'Documentation' diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 094e9b2fa..ec2d837e2 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -6,10 +6,10 @@ repos: args: - --fix - --line-length=127 - files: ^((\.github/scripts|scripts)/.+)?[^/]+\.py$ + files: ^((\.github/scripts|scripts|app/core/src/main/resources/static/python)/.+)?[^/]+\.py$ exclude: (split_photos.py) - id: ruff-format - files: ^((\.github/scripts|scripts)/.+)?[^/]+\.py$ + files: ^((\.github/scripts|scripts|app/core/src/main/resources/static/python)/.+)?[^/]+\.py$ exclude: (split_photos.py) - repo: https://github.com/codespell-project/codespell rev: v2.4.1 diff --git a/app/common/src/main/java/stirling/software/common/util/GeneralUtils.java b/app/common/src/main/java/stirling/software/common/util/GeneralUtils.java index ddbec92e0..4cbf3f84b 100644 --- a/app/common/src/main/java/stirling/software/common/util/GeneralUtils.java +++ b/app/common/src/main/java/stirling/software/common/util/GeneralUtils.java @@ -16,6 +16,7 @@ import java.util.List; import java.util.Locale; import java.util.UUID; +import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceLoader; import org.springframework.core.io.support.ResourcePatternUtils; @@ -442,6 +443,27 @@ public class GeneralUtils { } } + /** + * Extracts a file from classpath:/static/python to a temporary directory and returns the + * path. + */ + public static Path extractScript(String scriptName) throws IOException { + // 1. loade the script from classpath + ClassPathResource resource = new ClassPathResource("static/python/" + scriptName); + + // 2. create a temporary directory + Path tmpDir = Files.createTempDirectory("stirling-pdf-scripts"); + tmpDir.toFile().deleteOnExit(); + + // 3. Copy the file + Path scriptFile = tmpDir.resolve(scriptName); + try (InputStream in = resource.getInputStream()) { + Files.copy(in, scriptFile, StandardCopyOption.REPLACE_EXISTING); + } + + return scriptFile; + } + public static boolean isVersionHigher(String currentVersion, String compareVersion) { if (currentVersion == null || compareVersion == null) { return false; diff --git a/scripts/png_to_webp.py b/app/core/src/main/resources/static/python/png_to_webp.py similarity index 100% rename from scripts/png_to_webp.py rename to app/core/src/main/resources/static/python/png_to_webp.py diff --git a/scripts/split_photos.py b/app/core/src/main/resources/static/python/split_photos.py similarity index 100% rename from scripts/split_photos.py rename to app/core/src/main/resources/static/python/split_photos.py