feat: add button to fetch metadata from book file in metadata editor (#2739)

This commit is contained in:
ACX
2026-02-13 21:04:00 -07:00
committed by GitHub
parent 5076522f35
commit 77b4deb942
7 changed files with 83 additions and 3 deletions
@@ -690,6 +690,10 @@ export class BookService {
return this.http.post<void>(`${this.url}/${bookId}/regenerate-cover`, {});
}
getFileMetadata(bookId: number): Observable<BookMetadata> {
return this.http.get<BookMetadata>(`${this.url}/${bookId}/file-metadata`);
}
generateCustomCover(bookId: number): Observable<void> {
return this.http.post<void>(`${this.url}/${bookId}/generate-custom-cover`, {});
}
@@ -161,7 +161,6 @@
<p-button [pTooltip]="t('unlockCoverTooltip')" tooltipPosition="top" size="small" icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('audiobookCover')" severity="warn"></p-button>
}
</div>
`
</div>
}
</div>
@@ -967,6 +966,18 @@
}
<div class="actions-right">
@if (!book.isPhysical) {
<p-button
[label]="isFetchingFromFile ? t('fetchingBtn') : t('fetchFromFileBtn')"
[icon]="isFetchingFromFile ? 'pi pi-spin pi-spinner' : 'pi pi-file'"
[outlined]="true"
severity="secondary"
(onClick)="fetchFromFile(book.id)"
[disabled]="isFetchingFromFile"
[pTooltip]="t('fetchFromFileTooltip')"
tooltipPosition="top">
</p-button>
}
<p-button
[label]="isAutoFetching ? t('fetchingBtn') : t('autoFetchBtn')"
[icon]="isAutoFetching ? 'pi pi-spin pi-spinner' : 'pi pi-bolt'"
@@ -1025,6 +1036,17 @@
</div>
}
<div class="mobile-lock-actions">
@if (!book.isPhysical) {
<p-button
icon="pi pi-file"
[outlined]="true"
severity="secondary"
(onClick)="fetchFromFile(book.id)"
[disabled]="isFetchingFromFile"
[pTooltip]="t('fetchFromFileBtn')"
tooltipPosition="top">
</p-button>
}
<p-button
icon="pi pi-bolt"
[outlined]="true"
@@ -90,6 +90,7 @@ export class MetadataEditorComponent implements OnInit {
refreshingBookIds = new Set<number>();
isAutoFetching = false;
isFetchingFromFile = false;
autoSaveEnabled = false;
originalMetadata!: BookMetadata;
@@ -1035,6 +1036,31 @@ export class MetadataEditorComponent implements OnInit {
}, 15000);
}
fetchFromFile(bookId: number) {
this.isFetchingFromFile = true;
this.bookService.getFileMetadata(bookId).pipe(
finalize(() => this.isFetchingFromFile = false),
takeUntilDestroyed(this.destroyRef)
).subscribe({
next: (metadata) => {
this.populateFormFromMetadata(metadata);
this.metadataForm.markAsDirty();
this.messageService.add({
severity: 'info',
summary: this.t.translate('metadata.editor.toast.successSummary'),
detail: this.t.translate('metadata.editor.toast.fileMetadataLoaded'),
});
},
error: (err) => {
this.messageService.add({
severity: 'error',
summary: this.t.translate('metadata.editor.toast.errorSummary'),
detail: err?.error?.message || this.t.translate('metadata.editor.toast.fileMetadataFailed'),
});
}
});
}
onNext() {
this.nextBookClicked.emit();
}