From 91bed18df2084212355965c5088acafb21257ebc Mon Sep 17 00:00:00 2001 From: Peter Dave Hello Date: Fri, 1 Aug 2025 06:57:09 +0800 Subject: [PATCH 1/3] Optimize Dockerfiles (#4069) # Description of Changes Summary from GitHub Copilot: > Optimize Dockerfiles > > This pull request includes updates to multiple Dockerfiles to improve efficiency, simplify permissions management, and enhance consistency across development environments. The most important changes involve optimizing `pip` installations, consolidating `chmod` commands, and removing redundant script permissions. > > ### Efficiency Improvements: > * Updated `pip install` commands in `Dockerfile`, `Dockerfile.dev`, and `Dockerfile.fat` to use the `--no-cache-dir` flag, reducing disk usage during package installations. [[1]](diffhunk://#diff-dd2c0eb6ea5cfc6c4bd4eac30934e2d5746747af48fef6da689e85b752f39557L81-R81) [[2]](diffhunk://#diff-86930c95a19b82f7e64a962a0053d44e855824813019b3698eae4917a90cdcacL39-R39) [[3]](diffhunk://#diff-571631582b988e88c52c86960cc083b0b8fa63cf88f056f26e9e684195221c27L94-R94) > > ### Permissions Management: > * Consolidated `chmod` commands for scripts in `Dockerfile.dev` to simplify permissions setup. Combined `git-init.sh` and `init-setup.sh` into a single command. > * Removed redundant `chmod +x` for `init.sh` in `Dockerfile` and `Dockerfile.fat`, as permissions for `/scripts/*` already cover this file. [[1]](diffhunk://#diff-dd2c0eb6ea5cfc6c4bd4eac30934e2d5746747af48fef6da689e85b752f39557L92) [[2]](diffhunk://#diff-571631582b988e88c52c86960cc083b0b8fa63cf88f056f26e9e684195221c27L105) --- ## Checklist ### General - [x] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [x] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md) (if applicable) - [ ] I have read the [How to add new languages to Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md) (if applicable) - [x] I have performed a self-review of my own code - [x] My changes generate no new warnings ### Documentation - [ ] I have updated relevant docs on [Stirling-PDF's doc repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/) (if functionality has heavily changed) - [ ] I have read the section [Add New Translation Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md#add-new-translation-tags) (for new translation tags only) ### UI Changes (if applicable) - [ ] Screenshots or videos demonstrating the UI changes are attached (e.g., as comments or direct attachments in the PR) ### Testing (if applicable) - [ ] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md#6-testing) for more details. --- Dockerfile | 3 +-- Dockerfile.dev | 5 ++--- Dockerfile.fat | 3 +-- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4ea6316ae..375ab94c1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -78,7 +78,7 @@ RUN echo "@main https://dl-cdn.alpinelinux.org/alpine/edge/main" | tee -a /etc/a # URW Base 35 fonts for better PDF rendering font-urw-base35 && \ python3 -m venv /opt/venv && \ - /opt/venv/bin/pip install --upgrade pip setuptools && \ + /opt/venv/bin/pip install --no-cache-dir --upgrade pip setuptools && \ /opt/venv/bin/pip install --no-cache-dir --upgrade unoserver weasyprint && \ ln -s /usr/lib/libreoffice/program/uno.py /opt/venv/lib/python3.12/site-packages/ && \ ln -s /usr/lib/libreoffice/program/unohelper.py /opt/venv/lib/python3.12/site-packages/ && \ @@ -89,7 +89,6 @@ RUN echo "@main https://dl-cdn.alpinelinux.org/alpine/edge/main" | tee -a /etc/a ln -s /usr/share/fontconfig/conf.avail/69-urw-*.conf /etc/fonts/conf.d/ && \ fc-cache -f -v && \ chmod +x /scripts/* && \ - chmod +x /scripts/init.sh && \ # User permissions addgroup -S stirlingpdfgroup && adduser -S stirlingpdfuser -G stirlingpdfgroup && \ chown -R stirlingpdfuser:stirlingpdfgroup $HOME /scripts /usr/share/fonts/opentype/noto /configs /customFiles /pipeline /tmp/stirling-pdf && \ diff --git a/Dockerfile.dev b/Dockerfile.dev index 78460115f..48084878d 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -36,7 +36,7 @@ ENV SETUPTOOLS_USE_DISTUTILS=local \ # Installation der benötigten Python-Pakete RUN python3 -m venv --system-site-packages /opt/venv \ && . /opt/venv/bin/activate \ - && pip install --upgrade pip setuptools \ + && pip install --no-cache-dir --upgrade pip setuptools \ && pip install --no-cache-dir WeasyPrint pdf2image pillow unoserver opencv-python-headless pre-commit # Füge den venv-Pfad zur globalen PATH-Variable hinzu, damit die Tools verfügbar sind @@ -54,8 +54,7 @@ RUN echo "devuser ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/devuser \ # Setze das Arbeitsverzeichnis (wird später per Bind-Mount überschrieben) WORKDIR /workspace -RUN chmod +x /workspace/.devcontainer/git-init.sh -RUN sudo chmod +x /workspace/.devcontainer/init-setup.sh +RUN chmod +x /workspace/.devcontainer/git-init.sh /workspace/.devcontainer/init-setup.sh # Wechsel zum Nicht‑Root Benutzer USER devuser diff --git a/Dockerfile.fat b/Dockerfile.fat index fd5964baf..fda3d89c4 100644 --- a/Dockerfile.fat +++ b/Dockerfile.fat @@ -91,7 +91,7 @@ RUN echo "@main https://dl-cdn.alpinelinux.org/alpine/edge/main" | tee -a /etc/a py3-pillow@testing \ py3-pdf2image@testing && \ python3 -m venv /opt/venv && \ - /opt/venv/bin/pip install --upgrade pip setuptools && \ + /opt/venv/bin/pip install --no-cache-dir --upgrade pip setuptools && \ /opt/venv/bin/pip install --no-cache-dir --upgrade unoserver weasyprint && \ ln -s /usr/lib/libreoffice/program/uno.py /opt/venv/lib/python3.12/site-packages/ && \ ln -s /usr/lib/libreoffice/program/unohelper.py /opt/venv/lib/python3.12/site-packages/ && \ @@ -102,7 +102,6 @@ RUN echo "@main https://dl-cdn.alpinelinux.org/alpine/edge/main" | tee -a /etc/a ln -s /usr/share/fontconfig/conf.avail/69-urw-*.conf /etc/fonts/conf.d/ && \ fc-cache -f -v && \ chmod +x /scripts/* && \ - chmod +x /scripts/init.sh && \ # User permissions addgroup -S stirlingpdfgroup && adduser -S stirlingpdfuser -G stirlingpdfgroup && \ chown -R stirlingpdfuser:stirlingpdfgroup $HOME /scripts /usr/share/fonts/opentype/noto /configs /customFiles /pipeline /tmp/stirling-pdf && \ From 6879d5fb7331f084411a43db346b9fe0985cb7d6 Mon Sep 17 00:00:00 2001 From: Lukas <38840142+lukasstorck@users.noreply.github.com> Date: Fri, 1 Aug 2025 00:58:31 +0200 Subject: [PATCH 2/3] fix: adjust margin of bookmark editor (#4068) # Description of Changes - remove overlapping margins of bookmark editor to the checkbox above - add bottom margin for the bookmark editor element to the "Info"-button below - I guess this simply was a typo `margin-top` vs. `margin-bottom` as the margin to the element above is overlapping --- ## Checklist ### General - [x] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [ ] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md) (if applicable) - [ ] I have read the [How to add new languages to Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md) (if applicable) - [x] I have performed a self-review of my own code - [x] My changes generate no new warnings ### Documentation - [ ] I have updated relevant docs on [Stirling-PDF's doc repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/) (if functionality has heavily changed) - [ ] I have read the section [Add New Translation Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md#add-new-translation-tags) (for new translation tags only) ### UI Changes (if applicable) - [x] Screenshots or videos demonstrating the UI changes are attached (e.g., as comments or direct attachments in the PR) *before / after*:

before edit with margin highlighted after edit with margin highlighted

before / after with margin highlighted:

before edit with margin highlighted after edit with margin highlighted

### Testing (if applicable) - [x] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md#6-testing) for more details. --- .../src/main/resources/static/css/edit-table-of-contents.css | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/core/src/main/resources/static/css/edit-table-of-contents.css b/app/core/src/main/resources/static/css/edit-table-of-contents.css index 11a4bf777..d85813a73 100644 --- a/app/core/src/main/resources/static/css/edit-table-of-contents.css +++ b/app/core/src/main/resources/static/css/edit-table-of-contents.css @@ -1,6 +1,6 @@ /* Main bookmark container styles */ .bookmark-editor { - margin-top: 20px; + margin-bottom: 20px; padding: 20px; border: 1px solid var(--border-color, #ced4da); border-radius: 0.25rem; @@ -273,4 +273,4 @@ --text-muted: var(--md-sys-color-on-surface-variant, #adb5bd); --bg-empty: var(--md-sys-color-surface-container-low, #24282e); --border-empty: var(--md-sys-color-outline, #495057); -} \ No newline at end of file +} From 422af007dc18b23512782f85c6615ddc4736aca5 Mon Sep 17 00:00:00 2001 From: Ludy Date: Fri, 1 Aug 2025 00:58:56 +0200 Subject: [PATCH 3/3] fix(pipeline): allow slashes in pipeline operation values (#4066) # Description of Changes - Extended the validation regex for `operation` in the pipeline processor to allow slashes (`/`), in addition to alphanumeric characters, underscores, and hyphens. - This resolves the issue where valid operation strings (e.g., with subpaths like `/api/v1/general/remove-pages`) were incorrectly rejected. - Added an explicit log message for better debugging in case of invalid `operation` values. --- ## Checklist ### General - [x] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [x] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md) (if applicable) - [ ] I have read the [How to add new languages to Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md) (if applicable) - [x] I have performed a self-review of my own code - [x] My changes generate no new warnings ### Documentation - [ ] I have updated relevant docs on [Stirling-PDF's doc repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/) (if functionality has heavily changed) - [ ] I have read the section [Add New Translation Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md#add-new-translation-tags) (for new translation tags only) ### UI Changes (if applicable) - [ ] Screenshots or videos demonstrating the UI changes are attached (e.g., as comments or direct attachments in the PR) ### Testing (if applicable) - [ ] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md#6-testing) for more details. --- .../api/pipeline/PipelineProcessor.java | 10 ++++++--- .../api/pipeline/PipelineProcessorTest.java | 21 +++++++++++-------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/app/core/src/main/java/stirling/software/SPDF/controller/api/pipeline/PipelineProcessor.java b/app/core/src/main/java/stirling/software/SPDF/controller/api/pipeline/PipelineProcessor.java index 44f2b892a..070d681e4 100644 --- a/app/core/src/main/java/stirling/software/SPDF/controller/api/pipeline/PipelineProcessor.java +++ b/app/core/src/main/java/stirling/software/SPDF/controller/api/pipeline/PipelineProcessor.java @@ -108,9 +108,13 @@ public class PipelineProcessor { if (inputFileTypes == null) { inputFileTypes = new ArrayList(Arrays.asList("ALL")); } - if (!operation.matches("^[a-zA-Z0-9_-]+$")) { - throw new IllegalArgumentException("Invalid operation value received."); + + if (!apiDocService.isValidOperation(operation, parameters)) { + log.error("Invalid operation or parameters: o:{} p:{}", operation, parameters); + throw new IllegalArgumentException( + "Invalid operation: " + operation + " with parameters: " + parameters); } + String url = getBaseUrl() + operation; List newOutputFiles = new ArrayList<>(); if (!isMultiInputOperation) { @@ -136,7 +140,7 @@ public class PipelineProcessor { // skip // this // file - if (operation.startsWith("filter-") + if (operation.startsWith("/api/v1/filter/filter-") && (response.getBody() == null || response.getBody().length == 0)) { filtersApplied = true; diff --git a/app/core/src/test/java/stirling/software/SPDF/controller/api/pipeline/PipelineProcessorTest.java b/app/core/src/test/java/stirling/software/SPDF/controller/api/pipeline/PipelineProcessorTest.java index 60e3f975d..0a40fcd5b 100644 --- a/app/core/src/test/java/stirling/software/SPDF/controller/api/pipeline/PipelineProcessorTest.java +++ b/app/core/src/test/java/stirling/software/SPDF/controller/api/pipeline/PipelineProcessorTest.java @@ -45,23 +45,26 @@ class PipelineProcessorTest { @Test void runPipelineWithFilterSetsFlag() throws Exception { PipelineOperation op = new PipelineOperation(); - op.setOperation("filter-page-count"); + op.setOperation("/api/v1/filter/filter-page-count"); op.setParameters(Map.of()); PipelineConfig config = new PipelineConfig(); config.setOperations(List.of(op)); - Resource file = new ByteArrayResource("data".getBytes()) { - @Override - public String getFilename() { - return "test.pdf"; - } - }; + Resource file = + new ByteArrayResource("data".getBytes()) { + @Override + public String getFilename() { + return "test.pdf"; + } + }; List files = List.of(file); - when(apiDocService.isMultiInput("filter-page-count")).thenReturn(false); - when(apiDocService.getExtensionTypes(false, "filter-page-count")) + when(apiDocService.isMultiInput("/api/v1/filter/filter-page-count")).thenReturn(false); + when(apiDocService.getExtensionTypes(false, "/api/v1/filter/filter-page-count")) .thenReturn(List.of("pdf")); + when(apiDocService.isValidOperation(eq("/api/v1/filter/filter-page-count"), anyMap())) + .thenReturn(true); doReturn(new ResponseEntity<>(new byte[0], HttpStatus.OK)) .when(pipelineProcessor)