diff --git a/common/src/main/java/stirling/software/common/util/TempFileNamingConvention.java b/common/src/main/java/stirling/software/common/util/TempFileNamingConvention.java deleted file mode 100644 index f0ba2890d..000000000 --- a/common/src/main/java/stirling/software/common/util/TempFileNamingConvention.java +++ /dev/null @@ -1,82 +0,0 @@ -package stirling.software.common.util; - -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; -import java.util.UUID; - -/** - * Utility class for generating consistent temporary file names. Provides methods to create - * standardized, identifiable temp file names. - */ -public class TempFileNamingConvention { - - private static final String DEFAULT_PREFIX = "stirling-pdf-"; - private static final DateTimeFormatter DATE_FORMATTER = - DateTimeFormatter.ofPattern("yyyyMMdd-HHmmss"); - - /** - * Create a temporary file name for a specific operation type. - * - * @param operationType The type of operation (e.g., "merge", "split", "watermark") - * @param extension File extension without the dot - * @return A formatted temporary file name - */ - public static String forOperation(String operationType, String extension) { - String timestamp = LocalDateTime.now().format(DATE_FORMATTER); - String uuid = UUID.randomUUID().toString().substring(0, 8); - - return DEFAULT_PREFIX + operationType + "-" + timestamp + "-" + uuid + "." + extension; - } - - /** - * Create a temporary file name for intermediate processing. - * - * @param operationType The type of operation - * @param step The processing step number or identifier - * @param extension File extension without the dot - * @return A formatted temporary file name for intermediate processing - */ - public static String forProcessingStep(String operationType, String step, String extension) { - String uuid = UUID.randomUUID().toString().substring(0, 8); - return DEFAULT_PREFIX + operationType + "-" + step + "-" + uuid + "." + extension; - } - - /** - * Create a temporary file name for a LibreOffice operation. - * - * @param sourceFilename The original filename - * @param extension File extension without the dot - * @return A formatted temporary file name for LibreOffice operations - */ - public static String forLibreOffice(String sourceFilename, String extension) { - // Extract base filename without extension - String baseName = sourceFilename; - int lastDot = sourceFilename.lastIndexOf('.'); - if (lastDot > 0) { - baseName = sourceFilename.substring(0, lastDot); - } - - // Sanitize the base name - baseName = baseName.replaceAll("[^a-zA-Z0-9]", "_"); - - // Limit the length of the base name - if (baseName.length() > 20) { - baseName = baseName.substring(0, 20); - } - - String uuid = UUID.randomUUID().toString().substring(0, 8); - return DEFAULT_PREFIX + "lo-" + baseName + "-" + uuid + "." + extension; - } - - /** - * Create a temporary directory name. - * - * @param purpose The purpose of the directory - * @return A formatted temporary directory name - */ - public static String forTempDirectory(String purpose) { - String timestamp = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")); - String uuid = UUID.randomUUID().toString().substring(0, 8); - return DEFAULT_PREFIX + purpose + "-" + timestamp + "-" + uuid; - } -} diff --git a/proprietary/src/main/java/stirling/software/proprietary/config/HttpRequestAuditPublisher.java b/proprietary/src/main/java/stirling/software/proprietary/config/HttpRequestAuditPublisher.java deleted file mode 100644 index 8b1378917..000000000 --- a/proprietary/src/main/java/stirling/software/proprietary/config/HttpRequestAuditPublisher.java +++ /dev/null @@ -1 +0,0 @@ - diff --git a/stirling-pdf/src/main/java/stirling/software/SPDF/UnoconvServer.java b/stirling-pdf/src/main/java/stirling/software/SPDF/UnoconvServer.java deleted file mode 100644 index 37d27530a..000000000 --- a/stirling-pdf/src/main/java/stirling/software/SPDF/UnoconvServer.java +++ /dev/null @@ -1,152 +0,0 @@ -package stirling.software.SPDF; - -import java.io.IOException; -import java.net.InetSocketAddress; -import java.net.Socket; -import java.nio.file.Path; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -import io.github.pixee.security.SystemCommand; - -import lombok.extern.slf4j.Slf4j; - -import stirling.software.common.service.TempFileCleanupService; -import stirling.software.common.util.ApplicationContextProvider; -import stirling.software.common.util.TempFileManager; - -@Slf4j -@Component -public class UnoconvServer { - - private static final long ACTIVITY_TIMEOUT = 20L * 60 * 1000; // 20 minutes - - private static UnoconvServer INSTANCE; - private static final int LISTENER_PORT = 2002; - private ExecutorService executorService; - private long lastActivityTime; - private Process process; - private Path tempDir; - - private final TempFileManager tempFileManager; - private final TempFileCleanupService cleanupService; - - @Autowired - public UnoconvServer(TempFileManager tempFileManager, TempFileCleanupService cleanupService) { - this.tempFileManager = tempFileManager; - this.cleanupService = cleanupService; - INSTANCE = this; - } - - public static UnoconvServer getInstance() { - // If INSTANCE is not set through Spring, try to get it from the ApplicationContext - if (INSTANCE == null) { - INSTANCE = ApplicationContextProvider.getBean(UnoconvServer.class); - - if (INSTANCE == null) { - log.warn("Creating UnoconvServer without Spring context"); - INSTANCE = new UnoconvServer(null, null); - } - } - return INSTANCE; - } - - private boolean isServerRunning() { - log.info("Checking if unoconv server is running"); - try (Socket socket = new Socket()) { - socket.connect( - new InetSocketAddress("localhost", LISTENER_PORT), - 1000); // Timeout after 1 second - return true; - } catch (Exception e) { - return false; - } - } - - public void start() throws IOException { - // Check if the server is already running - if (process != null && process.isAlive()) { - return; - } - - // Create and register a temp directory for unoconv if TempFileManager is available - if (tempFileManager != null) { - tempDir = tempFileManager.registerLibreOfficeTempDir(); - log.info("Created unoconv temp directory: {}", tempDir); - } - - String command; - if (tempDir != null) { - command = "unoconv-server --user-profile " + tempDir.toString(); - } else { - command = "unoconv-server"; - } - - // Start the server process - process = SystemCommand.runCommand(Runtime.getRuntime(), command); - lastActivityTime = System.currentTimeMillis(); - - // Start a background thread to monitor the activity timeout - executorService = Executors.newSingleThreadExecutor(); - executorService.submit( - () -> { - while (true) { - long idleTime = System.currentTimeMillis() - lastActivityTime; - if (idleTime >= ACTIVITY_TIMEOUT) { - process.destroy(); - - if (cleanupService != null) { - cleanupService.cleanupLibreOfficeTempFiles(); - } - break; - } - try { - Thread.sleep(5000); // Check for inactivity every 5 seconds - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - break; - } - } - }); - - // Wait for the server to start up - long startTime = System.currentTimeMillis(); - long timeout = 30000; // Timeout after 30 seconds - while (System.currentTimeMillis() - startTime < timeout) { - if (isServerRunning()) { - lastActivityTime = System.currentTimeMillis(); - return; - } - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - log.error("Error waiting for server to start", e); - } // Check every 1 second - } - } - - public synchronized void stop() { - // Stop the activity timeout monitor thread - if (executorService != null) { - executorService.shutdownNow(); - } - - // Stop the server process - if (process != null && process.isAlive()) { - process.destroy(); - } - - if (cleanupService != null) { - cleanupService.cleanupLibreOfficeTempFiles(); - } - } - - /** Notify that unoconv is being used, to reset the inactivity timer. */ - public void notifyActivity() { - lastActivityTime = System.currentTimeMillis(); - } -}