diff --git a/booklore-api/src/main/java/com/adityachandel/booklore/config/security/ImageCachingFilter.java b/booklore-api/src/main/java/com/adityachandel/booklore/config/security/ImageCachingFilter.java new file mode 100644 index 000000000..60011de41 --- /dev/null +++ b/booklore-api/src/main/java/com/adityachandel/booklore/config/security/ImageCachingFilter.java @@ -0,0 +1,26 @@ +package com.adityachandel.booklore.config.security; + +import jakarta.servlet.FilterChain; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import org.springframework.stereotype.Component; +import org.springframework.http.HttpHeaders; +import org.springframework.web.filter.OncePerRequestFilter; + +import java.io.IOException; + +@Component +public class ImageCachingFilter extends OncePerRequestFilter { + + @Override + protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { + + if (request.getRequestURI().startsWith("/api/v1/books") && request.getRequestURI().contains("/cover")) { + response.setHeader(HttpHeaders.CACHE_CONTROL, "public, max-age=3600"); + response.setHeader(HttpHeaders.EXPIRES, String.valueOf(System.currentTimeMillis() + 3600000)); + } + + filterChain.doFilter(request, response); + } +} diff --git a/booklore-api/src/main/java/com/adityachandel/booklore/config/security/SecurityConfig.java b/booklore-api/src/main/java/com/adityachandel/booklore/config/security/SecurityConfig.java index 84dbc4a14..929003358 100644 --- a/booklore-api/src/main/java/com/adityachandel/booklore/config/security/SecurityConfig.java +++ b/booklore-api/src/main/java/com/adityachandel/booklore/config/security/SecurityConfig.java @@ -1,6 +1,7 @@ package com.adityachandel.booklore.config.security; import lombok.AllArgsConstructor; +import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity; @@ -49,7 +50,7 @@ public class SecurityConfig { @Bean public CorsConfigurationSource corsConfigurationSource() { CorsConfiguration configuration = new CorsConfiguration(); - configuration.setAllowedOrigins(List.of("http://localhost:4200")); // Allow frontend origin + configuration.setAllowedOrigins(List.of("http://localhost:4200")); configuration.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE", "OPTIONS")); configuration.setAllowedHeaders(List.of("Authorization", "Cache-Control", "Content-Type")); configuration.setExposedHeaders(List.of("Content-Disposition")); @@ -59,4 +60,12 @@ public class SecurityConfig { source.registerCorsConfiguration("/**", configuration); return source; } + + @Bean + public FilterRegistrationBean loggingFilter() { + FilterRegistrationBean registrationBean = new FilterRegistrationBean<>(); + registrationBean.setFilter(new ImageCachingFilter()); + registrationBean.addUrlPatterns("/api/v1/books/*/cover"); + return registrationBean; + } } diff --git a/booklore-ui/src/app/book/components/book-browser/book-card/book-card.component.ts b/booklore-ui/src/app/book/components/book-browser/book-card/book-card.component.ts index aa26ac6df..d02b52385 100644 --- a/booklore-ui/src/app/book/components/book-browser/book-card/book-card.component.ts +++ b/booklore-ui/src/app/book/components/book-browser/book-card/book-card.component.ts @@ -13,15 +13,14 @@ import {MetadataFetchOptionsComponent} from '../../../../metadata/metadata-optio import {MetadataRefreshType} from '../../../../metadata/model/request/metadata-refresh-type.enum'; import {MetadataRefreshRequest} from '../../../../metadata/model/request/metadata-refresh-request.model'; import {UrlHelperService} from '../../../../utilities/service/url-helper.service'; -import {AsyncPipe, NgIf} from '@angular/common'; -import {SecurePipe} from '../../../../secure-pipe'; +import {NgIf} from '@angular/common'; import {UserService} from '../../../../user.service'; @Component({ selector: 'app-book-card', templateUrl: './book-card.component.html', styleUrls: ['./book-card.component.scss'], - imports: [Button, MenuModule, CheckboxModule, FormsModule, NgIf, SecurePipe, AsyncPipe], + imports: [Button, MenuModule, CheckboxModule, FormsModule, NgIf], standalone: true }) export class BookCardComponent implements OnInit { diff --git a/booklore-ui/src/app/book/components/book-browser/book-table/book-table.component.html b/booklore-ui/src/app/book/components/book-browser/book-table/book-table.component.html index 3d984b068..1bf5cbf15 100644 --- a/booklore-ui/src/app/book/components/book-browser/book-table/book-table.component.html +++ b/booklore-ui/src/app/book/components/book-browser/book-table/book-table.component.html @@ -35,7 +35,7 @@ - Book Cover + Book Cover {{ metadata.title }} {{ getAuthorNames(metadata.authors) }} diff --git a/booklore-ui/src/app/book/components/book-browser/book-table/book-table.component.ts b/booklore-ui/src/app/book/components/book-browser/book-table/book-table.component.ts index a049930b4..0bcf035cc 100644 --- a/booklore-ui/src/app/book/components/book-browser/book-table/book-table.component.ts +++ b/booklore-ui/src/app/book/components/book-browser/book-table/book-table.component.ts @@ -1,13 +1,12 @@ import {Component, EventEmitter, inject, Input, OnChanges, Output} from '@angular/core'; import {TableModule} from 'primeng/table'; -import {AsyncPipe, NgIf} from '@angular/common'; +import {NgIf} from '@angular/common'; import {Rating} from 'primeng/rating'; import {FormsModule} from '@angular/forms'; import {Book} from '../../../model/book.model'; import {SortOption} from '../../../model/sort.model'; import {MetadataDialogService} from '../../../../metadata/service/metadata-dialog.service'; import {UrlHelperService} from '../../../../utilities/service/url-helper.service'; -import {SecurePipe} from '../../../../secure-pipe'; @Component({ selector: 'app-book-table', @@ -17,9 +16,7 @@ import {SecurePipe} from '../../../../secure-pipe'; TableModule, NgIf, Rating, - FormsModule, - SecurePipe, - AsyncPipe + FormsModule ], styleUrl: './book-table.component.scss' }) diff --git a/booklore-ui/src/app/book/components/book-searcher/book-searcher.component.html b/booklore-ui/src/app/book/components/book-searcher/book-searcher.component.html index 76a7a3f2e..f059a3845 100644 --- a/booklore-ui/src/app/book/components/book-searcher/book-searcher.component.html +++ b/booklore-ui/src/app/book/components/book-searcher/book-searcher.component.html @@ -17,7 +17,7 @@
- Book Cover + Book Cover

{{ book.metadata?.title | slice:0:70 }}

diff --git a/booklore-ui/src/app/book/components/book-searcher/book-searcher.component.ts b/booklore-ui/src/app/book/components/book-searcher/book-searcher.component.ts index bea16a78b..5125cfcef 100644 --- a/booklore-ui/src/app/book/components/book-searcher/book-searcher.component.ts +++ b/booklore-ui/src/app/book/components/book-searcher/book-searcher.component.ts @@ -6,11 +6,10 @@ import {FormsModule} from '@angular/forms'; import {InputTextModule} from 'primeng/inputtext'; import {BookService} from '../../service/book.service'; import {Button} from 'primeng/button'; -import {AsyncPipe, NgForOf, NgIf, SlicePipe} from '@angular/common'; +import {NgForOf, NgIf, SlicePipe} from '@angular/common'; import {MetadataDialogService} from '../../../metadata/service/metadata-dialog.service'; import {Divider} from 'primeng/divider'; import {UrlHelperService} from '../../../utilities/service/url-helper.service'; -import {SecurePipe} from '../../../secure-pipe'; @Component({ selector: 'app-book-searcher', @@ -22,9 +21,7 @@ import {SecurePipe} from '../../../secure-pipe'; NgIf, NgForOf, SlicePipe, - Divider, - AsyncPipe, - SecurePipe + Divider ], styleUrls: ['./book-searcher.component.scss'], standalone: true diff --git a/booklore-ui/src/app/metadata/book-metadata-center/metadata-editor/metadata-editor.component.html b/booklore-ui/src/app/metadata/book-metadata-center/metadata-editor/metadata-editor.component.html index 6c733a0b6..ee2b6989c 100644 --- a/booklore-ui/src/app/metadata/book-metadata-center/metadata-editor/metadata-editor.component.html +++ b/booklore-ui/src/app/metadata/book-metadata-center/metadata-editor/metadata-editor.component.html @@ -10,7 +10,7 @@
Image
-