diff --git a/app/common/src/main/java/stirling/software/common/service/CustomPDFDocumentFactory.java b/app/common/src/main/java/stirling/software/common/service/CustomPDFDocumentFactory.java index 8d7419eb7..4e2b4c789 100644 --- a/app/common/src/main/java/stirling/software/common/service/CustomPDFDocumentFactory.java +++ b/app/common/src/main/java/stirling/software/common/service/CustomPDFDocumentFactory.java @@ -478,11 +478,6 @@ public class CustomPDFDocumentFactory { return file; } - /** Create a uniquely named temporary directory */ - private Path createTempDirectory(String prefix) throws IOException { - return Files.createTempDirectory(prefix + tempCounter.incrementAndGet() + "-"); - } - /** Create new document bytes based on an existing document */ public byte[] createNewBytesBasedOnOldDocument(byte[] oldDocument) throws IOException { try (PDDocument document = load(oldDocument)) { diff --git a/app/common/src/main/java/stirling/software/common/util/FileToPdf.java b/app/common/src/main/java/stirling/software/common/util/FileToPdf.java index 30a478294..6e0fec08e 100644 --- a/app/common/src/main/java/stirling/software/common/util/FileToPdf.java +++ b/app/common/src/main/java/stirling/software/common/util/FileToPdf.java @@ -5,11 +5,8 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.UncheckedIOException; import java.nio.charset.StandardCharsets; -import java.nio.file.FileVisitResult; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.SimpleFileVisitor; -import java.nio.file.attribute.BasicFileAttributes; import java.util.ArrayList; import java.util.List; import java.util.Locale; @@ -148,64 +145,6 @@ public class FileToPdf { } } - private static void deleteDirectory(Path dir) throws IOException { - Files.walkFileTree( - dir, - new SimpleFileVisitor() { - @Override - public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) - throws IOException { - Files.delete(file); - return FileVisitResult.CONTINUE; - } - - @Override - public FileVisitResult postVisitDirectory(Path dir, IOException exc) - throws IOException { - Files.delete(dir); - return FileVisitResult.CONTINUE; - } - }); - } - - private static Path unzipAndGetMainHtml(byte[] fileBytes) throws IOException { - Path tempDirectory = Files.createTempDirectory("unzipped_"); - try (ZipInputStream zipIn = - ZipSecurity.createHardenedInputStream(new ByteArrayInputStream(fileBytes))) { - ZipEntry entry = zipIn.getNextEntry(); - while (entry != null) { - Path filePath = tempDirectory.resolve(sanitizeZipFilename(entry.getName())); - if (entry.isDirectory()) { - Files.createDirectories(filePath); // Explicitly create the directory structure - } else { - Files.createDirectories( - filePath.getParent()); // Create parent directories if they don't exist - Files.copy(zipIn, filePath); - } - zipIn.closeEntry(); - entry = zipIn.getNextEntry(); - } - } - - // Search for the main HTML file. - try (Stream walk = Files.walk(tempDirectory)) { - List htmlFiles = walk.filter(file -> file.toString().endsWith(".html")).toList(); - - if (htmlFiles.isEmpty()) { - throw new IOException("No HTML files found in the unzipped directory."); - } - - // Prioritize 'index.html' if it exists, otherwise use the first .html file - for (Path htmlFile : htmlFiles) { - if ("index.html".equals(htmlFile.getFileName().toString())) { - return htmlFile; - } - } - - return htmlFiles.get(0); - } - } - static String sanitizeZipFilename(String entryName) { if (entryName == null || entryName.trim().isEmpty()) { return ""; 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 874417990..1379b7459 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 @@ -94,32 +94,6 @@ public class GeneralUtils { return tempFile; } - /* - * Gets the configured temporary directory, creating it if necessary. - * - * @return Path to the temporary directory - * @throws IOException if directory creation fails - */ - private Path getTempDirectory() throws IOException { - String customTempDir = System.getenv("STIRLING_TEMPFILES_DIRECTORY"); - if (customTempDir == null || customTempDir.isEmpty()) { - customTempDir = System.getProperty("stirling.tempfiles.directory"); - } - - Path tempDir; - if (customTempDir != null && !customTempDir.isEmpty()) { - tempDir = Path.of(customTempDir); - } else { - tempDir = Path.of(System.getProperty("java.io.tmpdir"), "stirling-pdf"); - } - - if (!Files.exists(tempDir)) { - Files.createDirectories(tempDir); - } - - return tempDir; - } - /* * Remove file extension *