This commit is contained in:
@@ -6,6 +6,7 @@ import org.booklore.mapper.BookMetadataMapper;
|
||||
import org.booklore.model.MetadataUpdateContext;
|
||||
import org.booklore.model.MetadataUpdateWrapper;
|
||||
import org.booklore.model.dto.BookMetadata;
|
||||
import org.booklore.model.dto.request.IsbnLookupRequest;
|
||||
import org.booklore.model.dto.request.*;
|
||||
import org.booklore.model.entity.BookEntity;
|
||||
import org.booklore.model.enums.MetadataProvider;
|
||||
@@ -142,6 +143,19 @@ public class MetadataController {
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@Operation(summary = "Lookup metadata by ISBN", description = "Fetch metadata for a book by ISBN. Requires library management permission or admin.")
|
||||
@ApiResponse(responseCode = "200", description = "Metadata found")
|
||||
@ApiResponse(responseCode = "404", description = "No metadata found for the given ISBN")
|
||||
@PostMapping("/metadata/isbn-lookup")
|
||||
@PreAuthorize("@securityUtil.canManageLibrary() or @securityUtil.isAdmin()")
|
||||
public ResponseEntity<BookMetadata> lookupByIsbn(@RequestBody IsbnLookupRequest request) {
|
||||
BookMetadata metadata = bookMetadataService.lookupByIsbn(request);
|
||||
if (metadata == null) {
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
return ResponseEntity.ok(metadata);
|
||||
}
|
||||
|
||||
@Operation(summary = "Get detailed metadata from provider", description = "Fetch full metadata details for a specific item from a provider. Requires metadata edit permission or admin.")
|
||||
@ApiResponse(responseCode = "200", description = "Detailed metadata returned successfully")
|
||||
@GetMapping("/metadata/detail/{provider}/{providerItemId}")
|
||||
|
||||
+1
@@ -27,4 +27,5 @@ public class CreatePhysicalBookRequest {
|
||||
private String language;
|
||||
private Integer pageCount;
|
||||
private List<String> categories;
|
||||
private String thumbnailUrl;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package org.booklore.model.dto.request;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Builder
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class IsbnLookupRequest {
|
||||
private String isbn;
|
||||
}
|
||||
@@ -13,6 +13,8 @@ import org.booklore.repository.AuthorRepository;
|
||||
import org.booklore.repository.BookRepository;
|
||||
import org.booklore.repository.CategoryRepository;
|
||||
import org.booklore.repository.LibraryRepository;
|
||||
import org.booklore.util.BookCoverUtils;
|
||||
import org.booklore.util.FileService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.HttpStatus;
|
||||
@@ -37,6 +39,7 @@ public class PhysicalBookService {
|
||||
private final AuthorRepository authorRepository;
|
||||
private final CategoryRepository categoryRepository;
|
||||
private final BookMapper bookMapper;
|
||||
private final FileService fileService;
|
||||
|
||||
@Transactional
|
||||
public Book createPhysicalBook(CreatePhysicalBookRequest request) {
|
||||
@@ -76,6 +79,17 @@ public class PhysicalBookService {
|
||||
BookEntity savedBook = bookRepository.save(bookEntity);
|
||||
log.info("Created physical book '{}' in library {} with id {}", request.getTitle(), library.getName(), savedBook.getId());
|
||||
|
||||
if (request.getThumbnailUrl() != null && !request.getThumbnailUrl().isBlank()) {
|
||||
try {
|
||||
fileService.createThumbnailFromUrl(savedBook.getId(), request.getThumbnailUrl());
|
||||
savedBook.getMetadata().setCoverUpdatedOn(Instant.now());
|
||||
savedBook.setBookCoverHash(BookCoverUtils.generateCoverHash());
|
||||
savedBook = bookRepository.save(savedBook);
|
||||
} catch (Exception ex) {
|
||||
log.warn("Failed to download cover for physical book {}: {}", savedBook.getId(), ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
return bookMapper.toBook(savedBook);
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,8 @@ import org.booklore.service.metadata.extractor.CbxMetadataExtractor;
|
||||
import org.booklore.service.metadata.extractor.MetadataExtractorFactory;
|
||||
import org.booklore.service.metadata.parser.BookParser;
|
||||
import org.booklore.service.metadata.parser.DetailedMetadataProvider;
|
||||
import org.booklore.service.appsettings.AppSettingService;
|
||||
import org.booklore.model.dto.request.MetadataRefreshOptions;
|
||||
import org.booklore.util.FileUtils;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -38,12 +40,13 @@ import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.core.scheduler.Schedulers;
|
||||
|
||||
import org.booklore.model.dto.request.IsbnLookupRequest;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@@ -62,6 +65,7 @@ public class BookMetadataService {
|
||||
private final MetadataExtractorFactory metadataExtractorFactory;
|
||||
private final MetadataClearFlagsMapper metadataClearFlagsMapper;
|
||||
private final PlatformTransactionManager transactionManager;
|
||||
private final AppSettingService appSettingService;
|
||||
|
||||
|
||||
public Flux<BookMetadata> getProspectiveMetadataListForBookId(long bookId, FetchMetadataRequest request) {
|
||||
@@ -85,6 +89,52 @@ public class BookMetadataService {
|
||||
}
|
||||
|
||||
|
||||
public BookMetadata lookupByIsbn(IsbnLookupRequest request) {
|
||||
List<MetadataProvider> providers = deriveProviderChainFromSettings();
|
||||
|
||||
FetchMetadataRequest fetchRequest = FetchMetadataRequest.builder()
|
||||
.isbn(request.getIsbn())
|
||||
.providers(providers)
|
||||
.build();
|
||||
|
||||
Book emptyBook = Book.builder().build();
|
||||
|
||||
for (MetadataProvider provider : providers) {
|
||||
try {
|
||||
List<BookMetadata> results = fetchMetadataListFromAProvider(provider, emptyBook, fetchRequest);
|
||||
if (results != null && !results.isEmpty()) {
|
||||
return results.getFirst();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("ISBN lookup failed for provider {}: {}", provider, e.getMessage());
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private List<MetadataProvider> deriveProviderChainFromSettings() {
|
||||
try {
|
||||
MetadataRefreshOptions options = appSettingService.getAppSettings().getDefaultMetadataRefreshOptions();
|
||||
if (options != null && options.getFieldOptions() != null) {
|
||||
MetadataRefreshOptions.FieldProvider titleProvider = options.getFieldOptions().getTitle();
|
||||
if (titleProvider != null) {
|
||||
List<MetadataProvider> chain = Stream.of(
|
||||
titleProvider.getP1(), titleProvider.getP2(),
|
||||
titleProvider.getP3(), titleProvider.getP4())
|
||||
.filter(Objects::nonNull)
|
||||
.distinct()
|
||||
.toList();
|
||||
if (!chain.isEmpty()) {
|
||||
return chain;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("Failed to derive provider chain from settings, falling back to default: {}", e.getMessage());
|
||||
}
|
||||
return List.of(MetadataProvider.Google);
|
||||
}
|
||||
|
||||
public BookMetadata getDetailedProviderMetadata(MetadataProvider provider, String providerItemId) {
|
||||
BookParser parser = getParser(provider);
|
||||
if (parser instanceof DetailedMetadataProvider detailedProvider) {
|
||||
|
||||
@@ -323,8 +323,9 @@ public class FileService {
|
||||
String requestUrl = uri.getScheme() + "://" + hostInUrl + portSuffix + path + (query != null ? "?" + query : "");
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
// Set original 'Host' header for server-side virtual hosting
|
||||
headers.set(HttpHeaders.HOST, host);
|
||||
// Host header is set in prepareConnection via setRequestProperty.
|
||||
// Do NOT set it here: Spring's addRequestProperty would add a duplicate,
|
||||
// and duplicate Host headers cause 400 on strict CDNs like CloudFront.
|
||||
headers.set(HttpHeaders.USER_AGENT, "BookLore/1.0 (Book and Comic Metadata Fetcher; +https://github.com/booklore-app/booklore)");
|
||||
headers.set(HttpHeaders.ACCEPT, "image/*");
|
||||
|
||||
|
||||
+71
-53
@@ -38,63 +38,81 @@
|
||||
|
||||
<div class="gradient-divider"></div>
|
||||
|
||||
<div class="form-row">
|
||||
<div class="form-group highlight-group flex-2">
|
||||
<label for="title" class="form-label">
|
||||
<i class="pi pi-tag label-icon"></i>
|
||||
{{ t('titleLabel') }}
|
||||
</label>
|
||||
<div class="input-wrapper">
|
||||
<input
|
||||
id="title"
|
||||
type="text"
|
||||
pInputText
|
||||
[(ngModel)]="title"
|
||||
class="input-full"
|
||||
[placeholder]="t('titlePlaceholder')"
|
||||
[class.filled]="title.trim()"/>
|
||||
<div class="top-section">
|
||||
@if (coverUrl) {
|
||||
<div class="cover-preview">
|
||||
<img [src]="coverUrl" alt="Book cover"/>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
<div class="form-group highlight-group flex-1">
|
||||
<label for="isbn" class="form-label">
|
||||
<i class="pi pi-barcode label-icon"></i>
|
||||
{{ t('isbnLabel') }}
|
||||
</label>
|
||||
<div class="input-wrapper">
|
||||
<input
|
||||
id="isbn"
|
||||
type="text"
|
||||
pInputText
|
||||
[(ngModel)]="isbn"
|
||||
class="input-full"
|
||||
[placeholder]="t('isbnPlaceholder')"/>
|
||||
<div class="top-fields">
|
||||
<div class="form-row">
|
||||
<div class="form-group highlight-group flex-2">
|
||||
<label for="title" class="form-label">
|
||||
<i class="pi pi-tag label-icon"></i>
|
||||
{{ t('titleLabel') }}
|
||||
</label>
|
||||
<div class="input-wrapper">
|
||||
<input
|
||||
id="title"
|
||||
type="text"
|
||||
pInputText
|
||||
[(ngModel)]="title"
|
||||
class="input-full"
|
||||
[placeholder]="t('titlePlaceholder')"
|
||||
[class.filled]="title.trim()"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group highlight-group flex-1">
|
||||
<label for="isbn" class="form-label">
|
||||
<i class="pi pi-barcode label-icon"></i>
|
||||
{{ t('isbnLabel') }}
|
||||
</label>
|
||||
<div class="isbn-input-row">
|
||||
<input
|
||||
id="isbn"
|
||||
type="text"
|
||||
pInputText
|
||||
[(ngModel)]="isbn"
|
||||
class="input-full"
|
||||
[placeholder]="t('isbnPlaceholder')"/>
|
||||
<p-button
|
||||
icon="pi pi-search"
|
||||
[rounded]="true"
|
||||
[text]="true"
|
||||
severity="info"
|
||||
(onClick)="fetchMetadataByIsbn()"
|
||||
[disabled]="!isbn.trim() || isFetchingMetadata"
|
||||
[loading]="isFetchingMetadata"
|
||||
[pTooltip]="t('fetchMetadataTooltip')"
|
||||
tooltipPosition="top"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="gradient-divider"></div>
|
||||
|
||||
<div class="form-group highlight-group">
|
||||
<label for="authors" class="form-label">
|
||||
<i class="pi pi-user label-icon"></i>
|
||||
{{ t('authorsLabel') }}
|
||||
</label>
|
||||
<div class="autocomplete-wrapper">
|
||||
<p-autoComplete
|
||||
appendTo="body"
|
||||
[(ngModel)]="authors"
|
||||
[multiple]="true"
|
||||
[fluid]="true"
|
||||
[dropdown]="false"
|
||||
[suggestions]="filteredAuthors"
|
||||
[forceSelection]="false"
|
||||
[showClear]="false"
|
||||
[placeholder]="t('authorsPlaceholder')"
|
||||
(completeMethod)="filterAuthors($event)"
|
||||
(onKeyUp)="onAutoCompleteKeyUp('authors', $event)"
|
||||
(onSelect)="onAutoCompleteSelect('authors', $event)">
|
||||
</p-autoComplete>
|
||||
<div class="form-group highlight-group">
|
||||
<label for="authors" class="form-label">
|
||||
<i class="pi pi-user label-icon"></i>
|
||||
{{ t('authorsLabel') }}
|
||||
</label>
|
||||
<div class="autocomplete-wrapper">
|
||||
<p-autoComplete
|
||||
appendTo="body"
|
||||
[(ngModel)]="authors"
|
||||
[multiple]="true"
|
||||
[fluid]="true"
|
||||
[dropdown]="false"
|
||||
[suggestions]="filteredAuthors"
|
||||
[forceSelection]="false"
|
||||
[showClear]="false"
|
||||
[placeholder]="t('authorsPlaceholder')"
|
||||
(completeMethod)="filterAuthors($event)"
|
||||
(onKeyUp)="onAutoCompleteKeyUp('authors', $event)"
|
||||
(onSelect)="onAutoCompleteSelect('authors', $event)">
|
||||
</p-autoComplete>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
+48
@@ -106,6 +106,54 @@
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.isbn-input-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.25rem;
|
||||
|
||||
.input-full {
|
||||
flex: 1;
|
||||
}
|
||||
}
|
||||
|
||||
.top-section {
|
||||
display: flex;
|
||||
gap: 1rem;
|
||||
align-items: flex-start;
|
||||
|
||||
@media (max-width: 640px) {
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
}
|
||||
}
|
||||
|
||||
.top-fields {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.cover-preview {
|
||||
flex-shrink: 0;
|
||||
padding: 0.5rem;
|
||||
|
||||
img {
|
||||
height: 180px;
|
||||
border-radius: 4px;
|
||||
border: 1px solid var(--border-color);
|
||||
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
|
||||
object-fit: contain;
|
||||
}
|
||||
|
||||
@media (max-width: 640px) {
|
||||
img {
|
||||
height: 150px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.autocomplete-wrapper {
|
||||
width: 100%;
|
||||
|
||||
|
||||
+30
-1
@@ -9,6 +9,7 @@ import {Textarea} from 'primeng/textarea';
|
||||
import {InputNumber} from 'primeng/inputnumber';
|
||||
import {AutoComplete, AutoCompleteCompleteEvent} from 'primeng/autocomplete';
|
||||
import {BookService} from '../../service/book.service';
|
||||
import {BookMetadataService} from '../../service/book-metadata.service';
|
||||
import {LibraryService} from '../../service/library.service';
|
||||
import {Library} from '../../model/library.model';
|
||||
import {CreatePhysicalBookRequest} from '../../model/book.model';
|
||||
@@ -37,6 +38,7 @@ export class AddPhysicalBookDialogComponent implements OnInit {
|
||||
private dynamicDialogRef = inject(DynamicDialogRef);
|
||||
private dialogConfig = inject(DynamicDialogConfig);
|
||||
private bookService = inject(BookService);
|
||||
private bookMetadataService = inject(BookMetadataService);
|
||||
private libraryService = inject(LibraryService);
|
||||
private destroyRef = inject(DestroyRef);
|
||||
|
||||
@@ -57,7 +59,9 @@ export class AddPhysicalBookDialogComponent implements OnInit {
|
||||
filteredAuthors: string[] = [];
|
||||
filteredCategories: string[] = [];
|
||||
|
||||
coverUrl: string | null = null;
|
||||
isLoading: boolean = false;
|
||||
isFetchingMetadata: boolean = false;
|
||||
|
||||
ngOnInit(): void {
|
||||
this.libraryService.libraryState$
|
||||
@@ -131,6 +135,30 @@ export class AddPhysicalBookDialogComponent implements OnInit {
|
||||
(event.originalEvent.target as HTMLInputElement).value = '';
|
||||
}
|
||||
|
||||
fetchMetadataByIsbn(): void {
|
||||
const isbnValue = this.isbn.trim();
|
||||
if (!isbnValue || this.isFetchingMetadata) return;
|
||||
|
||||
this.isFetchingMetadata = true;
|
||||
this.bookMetadataService.lookupByIsbn(isbnValue).subscribe({
|
||||
next: (metadata) => {
|
||||
if (metadata.title) this.title = metadata.title;
|
||||
if (metadata.authors?.length) this.authors = [...metadata.authors];
|
||||
if (metadata.description) this.description = metadata.description;
|
||||
if (metadata.publisher) this.publisher = metadata.publisher;
|
||||
if (metadata.publishedDate) this.publishedDate = metadata.publishedDate;
|
||||
if (metadata.language) this.language = metadata.language;
|
||||
if (metadata.pageCount) this.pageCount = metadata.pageCount;
|
||||
if (metadata.categories?.length) this.categories = [...metadata.categories];
|
||||
this.coverUrl = metadata.thumbnailUrl || null;
|
||||
this.isFetchingMetadata = false;
|
||||
},
|
||||
error: () => {
|
||||
this.isFetchingMetadata = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
cancel(): void {
|
||||
this.dynamicDialogRef.close();
|
||||
}
|
||||
@@ -154,7 +182,8 @@ export class AddPhysicalBookDialogComponent implements OnInit {
|
||||
publishedDate: this.publishedDate.trim() || undefined,
|
||||
language: this.language.trim() || undefined,
|
||||
pageCount: this.pageCount ?? undefined,
|
||||
categories: this.categories.length > 0 ? this.categories : undefined
|
||||
categories: this.categories.length > 0 ? this.categories : undefined,
|
||||
thumbnailUrl: this.coverUrl || undefined
|
||||
};
|
||||
|
||||
this.bookService.createPhysicalBook(request).subscribe({
|
||||
|
||||
@@ -413,6 +413,7 @@ export interface CreatePhysicalBookRequest {
|
||||
language?: string;
|
||||
pageCount?: number;
|
||||
categories?: string[];
|
||||
thumbnailUrl?: string;
|
||||
}
|
||||
|
||||
export interface BookStatusUpdateResponse {
|
||||
|
||||
@@ -57,4 +57,8 @@ export class BookMetadataService {
|
||||
fetchMetadataDetail(provider: string, providerItemId: string): Observable<BookMetadata> {
|
||||
return this.http.get<BookMetadata>(`${this.url}/metadata/detail/${provider}/${providerItemId}`);
|
||||
}
|
||||
|
||||
lookupByIsbn(isbn: string): Observable<BookMetadata> {
|
||||
return this.http.post<BookMetadata>(`${this.url}/metadata/isbn-lookup`, {isbn});
|
||||
}
|
||||
}
|
||||
|
||||
+3
-5
@@ -593,9 +593,8 @@
|
||||
<p-button
|
||||
icon="pi pi-chevron-left"
|
||||
[disabled]="!canNavigatePrevious()"
|
||||
(onClick)="navigatePrevious()"
|
||||
rounded
|
||||
text
|
||||
(onClick)="navigatePrevious()"`
|
||||
outlined
|
||||
severity="secondary"
|
||||
[pTooltip]="t('goToPreviousBook')"
|
||||
tooltipPosition="bottom">
|
||||
@@ -609,8 +608,7 @@
|
||||
[disabled]="!canNavigateNext()"
|
||||
(onClick)="navigateNext()"
|
||||
severity="secondary"
|
||||
rounded
|
||||
text
|
||||
outlined
|
||||
[pTooltip]="t('goToNextBook')"
|
||||
tooltipPosition="bottom">
|
||||
</p-button>
|
||||
|
||||
@@ -429,7 +429,8 @@
|
||||
"validationTitleOrIsbn": "Title or ISBN is required",
|
||||
"validationReady": "Ready to create",
|
||||
"cancelButton": "Cancel",
|
||||
"addButton": "Add Physical Book"
|
||||
"addButton": "Add Physical Book",
|
||||
"fetchMetadataTooltip": "Fetch metadata by ISBN"
|
||||
},
|
||||
"fileUploader": {
|
||||
"title": "Upload Additional File",
|
||||
|
||||
@@ -429,7 +429,8 @@
|
||||
"validationTitleOrIsbn": "Se requiere un título o ISBN",
|
||||
"validationReady": "Listo para crear",
|
||||
"cancelButton": "Cancelar",
|
||||
"addButton": "Agregar libro físico"
|
||||
"addButton": "Agregar libro físico",
|
||||
"fetchMetadataTooltip": "Obtener metadatos por ISBN"
|
||||
},
|
||||
"fileUploader": {
|
||||
"title": "Subir archivo adicional",
|
||||
|
||||
Reference in New Issue
Block a user