diff --git a/booklore-api/src/main/java/org/booklore/BookloreApplication.java b/booklore-api/src/main/java/org/booklore/BookloreApplication.java index 2da72ddac..f2a9fd680 100644 --- a/booklore-api/src/main/java/org/booklore/BookloreApplication.java +++ b/booklore-api/src/main/java/org/booklore/BookloreApplication.java @@ -6,11 +6,12 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.EnableScheduling; +import org.booklore.config.AppProperties; import org.booklore.config.BookmarkProperties; @EnableScheduling @EnableAsync -@EnableConfigurationProperties(BookmarkProperties.class) +@EnableConfigurationProperties({AppProperties.class, BookmarkProperties.class}) @SpringBootApplication public class BookloreApplication { diff --git a/booklore-api/src/main/java/org/booklore/config/AppProperties.java b/booklore-api/src/main/java/org/booklore/config/AppProperties.java index 629b97199..ced784428 100644 --- a/booklore-api/src/main/java/org/booklore/config/AppProperties.java +++ b/booklore-api/src/main/java/org/booklore/config/AppProperties.java @@ -3,9 +3,7 @@ package org.booklore.config; import lombok.Getter; import lombok.Setter; import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.stereotype.Component; -@Component @ConfigurationProperties(prefix = "app") @Getter @Setter diff --git a/booklore-api/src/main/java/org/booklore/config/BeanConfig.java b/booklore-api/src/main/java/org/booklore/config/BeanConfig.java deleted file mode 100644 index 340697056..000000000 --- a/booklore-api/src/main/java/org/booklore/config/BeanConfig.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.booklore.config; - -import jakarta.annotation.PostConstruct; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.http.client.JdkClientHttpRequestFactory; -import org.springframework.web.client.RestTemplate; -import org.springframework.web.socket.config.WebSocketMessageBrokerStats; - -import java.net.http.HttpClient; -import java.time.Duration; - -@Configuration -public class BeanConfig { - - @Autowired - private WebSocketMessageBrokerStats webSocketMessageBrokerStats; - - @Bean - public RestTemplate restTemplate(HttpClient httpClient) { - JdkClientHttpRequestFactory factory = new JdkClientHttpRequestFactory(httpClient); - factory.setReadTimeout(Duration.ofSeconds(15)); - return new RestTemplate(factory); - } - - @PostConstruct - public void init() { - webSocketMessageBrokerStats.setLoggingPeriod(30 * 24 * 60 * 60 * 1000L); // 30 days - } - - -} diff --git a/booklore-api/src/main/java/org/booklore/config/BookmarkProperties.java b/booklore-api/src/main/java/org/booklore/config/BookmarkProperties.java index 5162bb4f1..42efe9051 100644 --- a/booklore-api/src/main/java/org/booklore/config/BookmarkProperties.java +++ b/booklore-api/src/main/java/org/booklore/config/BookmarkProperties.java @@ -2,9 +2,7 @@ package org.booklore.config; import lombok.Data; import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Configuration; -@Configuration @ConfigurationProperties(prefix = "bookmarks") @Data public class BookmarkProperties { diff --git a/booklore-api/src/main/java/org/booklore/config/MultipartConfig.java b/booklore-api/src/main/java/org/booklore/config/MultipartConfig.java deleted file mode 100644 index dfe25c93f..000000000 --- a/booklore-api/src/main/java/org/booklore/config/MultipartConfig.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.booklore.config; - -import jakarta.servlet.MultipartConfigElement; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.util.unit.DataSize; - -@Configuration -public class MultipartConfig { - - private static final long DEFAULT_MAX_UPLOAD_SIZE_MB = 1024; - - /** - * Provides a MultipartConfigElement with a generous default max upload size. - * The actual user-configured limit from app_settings is enforced at the service layer. - * This bean is created during servlet container initialization (before Flyway migrations run), - * so it must NOT query the database. - */ - @Bean - public MultipartConfigElement multipartConfigElement() { - long maxSizeBytes = DataSize.ofMegabytes(DEFAULT_MAX_UPLOAD_SIZE_MB).toBytes(); - return new MultipartConfigElement("", maxSizeBytes, maxSizeBytes, 0); - } -} diff --git a/booklore-api/src/main/java/org/booklore/config/RestClientConfig.java b/booklore-api/src/main/java/org/booklore/config/RestClientConfig.java index 6d0a37d53..34d3d1bb9 100644 --- a/booklore-api/src/main/java/org/booklore/config/RestClientConfig.java +++ b/booklore-api/src/main/java/org/booklore/config/RestClientConfig.java @@ -2,10 +2,13 @@ package org.booklore.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; +import org.springframework.http.client.JdkClientHttpRequestFactory; import org.springframework.http.client.SimpleClientHttpRequestFactory; import org.springframework.web.client.RestClient; import org.springframework.web.client.RestTemplate; +import java.net.http.HttpClient; import java.time.Duration; @Configuration @@ -17,6 +20,14 @@ public class RestClientConfig { .build(); } + @Bean + @Primary + public RestTemplate restTemplate(HttpClient httpClient) { + JdkClientHttpRequestFactory factory = new JdkClientHttpRequestFactory(httpClient); + factory.setReadTimeout(Duration.ofSeconds(15)); + return new RestTemplate(factory); + } + @Bean public RestTemplate oidcRestTemplate() { var factory = new SimpleClientHttpRequestFactory(); @@ -25,4 +36,3 @@ public class RestClientConfig { return new RestTemplate(factory); } } - diff --git a/booklore-api/src/main/java/org/booklore/config/TaskSchedulerConfig.java b/booklore-api/src/main/java/org/booklore/config/TaskSchedulerConfig.java index db7ff7f8a..cd3390457 100644 --- a/booklore-api/src/main/java/org/booklore/config/TaskSchedulerConfig.java +++ b/booklore-api/src/main/java/org/booklore/config/TaskSchedulerConfig.java @@ -6,10 +6,8 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.boot.context.event.ApplicationReadyEvent; import org.springframework.context.annotation.Configuration; import org.springframework.context.event.EventListener; -import org.springframework.scheduling.annotation.EnableScheduling; @Configuration -@EnableScheduling @AllArgsConstructor @Slf4j public class TaskSchedulerConfig { diff --git a/booklore-api/src/main/java/org/booklore/config/TransactionConfig.java b/booklore-api/src/main/java/org/booklore/config/TransactionConfig.java deleted file mode 100644 index d4cb13fc1..000000000 --- a/booklore-api/src/main/java/org/booklore/config/TransactionConfig.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.booklore.config; - -import jakarta.persistence.EntityManagerFactory; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.orm.jpa.JpaTransactionManager; -import org.springframework.transaction.PlatformTransactionManager; -import org.springframework.transaction.annotation.EnableTransactionManagement; - -@Configuration -@EnableTransactionManagement -public class TransactionConfig { - - @Bean - public PlatformTransactionManager transactionManager(EntityManagerFactory entityManagerFactory) { - JpaTransactionManager transactionManager = new JpaTransactionManager(); - transactionManager.setEntityManagerFactory(entityManagerFactory); - return transactionManager; - } -} diff --git a/booklore-api/src/main/java/org/booklore/config/WebSocketConfig.java b/booklore-api/src/main/java/org/booklore/config/WebSocketConfig.java index 66de8e272..5c057b4d5 100644 --- a/booklore-api/src/main/java/org/booklore/config/WebSocketConfig.java +++ b/booklore-api/src/main/java/org/booklore/config/WebSocketConfig.java @@ -2,13 +2,16 @@ package org.booklore.config; import org.booklore.config.security.interceptor.WebSocketAuthInterceptor; import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.context.event.ApplicationReadyEvent; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.context.event.EventListener; import org.springframework.core.env.Environment; import org.springframework.messaging.simp.config.ChannelRegistration; import org.springframework.messaging.simp.config.MessageBrokerRegistry; import org.springframework.scheduling.TaskScheduler; import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; +import org.springframework.web.socket.config.WebSocketMessageBrokerStats; import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker; import org.springframework.web.socket.config.annotation.StompEndpointRegistry; import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer; @@ -29,6 +32,12 @@ public class WebSocketConfig implements WebSocketMessageBrokerConfigurer { this.env = env; } + @EventListener(ApplicationReadyEvent.class) + public void suppressStatsLogging(ApplicationReadyEvent event) { + var stats = event.getApplicationContext().getBean(WebSocketMessageBrokerStats.class); + stats.setLoggingPeriod(30 * 24 * 60 * 60 * 1000L); // 30 days + } + @Override public void configureMessageBroker(MessageBrokerRegistry registry) { registry.enableSimpleBroker("/queue", "/topic") diff --git a/booklore-api/src/main/java/org/booklore/service/appsettings/SettingPersistenceHelper.java b/booklore-api/src/main/java/org/booklore/service/appsettings/SettingPersistenceHelper.java index 071edd1da..2262a69be 100644 --- a/booklore-api/src/main/java/org/booklore/service/appsettings/SettingPersistenceHelper.java +++ b/booklore-api/src/main/java/org/booklore/service/appsettings/SettingPersistenceHelper.java @@ -259,10 +259,16 @@ public class SettingPersistenceHelper { .maxFileSizeInMb(250) .build(); + MetadataPersistenceSettings.FormatSettings audiobookSettings = MetadataPersistenceSettings.FormatSettings.builder() + .enabled(false) + .maxFileSizeInMb(250) + .build(); + MetadataPersistenceSettings.SaveToOriginalFile saveToOriginalFile = MetadataPersistenceSettings.SaveToOriginalFile.builder() .epub(epubSettings) .pdf(pdfSettings) .cbx(cbxSettings) + .audiobook(audiobookSettings) .build(); return MetadataPersistenceSettings.builder() diff --git a/booklore-api/src/main/java/org/booklore/service/kobo/KepubConversionService.java b/booklore-api/src/main/java/org/booklore/service/kobo/KepubConversionService.java index 579f19320..3e88b06e8 100644 --- a/booklore-api/src/main/java/org/booklore/service/kobo/KepubConversionService.java +++ b/booklore-api/src/main/java/org/booklore/service/kobo/KepubConversionService.java @@ -1,8 +1,8 @@ package org.booklore.service.kobo; import org.booklore.util.FileService; +import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.io.*; @@ -11,10 +11,10 @@ import java.util.stream.Collectors; @Slf4j @Service +@RequiredArgsConstructor public class KepubConversionService { - @Autowired - private FileService fileService; + private final FileService fileService; public File convertEpubToKepub(File epubFile, File tempDir, boolean forceEnableHyphenation) throws IOException, InterruptedException { validateInputs(epubFile); diff --git a/booklore-api/src/main/java/org/booklore/service/metadata/parser/GoogleParser.java b/booklore-api/src/main/java/org/booklore/service/metadata/parser/GoogleParser.java index 83107b5d2..dae97c7b8 100644 --- a/booklore-api/src/main/java/org/booklore/service/metadata/parser/GoogleParser.java +++ b/booklore-api/src/main/java/org/booklore/service/metadata/parser/GoogleParser.java @@ -10,7 +10,6 @@ import org.booklore.model.enums.MetadataProvider; import org.booklore.service.appsettings.AppSettingService; import org.booklore.util.BookUtils; import org.jsoup.Jsoup; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.web.util.UriComponentsBuilder; import tools.jackson.databind.ObjectMapper; @@ -48,11 +47,6 @@ public class GoogleParser implements BookParser { private static final String GOOGLE_BOOKS_API_URL = "https://www.googleapis.com/books/v1/volumes"; private final AtomicLong lastRequestTime = new AtomicLong(0); - @Autowired - public GoogleParser(ObjectMapper objectMapper, AppSettingService appSettingService) { - this(objectMapper, appSettingService, HttpClient.newHttpClient()); - } - public GoogleParser(ObjectMapper objectMapper, AppSettingService appSettingService, HttpClient httpClient) { this.objectMapper = objectMapper; this.appSettingService = appSettingService; diff --git a/booklore-api/src/main/java/org/booklore/service/metadata/parser/hardcover/HardcoverBookSearchService.java b/booklore-api/src/main/java/org/booklore/service/metadata/parser/hardcover/HardcoverBookSearchService.java index af182efd6..fc1e592bc 100644 --- a/booklore-api/src/main/java/org/booklore/service/metadata/parser/hardcover/HardcoverBookSearchService.java +++ b/booklore-api/src/main/java/org/booklore/service/metadata/parser/hardcover/HardcoverBookSearchService.java @@ -2,7 +2,6 @@ package org.booklore.service.metadata.parser.hardcover; import org.booklore.service.appsettings.AppSettingService; import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.stereotype.Service; @@ -27,7 +26,6 @@ public class HardcoverBookSearchService { private final AtomicLong lastRequestTime = new AtomicLong(0); private final AtomicLong successCount = new AtomicLong(0); - @Autowired public HardcoverBookSearchService(AppSettingService appSettingService) { this.appSettingService = appSettingService; this.restClient = RestClient.builder() diff --git a/booklore-api/src/main/resources/application.yaml b/booklore-api/src/main/resources/application.yaml index 24958dd77..89c6e1591 100644 --- a/booklore-api/src/main/resources/application.yaml +++ b/booklore-api/src/main/resources/application.yaml @@ -43,7 +43,10 @@ spring: fail-on-null-for-primitives: false servlet: multipart: - enabled: false + enabled: true + max-file-size: 1024MB + max-request-size: 1024MB + file-size-threshold: 0 mvc: async: request-timeout: 600000