From 96e399a617122e64a1fcd23e9957d6c4038aa744 Mon Sep 17 00:00:00 2001 From: Anthony Stirling <77850077+Frooodle@users.noreply.github.com> Date: Sat, 10 Feb 2024 00:00:07 +0000 Subject: [PATCH] changing html and book labels --- .../software/SPDF/config/AppConfig.java | 11 ++---- .../SPDF/config/EndpointConfiguration.java | 10 +++--- .../SPDF/config/PostStartupProcesses.java | 16 +++------ .../ConvertBookToPDFController.java | 10 +++--- .../ConvertPDFToBookController.java | 10 +++--- .../web/ConverterWebController.java | 4 +-- .../SPDF/model/ApplicationProperties.java | 25 ++++--------- .../api/converters/HTMLToPdfRequest.java | 35 ------------------- src/main/resources/settings.yml.template | 3 +- 9 files changed, 32 insertions(+), 92 deletions(-) diff --git a/src/main/java/stirling/software/SPDF/config/AppConfig.java b/src/main/java/stirling/software/SPDF/config/AppConfig.java index c1a646ad..65e98b7f 100644 --- a/src/main/java/stirling/software/SPDF/config/AppConfig.java +++ b/src/main/java/stirling/software/SPDF/config/AppConfig.java @@ -77,16 +77,11 @@ public class AppConfig { return Files.exists(Paths.get("/.dockerenv")); } - @Bean(name = "bookFormatsInstalled") - public boolean bookFormatsInstalled() { - return applicationProperties.getSystem().getCustomApplications().isInstallBookFormats(); - } - - @Bean(name = "htmlFormatsInstalled") - public boolean htmlFormatsInstalled() { + @Bean(name = "bookAndHtmlFormatsInstalled") + public boolean bookAndHtmlFormatsInstalled() { return applicationProperties .getSystem() .getCustomApplications() - .isInstallAdvancedHtmlToPDF(); + .isInstallBookAndHtmlFormats(); } } diff --git a/src/main/java/stirling/software/SPDF/config/EndpointConfiguration.java b/src/main/java/stirling/software/SPDF/config/EndpointConfiguration.java index f1e328f9..f82c189f 100644 --- a/src/main/java/stirling/software/SPDF/config/EndpointConfiguration.java +++ b/src/main/java/stirling/software/SPDF/config/EndpointConfiguration.java @@ -16,7 +16,7 @@ import org.springframework.stereotype.Service; import stirling.software.SPDF.model.ApplicationProperties; @Service -@DependsOn({"bookFormatsInstalled"}) +@DependsOn({"bookAndHtmlFormatsInstalled"}) public class EndpointConfiguration { private static final Logger logger = LoggerFactory.getLogger(EndpointConfiguration.class); private Map endpointStatuses = new ConcurrentHashMap<>(); @@ -24,14 +24,14 @@ public class EndpointConfiguration { private final ApplicationProperties applicationProperties; - private boolean bookFormatsInstalled; + private boolean bookAndHtmlFormatsInstalled; @Autowired public EndpointConfiguration( ApplicationProperties applicationProperties, - @Qualifier("bookFormatsInstalled") boolean bookFormatsInstalled) { + @Qualifier("bookAndHtmlFormatsInstalled") boolean bookAndHtmlFormatsInstalled) { this.applicationProperties = applicationProperties; - this.bookFormatsInstalled = bookFormatsInstalled; + this.bookAndHtmlFormatsInstalled = bookAndHtmlFormatsInstalled; init(); processEnvironmentConfigs(); } @@ -229,7 +229,7 @@ public class EndpointConfiguration { private void processEnvironmentConfigs() { List endpointsToRemove = applicationProperties.getEndpoints().getToRemove(); List groupsToRemove = applicationProperties.getEndpoints().getGroupsToRemove(); - if (!bookFormatsInstalled) { + if (!bookAndHtmlFormatsInstalled) { groupsToRemove.add("Calibre"); } if (endpointsToRemove != null) { diff --git a/src/main/java/stirling/software/SPDF/config/PostStartupProcesses.java b/src/main/java/stirling/software/SPDF/config/PostStartupProcesses.java index e7b684ff..2041cf95 100644 --- a/src/main/java/stirling/software/SPDF/config/PostStartupProcesses.java +++ b/src/main/java/stirling/software/SPDF/config/PostStartupProcesses.java @@ -26,12 +26,8 @@ public class PostStartupProcesses { private boolean runningInDocker; @Autowired - @Qualifier("bookFormatsInstalled") - private boolean bookFormatsInstalled; - - @Autowired - @Qualifier("htmlFormatsInstalled") - private boolean htmlFormatsInstalled; + @Qualifier("bookAndHtmlFormatsInstalled") + private boolean bookAndHtmlFormatsInstalled; private static final Logger logger = LoggerFactory.getLogger(PostStartupProcesses.class); @@ -39,15 +35,11 @@ public class PostStartupProcesses { public void runInstallCommandBasedOnEnvironment() throws IOException, InterruptedException { List> commands = new ArrayList<>(); // Checking for DOCKER_INSTALL_BOOK_FORMATS environment variable - if (bookFormatsInstalled) { + if (bookAndHtmlFormatsInstalled) { List tmpList = new ArrayList<>(); tmpList = new ArrayList<>(); - tmpList.addAll(Arrays.asList("whoami")); - commands.add(tmpList); - - tmpList = new ArrayList<>(); - tmpList.addAll(Arrays.asList("id")); + tmpList.addAll(Arrays.asList("apk add --no-cache calibre")); commands.add(tmpList); } diff --git a/src/main/java/stirling/software/SPDF/controller/api/converters/ConvertBookToPDFController.java b/src/main/java/stirling/software/SPDF/controller/api/converters/ConvertBookToPDFController.java index 3cbc783c..05784a15 100644 --- a/src/main/java/stirling/software/SPDF/controller/api/converters/ConvertBookToPDFController.java +++ b/src/main/java/stirling/software/SPDF/controller/api/converters/ConvertBookToPDFController.java @@ -23,21 +23,21 @@ import stirling.software.SPDF.utils.WebResponseUtils; public class ConvertBookToPDFController { @Autowired - @Qualifier("bookFormatsInstalled") - private boolean bookFormatsInstalled; + @Qualifier("bookAndHtmlFormatsInstalled") + private boolean bookAndHtmlFormatsInstalled; @PostMapping(consumes = "multipart/form-data", value = "/book/pdf") @Operation( summary = "Convert a BOOK/comic (*.epub | *.mobi | *.azw3 | *.fb2 | *.txt | *.docx) to PDF", description = - "(Requires bookFormatsInstalled flag and Calibre installed) This endpoint takes an BOOK/comic (*.epub | *.mobi | *.azw3 | *.fb2 | *.txt | *.docx) input and converts it to PDF format.") + "(Requires bookAndHtmlFormatsInstalled flag and Calibre installed) This endpoint takes an BOOK/comic (*.epub | *.mobi | *.azw3 | *.fb2 | *.txt | *.docx) input and converts it to PDF format.") public ResponseEntity HtmlToPdf(@ModelAttribute GeneralFile request) throws Exception { MultipartFile fileInput = request.getFileInput(); - if (!bookFormatsInstalled) { + if (!bookAndHtmlFormatsInstalled) { throw new IllegalArgumentException( - "bookFormatsInstalled flag is False, this functionality is not avaiable"); + "bookAndHtmlFormatsInstalled flag is False, this functionality is not avaiable"); } if (fileInput == null) { diff --git a/src/main/java/stirling/software/SPDF/controller/api/converters/ConvertPDFToBookController.java b/src/main/java/stirling/software/SPDF/controller/api/converters/ConvertPDFToBookController.java index c9171305..28793d48 100644 --- a/src/main/java/stirling/software/SPDF/controller/api/converters/ConvertPDFToBookController.java +++ b/src/main/java/stirling/software/SPDF/controller/api/converters/ConvertPDFToBookController.java @@ -30,22 +30,22 @@ import stirling.software.SPDF.utils.WebResponseUtils; public class ConvertPDFToBookController { @Autowired - @Qualifier("bookFormatsInstalled") - private boolean bookFormatsInstalled; + @Qualifier("bookAndHtmlFormatsInstalled") + private boolean bookAndHtmlFormatsInstalled; @PostMapping(consumes = "multipart/form-data", value = "/pdf/book") @Operation( summary = "Convert a PDF to a Book/comic (*.epub | *.mobi | *.azw3 | *.fb2 | *.txt | *.docx .. (others to include by chatgpt) to PDF", description = - "(Requires bookFormatsInstalled flag and Calibre installed) This endpoint Convert a PDF to a Book/comic (*.epub | *.mobi | *.azw3 | *.fb2 | *.txt | *.docx .. (others to include by chatgpt) to PDF") + "(Requires bookAndHtmlFormatsInstalled flag and Calibre installed) This endpoint Convert a PDF to a Book/comic (*.epub | *.mobi | *.azw3 | *.fb2 | *.txt | *.docx .. (others to include by chatgpt) to PDF") public ResponseEntity HtmlToPdf(@ModelAttribute PdfToBookRequest request) throws Exception { MultipartFile fileInput = request.getFileInput(); - if (!bookFormatsInstalled) { + if (!bookAndHtmlFormatsInstalled) { throw new IllegalArgumentException( - "bookFormatsInstalled flag is False, this functionality is not avaiable"); + "bookAndHtmlFormatsInstalled flag is False, this functionality is not avaiable"); } if (fileInput == null) { diff --git a/src/main/java/stirling/software/SPDF/controller/web/ConverterWebController.java b/src/main/java/stirling/software/SPDF/controller/web/ConverterWebController.java index 55ebcb91..23270df5 100644 --- a/src/main/java/stirling/software/SPDF/controller/web/ConverterWebController.java +++ b/src/main/java/stirling/software/SPDF/controller/web/ConverterWebController.java @@ -13,7 +13,7 @@ import io.swagger.v3.oas.annotations.tags.Tag; @Tag(name = "Convert", description = "Convert APIs") public class ConverterWebController { - @ConditionalOnExpression("#{bookFormatsInstalled}") + @ConditionalOnExpression("#{bookAndHtmlFormatsInstalled}") @GetMapping("/book-to-pdf") @Hidden public String convertBookToPdfForm(Model model) { @@ -21,7 +21,7 @@ public class ConverterWebController { return "convert/book-to-pdf"; } - @ConditionalOnExpression("#{bookFormatsInstalled}") + @ConditionalOnExpression("#{bookAndHtmlFormatsInstalled}") @GetMapping("/pdf-to-book") @Hidden public String convertPdfToBookForm(Model model) { diff --git a/src/main/java/stirling/software/SPDF/model/ApplicationProperties.java b/src/main/java/stirling/software/SPDF/model/ApplicationProperties.java index 3258d8b1..34c60bbe 100644 --- a/src/main/java/stirling/software/SPDF/model/ApplicationProperties.java +++ b/src/main/java/stirling/software/SPDF/model/ApplicationProperties.java @@ -290,31 +290,20 @@ public class ApplicationProperties { } public static class CustomApplications { - private boolean installBookFormats; - private boolean installAdvancedHtmlToPDF; + private boolean installBookAndHtmlFormats; - public boolean isInstallBookFormats() { - return installBookFormats; + public boolean isInstallBookAndHtmlFormats() { + return installBookAndHtmlFormats; } - public void setInstallBookFormats(boolean installBookFormats) { - this.installBookFormats = installBookFormats; - } - - public boolean isInstallAdvancedHtmlToPDF() { - return installAdvancedHtmlToPDF; - } - - public void setInstallAdvancedHtmlToPDF(boolean installAdvancedHtmlToPDF) { - this.installAdvancedHtmlToPDF = installAdvancedHtmlToPDF; + public void setInstallBookAndHtmlFormats(boolean installBookAndHtmlFormats) { + this.installBookAndHtmlFormats = installBookAndHtmlFormats; } @Override public String toString() { - return "CustomApplications [installBookFormats=" - + installBookFormats - + ", installAdvancedHtmlToPDF=" - + installAdvancedHtmlToPDF + return "CustomApplications [installBookAndHtmlFormats=" + + installBookAndHtmlFormats + "]"; } } diff --git a/src/main/java/stirling/software/SPDF/model/api/converters/HTMLToPdfRequest.java b/src/main/java/stirling/software/SPDF/model/api/converters/HTMLToPdfRequest.java index c778c36f..5f5ae051 100644 --- a/src/main/java/stirling/software/SPDF/model/api/converters/HTMLToPdfRequest.java +++ b/src/main/java/stirling/software/SPDF/model/api/converters/HTMLToPdfRequest.java @@ -14,39 +14,4 @@ public class HTMLToPdfRequest extends PDFFile { description = "Zoom level for displaying the website. Default is '1'.", defaultValue = "1") private float zoom; - - @Schema(description = "Width of the page in centimeters.") - private Float pageWidth; - - @Schema(description = "Height of the page in centimeters.") - private Float pageHeight; - - @Schema(description = "Top margin of the page in millimeters.") - private Float marginTop; - - @Schema(description = "Bottom margin of the page in millimeters.") - private Float marginBottom; - - @Schema(description = "Left margin of the page in millimeters.") - private Float marginLeft; - - @Schema(description = "Right margin of the page in millimeters.") - private Float marginRight; - - @Schema( - description = "Enable or disable rendering of website background.", - allowableValues = {"Yes", "No"}) - private String printBackground; - - @Schema( - description = - "Enable or disable the default header. The default header includes the name of the page on the left and the page number on the right.", - allowableValues = {"Yes", "No"}) - private String defaultHeader; - - @Schema( - description = "Change the CSS media type of the page. Defaults to 'print'.", - allowableValues = {"none", "print", "screen"}, - defaultValue = "print") - private String cssMediaType; } diff --git a/src/main/resources/settings.yml.template b/src/main/resources/settings.yml.template index 00c5998e..368a6a43 100644 --- a/src/main/resources/settings.yml.template +++ b/src/main/resources/settings.yml.template @@ -14,8 +14,7 @@ system: googlevisibility: false # 'true' to allow Google visibility (via robots.txt), 'false' to disallow enableAlphaFunctionality: false # Set to enable functionality which might need more testing before it fully goes live (This feature might make no changes) customApplications: - installBookFormats: false # Installs Calibre for book format conversion (For non docker it must be manually downloaded but will need to be true to show in UI) - installAdvancedHtmlToPDF: false # DO NOT USE EXTERNALLY, NOT SAFE! Install wkHtmlToPDF (For non docker it must be manually downloaded but will need to be true to show in UI) + installBookAndHtmlFormats: false # Installs Calibre for book format conversion (For non docker it must be manually downloaded but will need to be true to show in UI) #ui: # appName: exampleAppName # Application's visible name