feat: add additional cover art actions and settings (#1938)

* feat: add cover image auto cropping when oversized

* feat: add smart cropping to ignore sections of constant colours in cover images

* fix: description implied cbx files would be excluded from cover regeneration when they are not

* feat: add options to bulk edit cover images in the library view

* fix: resolve issues with batching requests and data validation for cover images
This commit is contained in:
CounterClops
2025-12-19 11:20:50 -07:00
committed by GitHub
parent 4e6842c189
commit 54108754f9
26 changed files with 745 additions and 37 deletions
@@ -257,6 +257,7 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
() => this.fetchMetadata(),
() => this.bulkEditMetadata(),
() => this.multiBookEditMetadata(),
() => this.regenerateCoversForSelected(),
);
this.tieredMenuItems = this.bookMenuService.getTieredMenuItems(this.selectedBooks);
@@ -668,6 +669,38 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
this.dialogHelperService.openMultibookMetadataEditorDialog(this.selectedBooks);
}
regenerateCoversForSelected(): void {
if (!this.selectedBooks || this.selectedBooks.size === 0) return;
const count = this.selectedBooks.size;
this.confirmationService.confirm({
message: `Are you sure you want to regenerate covers for ${count} book(s)?`,
header: 'Confirm Cover Regeneration',
icon: 'pi pi-image',
acceptLabel: 'Yes',
rejectLabel: 'No',
accept: () => {
this.bookService.regenerateCoversForBooks(Array.from(this.selectedBooks)).subscribe({
next: () => {
this.messageService.add({
severity: 'success',
summary: 'Cover Regeneration Started',
detail: `Regenerating covers for ${count} book(s). Refresh the page when complete.`,
life: 3000
});
},
error: () => {
this.messageService.add({
severity: 'error',
summary: 'Failed',
detail: 'Could not start cover regeneration.',
life: 3000
});
}
});
}
});
}
moveFiles() {
this.dialogHelperService.openFileMoverDialog(this.selectedBooks);
}
@@ -22,7 +22,8 @@ export class BookMenuService {
autoFetchMetadata: () => void,
fetchMetadata: () => void,
bulkEditMetadata: () => void,
multiBookEditMetadata: () => void): MenuItem[] {
multiBookEditMetadata: () => void,
regenerateCovers: () => void): MenuItem[] {
return [
{
label: 'Auto Fetch Metadata',
@@ -43,6 +44,11 @@ export class BookMenuService {
label: 'Multi-Book Metadata Editor',
icon: 'pi pi-clone',
command: multiBookEditMetadata
},
{
label: 'Regenerate Covers',
icon: 'pi pi-image',
command: regenerateCovers
}
];
}
@@ -432,6 +432,17 @@ export class BookService {
return this.http.post<void>(`${this.url}/${bookId}/regenerate-cover`, {});
}
regenerateCoversForBooks(bookIds: number[]): Observable<void> {
return this.http.post<void>(`${this.url}/bulk-regenerate-covers`, { bookIds });
}
bulkUploadCover(bookIds: number[], file: File): Observable<void> {
const formData = new FormData();
formData.append('file', file);
formData.append('bookIds', bookIds.join(','));
return this.http.post<void>(`${this.url}/bulk-upload-cover`, formData);
}
/*------------------ All the metadata related calls go here ------------------*/
@@ -312,6 +312,49 @@
</div>
</div>
<!-- Cover Image Upload Section -->
<div class="flex flex-col gap-2 border border-gray-700 rounded-md p-4 bg-gray-900">
<label class="flex items-center gap-2 text-base font-semibold">
<i class="pi pi-image"></i>
Cover Image
</label>
<p class="text-sm text-gray-400">
Upload an image to set as the cover for all selected books.
</p>
<div class="flex items-center gap-4 mt-2">
@if (selectedCoverFile) {
<div class="flex items-center gap-2 text-sm text-gray-300">
<i class="pi pi-file-image"></i>
<span>{{ selectedCoverFile.name }}</span>
<p-button
icon="pi pi-times"
[text]="true"
size="small"
severity="danger"
(onClick)="clearCoverFile()"
pTooltip="Remove file"
tooltipPosition="top">
</p-button>
</div>
} @else {
<input
type="file"
#coverFileInput
accept="image/jpeg,image/png,image/webp"
(change)="onCoverFileSelect($event)"
class="hidden">
<p-button
icon="pi pi-upload"
label="Select Image"
[outlined]="true"
size="small"
severity="info"
(onClick)="coverFileInput.click()">
</p-button>
}
</div>
</div>
<div class="flex justify-end mt-4">
<p-button type="submit" label="Apply to Selected" [disabled]="loading"/>
</div>
@@ -41,6 +41,7 @@ export class BulkMetadataUpdateComponent implements OnInit {
mergeMoods = true;
mergeTags = true;
loading = false;
selectedCoverFile: File | null = null;
clearFields = {
authors: false,
@@ -257,13 +258,37 @@ export class BulkMetadataUpdateComponent implements OnInit {
this.loading = true;
this.bookService.updateBooksMetadata(payload).subscribe({
next: () => {
this.loading = false;
this.messageService.add({
severity: 'success',
summary: 'Metadata Updated',
detail: 'Books updated successfully'
});
this.ref.close(true);
if (this.selectedCoverFile) {
this.bookService.bulkUploadCover(this.bookIds, this.selectedCoverFile).subscribe({
next: () => {
this.loading = false;
this.messageService.add({
severity: 'success',
summary: 'Metadata & Cover Updated',
detail: 'Books updated and cover upload started. Refresh the page when complete.'
});
this.ref.close(true);
},
error: err => {
console.error('Bulk cover upload failed:', err);
this.loading = false;
this.messageService.add({
severity: 'warn',
summary: 'Partial Success',
detail: 'Metadata updated but cover upload failed'
});
this.ref.close(true);
}
});
} else {
this.loading = false;
this.messageService.add({
severity: 'success',
summary: 'Metadata Updated',
detail: 'Books updated successfully'
});
this.ref.close(true);
}
},
error: err => {
console.error('Bulk metadata update failed:', err);
@@ -276,4 +301,15 @@ export class BulkMetadataUpdateComponent implements OnInit {
}
});
}
onCoverFileSelect(event: Event): void {
const input = event.target as HTMLInputElement;
if (input.files && input.files.length > 0) {
this.selectedCoverFile = input.files[0];
}
}
clearCoverFile(): void {
this.selectedCoverFile = null;
}
}
@@ -34,7 +34,76 @@
</div>
<p class="setting-description">
<i class="pi pi-info-circle"></i>
Regenerates cover images for all EPUB and PDF books (excluding locked ones) from the embedded covers in the file.
Regenerates cover images for all books from the embedded covers in the file.
</p>
</div>
</div>
<div class="setting-item">
<div class="setting-info">
<div class="setting-label-row">
<label class="setting-label">Vertical Cover Cropping</label>
<p-toggleswitch
[(ngModel)]="coverCroppingSettings.verticalCroppingEnabled"
(onChange)="onCoverCroppingChange()">
</p-toggleswitch>
</div>
<p class="setting-description">
<i class="pi pi-info-circle"></i>
Automatically crop extremely tall images (like web comics) from the top to create usable cover thumbnails.
</p>
</div>
</div>
<div class="setting-item">
<div class="setting-info">
<div class="setting-label-row">
<label class="setting-label">Horizontal Cover Cropping</label>
<p-toggleswitch
[(ngModel)]="coverCroppingSettings.horizontalCroppingEnabled"
(onChange)="onCoverCroppingChange()">
</p-toggleswitch>
</div>
<p class="setting-description">
<i class="pi pi-info-circle"></i>
Automatically crop extremely wide images from the left to create usable cover thumbnails.
</p>
</div>
</div>
<div class="setting-item">
<div class="setting-info">
<div class="setting-label-row">
<label class="setting-label">Aspect Ratio Threshold: {{ coverCroppingSettings.aspectRatioThreshold }}</label>
<div class="slider-container">
<p-slider
[(ngModel)]="coverCroppingSettings.aspectRatioThreshold"
[min]="1.5"
[max]="3"
[step]="0.1"
(onSlideEnd)="onCoverCroppingChange()">
</p-slider>
</div>
</div>
<p class="setting-description">
<i class="pi pi-info-circle"></i>
Images with aspect ratios exceeding this threshold will be cropped. A value of 2.5 means images more than 2.5x taller (or wider) than normal will be cropped.
</p>
</div>
</div>
<div class="setting-item">
<div class="setting-info">
<div class="setting-label-row">
<label class="setting-label">Smart Cropping</label>
<p-toggleswitch
[(ngModel)]="coverCroppingSettings.smartCroppingEnabled"
(onChange)="onCoverCroppingChange()">
</p-toggleswitch>
</div>
<p class="setting-description">
<i class="pi pi-info-circle"></i>
Skip uniform colour regions when determining where to crop. Focuses the cover image on the most relevant content.
</p>
</div>
</div>
@@ -215,3 +215,14 @@
margin-top: 0.5rem;
}
}
.slider-container {
flex: 1;
min-width: 200px;
max-width: 300px;
@media (max-width: 768px) {
min-width: 180px;
max-width: 250px;
}
}
@@ -7,9 +7,10 @@ import {MessageService} from 'primeng/api';
import {AppSettingsService} from '../../../shared/service/app-settings.service';
import {BookService} from '../../book/service/book.service';
import {AppSettingKey, AppSettings} from '../../../shared/model/app-settings.model';
import {AppSettingKey, AppSettings, CoverCroppingSettings} from '../../../shared/model/app-settings.model';
import {filter, take} from 'rxjs/operators';
import {InputText} from 'primeng/inputtext';
import {Slider} from 'primeng/slider';
@Component({
selector: 'app-global-preferences',
@@ -18,7 +19,8 @@ import {InputText} from 'primeng/inputtext';
Button,
ToggleSwitch,
FormsModule,
InputText
InputText,
Slider
],
templateUrl: './global-preferences.component.html',
styleUrl: './global-preferences.component.scss'
@@ -30,6 +32,13 @@ export class GlobalPreferencesComponent implements OnInit {
similarBookRecommendation: false,
};
coverCroppingSettings: CoverCroppingSettings = {
verticalCroppingEnabled: false,
horizontalCroppingEnabled: false,
aspectRatioThreshold: 2.5,
smartCroppingEnabled: false
};
private appSettingsService = inject(AppSettingsService);
private bookService = inject(BookService);
private messageService = inject(MessageService);
@@ -49,6 +58,9 @@ export class GlobalPreferencesComponent implements OnInit {
if (settings?.maxFileUploadSizeInMb) {
this.maxFileUploadSizeInMb = settings.maxFileUploadSizeInMb;
}
if (settings?.coverCroppingSettings) {
this.coverCroppingSettings = {...settings.coverCroppingSettings};
}
this.toggles.autoBookSearch = settings.autoBookSearch ?? false;
this.toggles.similarBookRecommendation = settings.similarBookRecommendation ?? false;
});
@@ -68,6 +80,10 @@ export class GlobalPreferencesComponent implements OnInit {
}
}
onCoverCroppingChange(): void {
this.saveSetting(AppSettingKey.COVER_CROPPING_SETTINGS, this.coverCroppingSettings);
}
saveCacheSize(): void {
if (!this.cbxCacheValue || this.cbxCacheValue <= 0) {
this.showMessage('error', 'Invalid Input', 'Please enter a valid cache size in MB.');
@@ -108,6 +108,13 @@ export interface KoboSettings {
forceEnableHyphenation: boolean;
}
export interface CoverCroppingSettings {
verticalCroppingEnabled: boolean;
horizontalCroppingEnabled: boolean;
aspectRatioThreshold: number;
smartCroppingEnabled: boolean;
}
export interface AppSettings {
autoBookSearch: boolean;
similarBookRecommendation: boolean;
@@ -126,6 +133,7 @@ export interface AppSettings {
metadataPersistenceSettings: MetadataPersistenceSettings;
metadataPublicReviewsSettings: PublicReviewSettings;
koboSettings: KoboSettings;
coverCroppingSettings: CoverCroppingSettings;
metadataDownloadOnBookdrop: boolean;
}
@@ -146,5 +154,6 @@ export enum AppSettingKey {
METADATA_PERSISTENCE_SETTINGS = 'METADATA_PERSISTENCE_SETTINGS',
METADATA_DOWNLOAD_ON_BOOKDROP = 'METADATA_DOWNLOAD_ON_BOOKDROP',
METADATA_PUBLIC_REVIEWS_SETTINGS = 'METADATA_PUBLIC_REVIEWS_SETTINGS',
KOBO_SETTINGS = 'KOBO_SETTINGS'
KOBO_SETTINGS = 'KOBO_SETTINGS',
COVER_CROPPING_SETTINGS = 'COVER_CROPPING_SETTINGS'
}