@@ -95,8 +95,8 @@ public class BookCoverController {
|
||||
@ApiResponse(responseCode = "204", description = "Covers regenerated successfully")
|
||||
@PostMapping("/regenerate-covers")
|
||||
@PreAuthorize("@securityUtil.canBulkRegenerateCover() or @securityUtil.isAdmin()")
|
||||
public void regenerateCovers() {
|
||||
bookCoverService.regenerateCovers();
|
||||
public void regenerateCovers(@RequestParam(defaultValue = "false") boolean missingOnly) {
|
||||
bookCoverService.regenerateCovers(missingOnly);
|
||||
}
|
||||
|
||||
@Operation(summary = "Regenerate cover for a book", description = "Regenerate cover for a specific book. Requires metadata edit permission or admin.")
|
||||
|
||||
@@ -293,18 +293,20 @@ public class BookCoverService {
|
||||
}
|
||||
|
||||
/**
|
||||
* Regenerate covers for all books.
|
||||
* Regenerate covers for all books, optionally only for books with missing covers.
|
||||
*/
|
||||
public void regenerateCovers() {
|
||||
public void regenerateCovers(boolean missingOnly) {
|
||||
SecurityContextVirtualThread.runWithSecurityContext(() -> {
|
||||
try {
|
||||
List<BookRegenerationInfo> books = bookQueryService.getAllFullBookEntities().stream()
|
||||
.filter(book -> !isCoverLocked(book))
|
||||
.filter(book -> book.getPrimaryBookFile() != null)
|
||||
.filter(book -> !missingOnly || book.getBookCoverHash() == null)
|
||||
.map(book -> new BookRegenerationInfo(book.getId(), book.getMetadata().getTitle(), book.getPrimaryBookFile().getBookType(), false))
|
||||
.toList();
|
||||
int total = books.size();
|
||||
notificationService.sendMessage(Topic.LOG, LogNotification.info("Started regenerating covers for " + total + " books"));
|
||||
String label = missingOnly ? "missing" : "all";
|
||||
notificationService.sendMessage(Topic.LOG, LogNotification.info("Started regenerating covers for " + total + " books (" + label + ")"));
|
||||
|
||||
int current = 1;
|
||||
List<Long> refreshedIds = new ArrayList<>();
|
||||
|
||||
Reference in New Issue
Block a user