add detach book file feature and fix attach not respecting move preference (#3024)

This commit is contained in:
ACX
2026-02-26 08:16:12 -07:00
committed by GitHub
parent 073bc1045e
commit 3e374a197f
19 changed files with 751 additions and 40 deletions
@@ -2,7 +2,7 @@ import {inject, Injectable} from '@angular/core';
import {Observable, throwError} from 'rxjs';
import {HttpClient} from '@angular/common/http';
import {catchError, tap} from 'rxjs/operators';
import {AdditionalFile, AdditionalFileType, Book, DuplicateDetectionRequest, DuplicateGroup} from '../model/book.model';
import {AdditionalFile, AdditionalFileType, Book, DetachBookFileResponse, DuplicateDetectionRequest, DuplicateGroup} from '../model/book.model';
import {API_CONFIG} from '../../../core/config/api-config';
import {MessageService} from 'primeng/api';
import {FileDownloadService} from '../../../shared/service/file-download.service';
@@ -208,6 +208,37 @@ export class BookFileService {
this.fileDownloadService.downloadFile(downloadUrl, additionalFile?.fileName ?? 'file');
}
detachBookFile(bookId: number, fileId: number, copyMetadata: boolean): Observable<DetachBookFileResponse> {
return this.http.post<DetachBookFileResponse>(`${this.url}/${bookId}/files/${fileId}/detach`, { copyMetadata }).pipe(
tap(response => {
const currentState = this.bookStateService.getCurrentBookState();
let updatedBooks = (currentState.books || []).map(book =>
book.id === bookId ? response.sourceBook : book
);
updatedBooks = [...updatedBooks, response.newBook];
this.bookStateService.updateBookState({
...currentState,
books: updatedBooks
});
this.messageService.add({
severity: 'success',
summary: this.t.translate('metadata.viewer.toast.detachFileSuccessSummary'),
detail: this.t.translate('metadata.viewer.toast.detachFileSuccessDetail')
});
}),
catchError(error => {
this.messageService.add({
severity: 'error',
summary: this.t.translate('metadata.viewer.toast.detachFileErrorSummary'),
detail: error?.error?.message || error?.message || this.t.translate('metadata.viewer.toast.detachFileErrorDetail')
});
return throwError(() => error);
})
);
}
findDuplicates(request: DuplicateDetectionRequest): Observable<DuplicateGroup[]> {
return this.http.post<DuplicateGroup[]>(`${this.url}/duplicates`, request);
}