changing html and book labels

This commit is contained in:
Anthony Stirling 2024-02-10 00:00:07 +00:00
parent 22343e507d
commit 96e399a617
9 changed files with 32 additions and 92 deletions

View File

@ -77,16 +77,11 @@ public class AppConfig {
return Files.exists(Paths.get("/.dockerenv")); return Files.exists(Paths.get("/.dockerenv"));
} }
@Bean(name = "bookFormatsInstalled") @Bean(name = "bookAndHtmlFormatsInstalled")
public boolean bookFormatsInstalled() { public boolean bookAndHtmlFormatsInstalled() {
return applicationProperties.getSystem().getCustomApplications().isInstallBookFormats();
}
@Bean(name = "htmlFormatsInstalled")
public boolean htmlFormatsInstalled() {
return applicationProperties return applicationProperties
.getSystem() .getSystem()
.getCustomApplications() .getCustomApplications()
.isInstallAdvancedHtmlToPDF(); .isInstallBookAndHtmlFormats();
} }
} }

View File

@ -16,7 +16,7 @@ import org.springframework.stereotype.Service;
import stirling.software.SPDF.model.ApplicationProperties; import stirling.software.SPDF.model.ApplicationProperties;
@Service @Service
@DependsOn({"bookFormatsInstalled"}) @DependsOn({"bookAndHtmlFormatsInstalled"})
public class EndpointConfiguration { public class EndpointConfiguration {
private static final Logger logger = LoggerFactory.getLogger(EndpointConfiguration.class); private static final Logger logger = LoggerFactory.getLogger(EndpointConfiguration.class);
private Map<String, Boolean> endpointStatuses = new ConcurrentHashMap<>(); private Map<String, Boolean> endpointStatuses = new ConcurrentHashMap<>();
@ -24,14 +24,14 @@ public class EndpointConfiguration {
private final ApplicationProperties applicationProperties; private final ApplicationProperties applicationProperties;
private boolean bookFormatsInstalled; private boolean bookAndHtmlFormatsInstalled;
@Autowired @Autowired
public EndpointConfiguration( public EndpointConfiguration(
ApplicationProperties applicationProperties, ApplicationProperties applicationProperties,
@Qualifier("bookFormatsInstalled") boolean bookFormatsInstalled) { @Qualifier("bookAndHtmlFormatsInstalled") boolean bookAndHtmlFormatsInstalled) {
this.applicationProperties = applicationProperties; this.applicationProperties = applicationProperties;
this.bookFormatsInstalled = bookFormatsInstalled; this.bookAndHtmlFormatsInstalled = bookAndHtmlFormatsInstalled;
init(); init();
processEnvironmentConfigs(); processEnvironmentConfigs();
} }
@ -229,7 +229,7 @@ public class EndpointConfiguration {
private void processEnvironmentConfigs() { private void processEnvironmentConfigs() {
List<String> endpointsToRemove = applicationProperties.getEndpoints().getToRemove(); List<String> endpointsToRemove = applicationProperties.getEndpoints().getToRemove();
List<String> groupsToRemove = applicationProperties.getEndpoints().getGroupsToRemove(); List<String> groupsToRemove = applicationProperties.getEndpoints().getGroupsToRemove();
if (!bookFormatsInstalled) { if (!bookAndHtmlFormatsInstalled) {
groupsToRemove.add("Calibre"); groupsToRemove.add("Calibre");
} }
if (endpointsToRemove != null) { if (endpointsToRemove != null) {

View File

@ -26,12 +26,8 @@ public class PostStartupProcesses {
private boolean runningInDocker; private boolean runningInDocker;
@Autowired @Autowired
@Qualifier("bookFormatsInstalled") @Qualifier("bookAndHtmlFormatsInstalled")
private boolean bookFormatsInstalled; private boolean bookAndHtmlFormatsInstalled;
@Autowired
@Qualifier("htmlFormatsInstalled")
private boolean htmlFormatsInstalled;
private static final Logger logger = LoggerFactory.getLogger(PostStartupProcesses.class); private static final Logger logger = LoggerFactory.getLogger(PostStartupProcesses.class);
@ -39,15 +35,11 @@ public class PostStartupProcesses {
public void runInstallCommandBasedOnEnvironment() throws IOException, InterruptedException { public void runInstallCommandBasedOnEnvironment() throws IOException, InterruptedException {
List<List<String>> commands = new ArrayList<>(); List<List<String>> commands = new ArrayList<>();
// Checking for DOCKER_INSTALL_BOOK_FORMATS environment variable // Checking for DOCKER_INSTALL_BOOK_FORMATS environment variable
if (bookFormatsInstalled) { if (bookAndHtmlFormatsInstalled) {
List<String> tmpList = new ArrayList<>(); List<String> tmpList = new ArrayList<>();
tmpList = new ArrayList<>(); tmpList = new ArrayList<>();
tmpList.addAll(Arrays.asList("whoami")); tmpList.addAll(Arrays.asList("apk add --no-cache calibre"));
commands.add(tmpList);
tmpList = new ArrayList<>();
tmpList.addAll(Arrays.asList("id"));
commands.add(tmpList); commands.add(tmpList);
} }

View File

@ -23,21 +23,21 @@ import stirling.software.SPDF.utils.WebResponseUtils;
public class ConvertBookToPDFController { public class ConvertBookToPDFController {
@Autowired @Autowired
@Qualifier("bookFormatsInstalled") @Qualifier("bookAndHtmlFormatsInstalled")
private boolean bookFormatsInstalled; private boolean bookAndHtmlFormatsInstalled;
@PostMapping(consumes = "multipart/form-data", value = "/book/pdf") @PostMapping(consumes = "multipart/form-data", value = "/book/pdf")
@Operation( @Operation(
summary = summary =
"Convert a BOOK/comic (*.epub | *.mobi | *.azw3 | *.fb2 | *.txt | *.docx) to PDF", "Convert a BOOK/comic (*.epub | *.mobi | *.azw3 | *.fb2 | *.txt | *.docx) to PDF",
description = 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<byte[]> HtmlToPdf(@ModelAttribute GeneralFile request) throws Exception { public ResponseEntity<byte[]> HtmlToPdf(@ModelAttribute GeneralFile request) throws Exception {
MultipartFile fileInput = request.getFileInput(); MultipartFile fileInput = request.getFileInput();
if (!bookFormatsInstalled) { if (!bookAndHtmlFormatsInstalled) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"bookFormatsInstalled flag is False, this functionality is not avaiable"); "bookAndHtmlFormatsInstalled flag is False, this functionality is not avaiable");
} }
if (fileInput == null) { if (fileInput == null) {

View File

@ -30,22 +30,22 @@ import stirling.software.SPDF.utils.WebResponseUtils;
public class ConvertPDFToBookController { public class ConvertPDFToBookController {
@Autowired @Autowired
@Qualifier("bookFormatsInstalled") @Qualifier("bookAndHtmlFormatsInstalled")
private boolean bookFormatsInstalled; private boolean bookAndHtmlFormatsInstalled;
@PostMapping(consumes = "multipart/form-data", value = "/pdf/book") @PostMapping(consumes = "multipart/form-data", value = "/pdf/book")
@Operation( @Operation(
summary = summary =
"Convert a PDF to a Book/comic (*.epub | *.mobi | *.azw3 | *.fb2 | *.txt | *.docx .. (others to include by chatgpt) to PDF", "Convert a PDF to a Book/comic (*.epub | *.mobi | *.azw3 | *.fb2 | *.txt | *.docx .. (others to include by chatgpt) to PDF",
description = 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<byte[]> HtmlToPdf(@ModelAttribute PdfToBookRequest request) public ResponseEntity<byte[]> HtmlToPdf(@ModelAttribute PdfToBookRequest request)
throws Exception { throws Exception {
MultipartFile fileInput = request.getFileInput(); MultipartFile fileInput = request.getFileInput();
if (!bookFormatsInstalled) { if (!bookAndHtmlFormatsInstalled) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"bookFormatsInstalled flag is False, this functionality is not avaiable"); "bookAndHtmlFormatsInstalled flag is False, this functionality is not avaiable");
} }
if (fileInput == null) { if (fileInput == null) {

View File

@ -13,7 +13,7 @@ import io.swagger.v3.oas.annotations.tags.Tag;
@Tag(name = "Convert", description = "Convert APIs") @Tag(name = "Convert", description = "Convert APIs")
public class ConverterWebController { public class ConverterWebController {
@ConditionalOnExpression("#{bookFormatsInstalled}") @ConditionalOnExpression("#{bookAndHtmlFormatsInstalled}")
@GetMapping("/book-to-pdf") @GetMapping("/book-to-pdf")
@Hidden @Hidden
public String convertBookToPdfForm(Model model) { public String convertBookToPdfForm(Model model) {
@ -21,7 +21,7 @@ public class ConverterWebController {
return "convert/book-to-pdf"; return "convert/book-to-pdf";
} }
@ConditionalOnExpression("#{bookFormatsInstalled}") @ConditionalOnExpression("#{bookAndHtmlFormatsInstalled}")
@GetMapping("/pdf-to-book") @GetMapping("/pdf-to-book")
@Hidden @Hidden
public String convertPdfToBookForm(Model model) { public String convertPdfToBookForm(Model model) {

View File

@ -290,31 +290,20 @@ public class ApplicationProperties {
} }
public static class CustomApplications { public static class CustomApplications {
private boolean installBookFormats; private boolean installBookAndHtmlFormats;
private boolean installAdvancedHtmlToPDF;
public boolean isInstallBookFormats() { public boolean isInstallBookAndHtmlFormats() {
return installBookFormats; return installBookAndHtmlFormats;
} }
public void setInstallBookFormats(boolean installBookFormats) { public void setInstallBookAndHtmlFormats(boolean installBookAndHtmlFormats) {
this.installBookFormats = installBookFormats; this.installBookAndHtmlFormats = installBookAndHtmlFormats;
}
public boolean isInstallAdvancedHtmlToPDF() {
return installAdvancedHtmlToPDF;
}
public void setInstallAdvancedHtmlToPDF(boolean installAdvancedHtmlToPDF) {
this.installAdvancedHtmlToPDF = installAdvancedHtmlToPDF;
} }
@Override @Override
public String toString() { public String toString() {
return "CustomApplications [installBookFormats=" return "CustomApplications [installBookAndHtmlFormats="
+ installBookFormats + installBookAndHtmlFormats
+ ", installAdvancedHtmlToPDF="
+ installAdvancedHtmlToPDF
+ "]"; + "]";
} }
} }

View File

@ -14,39 +14,4 @@ public class HTMLToPdfRequest extends PDFFile {
description = "Zoom level for displaying the website. Default is '1'.", description = "Zoom level for displaying the website. Default is '1'.",
defaultValue = "1") defaultValue = "1")
private float zoom; 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;
} }

View File

@ -14,8 +14,7 @@ system:
googlevisibility: false # 'true' to allow Google visibility (via robots.txt), 'false' to disallow 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) enableAlphaFunctionality: false # Set to enable functionality which might need more testing before it fully goes live (This feature might make no changes)
customApplications: 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) 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)
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)
#ui: #ui:
# appName: exampleAppName # Application's visible name # appName: exampleAppName # Application's visible name