diff --git a/src/main/java/stirling/software/SPDF/config/AppConfig.java b/src/main/java/stirling/software/SPDF/config/AppConfig.java index 326501cb..faf85b28 100644 --- a/src/main/java/stirling/software/SPDF/config/AppConfig.java +++ b/src/main/java/stirling/software/SPDF/config/AppConfig.java @@ -51,7 +51,6 @@ public class AppConfig { String appName = System.getProperty("rateLimit"); if (appName == null) appName = System.getenv("rateLimit"); - System.out.println("rateLimit=" + appName); return (appName != null) ? Boolean.valueOf(appName) : false; } diff --git a/src/main/java/stirling/software/SPDF/controller/api/converters/ConvertEpubToPdf.java b/src/main/java/stirling/software/SPDF/controller/api/converters/ConvertEpubToPdf.java deleted file mode 100644 index e821a36a..00000000 --- a/src/main/java/stirling/software/SPDF/controller/api/converters/ConvertEpubToPdf.java +++ /dev/null @@ -1,130 +0,0 @@ -package stirling.software.SPDF.controller.api.converters; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.StringReader; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.zip.ZipEntry; -import java.util.zip.ZipInputStream; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; - -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.ModelAttribute; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.multipart.MultipartFile; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.NodeList; -import org.xml.sax.InputSource; - -import io.swagger.v3.oas.annotations.Hidden; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.tags.Tag; -import stirling.software.SPDF.model.api.GeneralFile; -import stirling.software.SPDF.utils.FileToPdf; -import stirling.software.SPDF.utils.WebResponseUtils; - -@RestController -@RequestMapping("/api/v1/convert") -@Tag(name = "Convert", description = "Convert APIs") -public class ConvertEpubToPdf { - //TODO - @PostMapping(consumes = "multipart/form-data", value = "/epub-to-single-pdf") - @Hidden - @Operation( - summary = "Convert an EPUB file to a single PDF", - description = "This endpoint takes an EPUB file input and converts it to a single PDF." - ) - public ResponseEntity epubToSinglePdf( - @ModelAttribute GeneralFile request) - throws Exception { - MultipartFile fileInput = request.getFileInput(); - if (fileInput == null) { - throw new IllegalArgumentException("Please provide an EPUB file for conversion."); - } - - String originalFilename = fileInput.getOriginalFilename(); - if (originalFilename == null || !originalFilename.endsWith(".epub")) { - throw new IllegalArgumentException("File must be in .epub format."); - } - - Map epubContents = extractEpubContent(fileInput); - List htmlFilesOrder = getHtmlFilesOrderFromOpf(epubContents); - - List individualPdfs = new ArrayList<>(); - - for (String htmlFile : htmlFilesOrder) { - byte[] htmlContent = epubContents.get(htmlFile); - byte[] pdfBytes = FileToPdf.convertHtmlToPdf(htmlContent, htmlFile.replace(".html", ".pdf")); - individualPdfs.add(pdfBytes); - } - - // Pseudo-code to merge individual PDFs into one. - byte[] mergedPdfBytes = mergeMultiplePdfsIntoOne(individualPdfs); - - return WebResponseUtils.bytesToWebResponse(mergedPdfBytes, originalFilename.replace(".epub", ".pdf")); - } - - // Assuming a pseudo-code function that merges multiple PDFs into one. - private byte[] mergeMultiplePdfsIntoOne(List individualPdfs) { - // You can use a library such as PDFBox to perform the merging here. - // Return the byte[] of the merged PDF. - return null; - } - - private Map extractEpubContent(MultipartFile fileInput) throws IOException { - Map contentMap = new HashMap<>(); - - try (ZipInputStream zis = new ZipInputStream(fileInput.getInputStream())) { - ZipEntry zipEntry = zis.getNextEntry(); - while (zipEntry != null) { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - byte[] buffer = new byte[1024]; - int read = 0; - while ((read = zis.read(buffer)) != -1) { - baos.write(buffer, 0, read); - } - contentMap.put(zipEntry.getName(), baos.toByteArray()); - zipEntry = zis.getNextEntry(); - } - } - - return contentMap; - } - - private List getHtmlFilesOrderFromOpf(Map epubContents) throws Exception { - String opfContent = new String(epubContents.get("OEBPS/content.opf")); // Adjusting for given path - DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); - DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); - InputSource is = new InputSource(new StringReader(opfContent)); - Document doc = dBuilder.parse(is); - - NodeList itemRefs = doc.getElementsByTagName("itemref"); - List htmlFilesOrder = new ArrayList<>(); - - for (int i = 0; i < itemRefs.getLength(); i++) { - Element itemRef = (Element) itemRefs.item(i); - String idref = itemRef.getAttribute("idref"); - - NodeList items = doc.getElementsByTagName("item"); - for (int j = 0; j < items.getLength(); j++) { - Element item = (Element) items.item(j); - if (idref.equals(item.getAttribute("id"))) { - htmlFilesOrder.add(item.getAttribute("href")); // Fetching the actual href - break; - } - } - } - - return htmlFilesOrder; - } - - -} diff --git a/src/main/resources/banner.txt b/src/main/resources/banner.txt new file mode 100644 index 00000000..e3188c2a --- /dev/null +++ b/src/main/resources/banner.txt @@ -0,0 +1,6 @@ + ____ _____ ___ ____ _ ___ _ _ ____ ____ ____ _____ +/ ___|_ _|_ _| _ \| | |_ _| \ | |/ ___| | _ \| _ \| ___| +\___ \ | | | || |_) | | | || \| | | _ _____| |_) | | | | |_ + ___) || | | || _ <| |___ | || |\ | |_| |_____| __/| |_| | _| +|____/ |_| |___|_| \_\_____|___|_| \_|\____| |_| |____/|_| +Powered by Spring Boot ${spring-boot.version} \ No newline at end of file