Add duplicate book detection/merge and fix format-related data loss (#2820)
* Add duplicate book detection and merge feature * Remove delta sync, ETag, and IndexedDB caching --------- Co-authored-by: acx10 <acx10@users.noreply.github.com>
This commit is contained in:
Generated
-7
@@ -29,7 +29,6 @@
|
||||
"chartjs-chart-matrix": "^3.0.0",
|
||||
"chartjs-plugin-datalabels": "^2.2.0",
|
||||
"date-fns": "^4.1.0",
|
||||
"idb": "^8.0.3",
|
||||
"jwt-decode": "^4.0.0",
|
||||
"ng-lazyload-image": "^9.1.3",
|
||||
"ng2-charts": "^8.0.0",
|
||||
@@ -7316,12 +7315,6 @@
|
||||
"url": "https://opencollective.com/express"
|
||||
}
|
||||
},
|
||||
"node_modules/idb": {
|
||||
"version": "8.0.3",
|
||||
"resolved": "https://registry.npmjs.org/idb/-/idb-8.0.3.tgz",
|
||||
"integrity": "sha512-LtwtVyVYO5BqRvcsKuB2iUMnHwPVByPCXFXOpuU96IZPPoPN6xjOGxZQ74pgSVVLQWtUOYgyeL4GE98BY5D3wg==",
|
||||
"license": "ISC"
|
||||
},
|
||||
"node_modules/ignore": {
|
||||
"version": "7.0.5",
|
||||
"resolved": "https://registry.npmjs.org/ignore/-/ignore-7.0.5.tgz",
|
||||
|
||||
@@ -33,7 +33,6 @@
|
||||
"chartjs-chart-matrix": "^3.0.0",
|
||||
"chartjs-plugin-datalabels": "^2.2.0",
|
||||
"date-fns": "^4.1.0",
|
||||
"idb": "^8.0.3",
|
||||
"jwt-decode": "^4.0.0",
|
||||
"ng-lazyload-image": "^9.1.3",
|
||||
"ng2-charts": "^8.0.0",
|
||||
|
||||
+11
@@ -17,6 +17,7 @@ import {Book} from '../../model/book.model';
|
||||
import {AdditionalFileUploaderComponent} from '../additional-file-uploader/additional-file-uploader.component';
|
||||
import {BookFileAttacherComponent} from '../book-file-attacher/book-file-attacher.component';
|
||||
import {AddPhysicalBookDialogComponent} from '../add-physical-book-dialog/add-physical-book-dialog.component';
|
||||
import {DuplicateMergerComponent} from '../duplicate-merger/duplicate-merger.component';
|
||||
|
||||
@Injectable({providedIn: 'root'})
|
||||
export class BookDialogHelperService {
|
||||
@@ -165,6 +166,16 @@ export class BookDialogHelperService {
|
||||
});
|
||||
}
|
||||
|
||||
openDuplicateMergerDialog(libraryId: number): DynamicDialogRef | null {
|
||||
return this.openDialog(DuplicateMergerComponent, {
|
||||
showHeader: false,
|
||||
styleClass: `${DialogSize.XL} ${DialogStyle.MINIMAL}`,
|
||||
data: {
|
||||
libraryId: libraryId,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
openAddPhysicalBookDialog(libraryId?: number): DynamicDialogRef | null {
|
||||
return this.openDialog(AddPhysicalBookDialogComponent, {
|
||||
showHeader: false,
|
||||
|
||||
+215
@@ -0,0 +1,215 @@
|
||||
<ng-container *transloco="let t; prefix: 'book.duplicateMerger'">
|
||||
<div class="duplicate-merger-container">
|
||||
<div class="panel-header">
|
||||
<div class="header-icon-wrapper">
|
||||
<i class="pi pi-copy header-icon"></i>
|
||||
</div>
|
||||
<div class="header-text">
|
||||
<h2 class="panel-title">{{ t('title') }}</h2>
|
||||
<p class="panel-description">{{ t('description') }}</p>
|
||||
</div>
|
||||
<p-button
|
||||
icon="pi pi-times"
|
||||
[rounded]="true"
|
||||
[text]="true"
|
||||
severity="secondary"
|
||||
(click)="closeDialog()"
|
||||
class="close-button">
|
||||
</p-button>
|
||||
</div>
|
||||
|
||||
<div class="dialog-content">
|
||||
<!-- Preset Mode Selector -->
|
||||
<div class="preset-section">
|
||||
<p-selectButton
|
||||
[options]="presetOptions"
|
||||
[(ngModel)]="presetMode"
|
||||
(onChange)="onPresetChange()"
|
||||
optionLabel="label"
|
||||
optionValue="value"
|
||||
[disabled]="isScanning || isMerging">
|
||||
</p-selectButton>
|
||||
</div>
|
||||
|
||||
<!-- Advanced Toggles -->
|
||||
<div class="advanced-section">
|
||||
<button class="advanced-toggle" (click)="showAdvanced = !showAdvanced">
|
||||
<i class="pi" [class.pi-chevron-right]="!showAdvanced" [class.pi-chevron-down]="showAdvanced"></i>
|
||||
{{ t('advanced') }}
|
||||
</button>
|
||||
|
||||
@if (showAdvanced) {
|
||||
<div class="signal-checkboxes">
|
||||
<div class="signal-checkbox">
|
||||
<p-checkbox [(ngModel)]="matchByIsbn" [binary]="true" inputId="isbn" (onChange)="onSignalToggle()" [disabled]="isScanning || isMerging"></p-checkbox>
|
||||
<label for="isbn">{{ t('signalIsbn') }}</label>
|
||||
</div>
|
||||
<div class="signal-checkbox">
|
||||
<p-checkbox [(ngModel)]="matchByExternalId" [binary]="true" inputId="externalId" (onChange)="onSignalToggle()" [disabled]="isScanning || isMerging"></p-checkbox>
|
||||
<label for="externalId">{{ t('signalExternalId') }}</label>
|
||||
</div>
|
||||
<div class="signal-checkbox">
|
||||
<p-checkbox [(ngModel)]="matchByTitleAuthor" [binary]="true" inputId="titleAuthor" (onChange)="onSignalToggle()" [disabled]="isScanning || isMerging"></p-checkbox>
|
||||
<label for="titleAuthor">{{ t('signalTitleAuthor') }}</label>
|
||||
</div>
|
||||
<div class="signal-checkbox">
|
||||
<p-checkbox [(ngModel)]="matchByDirectory" [binary]="true" inputId="directory" (onChange)="onSignalToggle()" [disabled]="isScanning || isMerging"></p-checkbox>
|
||||
<label for="directory">{{ t('signalDirectory') }}</label>
|
||||
</div>
|
||||
<div class="signal-checkbox">
|
||||
<p-checkbox [(ngModel)]="matchByFilename" [binary]="true" inputId="filename" (onChange)="onSignalToggle()" [disabled]="isScanning || isMerging"></p-checkbox>
|
||||
<label for="filename">{{ t('signalFilename') }}</label>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<!-- Action Bar -->
|
||||
<div class="action-bar">
|
||||
<div class="action-bar-left">
|
||||
<p-button
|
||||
[label]="t('scan')"
|
||||
icon="pi pi-search"
|
||||
(click)="scan()"
|
||||
[disabled]="!canScan"
|
||||
[loading]="isScanning">
|
||||
</p-button>
|
||||
</div>
|
||||
<div class="action-bar-right">
|
||||
<div class="delete-option">
|
||||
<p-checkbox
|
||||
[(ngModel)]="deleteSourceBooks"
|
||||
[binary]="true"
|
||||
inputId="deleteSource"
|
||||
[disabled]="isMerging">
|
||||
</p-checkbox>
|
||||
<label for="deleteSource">{{ t('deleteSource') }}</label>
|
||||
</div>
|
||||
@if (activeGroups.length > 0) {
|
||||
<p-button
|
||||
[label]="t('mergeAll', { count: activeGroups.length })"
|
||||
icon="pi pi-check-circle"
|
||||
severity="success"
|
||||
(click)="mergeAll()"
|
||||
[disabled]="isMerging"
|
||||
[loading]="isMerging">
|
||||
</p-button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Merge Progress -->
|
||||
@if (isMerging) {
|
||||
<p-progressBar [value]="mergeTotal > 0 ? (mergeProgress / mergeTotal) * 100 : 0" [showValue]="false"></p-progressBar>
|
||||
}
|
||||
|
||||
<!-- Help Text -->
|
||||
@if (hasScanned && activeGroups.length > 0) {
|
||||
<div class="help-text">
|
||||
<i class="pi pi-info-circle"></i>
|
||||
<span>{{ t('helpText') }}</span>
|
||||
</div>
|
||||
}
|
||||
|
||||
<!-- Results Area -->
|
||||
<div class="results-area">
|
||||
@if (isScanning) {
|
||||
<div class="empty-state">
|
||||
<i class="pi pi-spin pi-spinner"></i>
|
||||
<p>{{ t('scanning') }}</p>
|
||||
</div>
|
||||
} @else if (!hasScanned) {
|
||||
<div class="empty-state">
|
||||
<i class="pi pi-search"></i>
|
||||
<p>{{ t('scanPrompt') }}</p>
|
||||
</div>
|
||||
} @else if (activeGroups.length === 0 && groups.length === 0) {
|
||||
<div class="empty-state">
|
||||
<i class="pi pi-check-circle"></i>
|
||||
<p>{{ t('noDuplicates') }}</p>
|
||||
</div>
|
||||
} @else if (activeGroups.length === 0 && groups.length > 0) {
|
||||
<div class="empty-state">
|
||||
<i class="pi pi-check-circle"></i>
|
||||
<p>{{ t('allMerged') }}</p>
|
||||
</div>
|
||||
} @else {
|
||||
<div class="groups-list">
|
||||
@for (group of pagedGroups; track group.suggestedTargetBookId) {
|
||||
<div class="duplicate-group">
|
||||
<div class="group-header">
|
||||
<span class="group-label">{{ t('groupLabel', { index: pageFirst + $index + 1 }) }}</span>
|
||||
<p-tag [value]="getMatchReasonLabel(group.matchReason)" [severity]="getMatchReasonSeverity(group.matchReason)"></p-tag>
|
||||
<div class="group-actions">
|
||||
<p-button
|
||||
[label]="t('merge')"
|
||||
icon="pi pi-check"
|
||||
size="small"
|
||||
severity="success"
|
||||
(click)="mergeGroup(group)"
|
||||
[disabled]="isMerging">
|
||||
</p-button>
|
||||
<p-button
|
||||
[label]="t('dismiss')"
|
||||
icon="pi pi-times"
|
||||
size="small"
|
||||
severity="secondary"
|
||||
[outlined]="true"
|
||||
(click)="dismissGroup(group)"
|
||||
[disabled]="isMerging">
|
||||
</p-button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="group-books">
|
||||
@for (book of group.books; track book.id) {
|
||||
<div class="book-row" [class.selected-target]="book.id === group.selectedTargetBookId" (click)="group.selectedTargetBookId = book.id">
|
||||
<img class="book-cover"
|
||||
[src]="urlHelper.getThumbnailUrl(book.id, book.metadata?.coverUpdatedOn)"
|
||||
[alt]="book.metadata?.title || ''"
|
||||
loading="lazy"/>
|
||||
<div class="book-info">
|
||||
<div class="book-title">{{ book.metadata?.title || ('book.fileAttacher.unknownTitle' | transloco) }}</div>
|
||||
@if (book.metadata?.authors?.length) {
|
||||
<div class="book-authors">{{ book.metadata?.authors?.join(', ') }}</div>
|
||||
}
|
||||
<div class="book-formats">
|
||||
@for (format of getBookFormats(book); track format) {
|
||||
<span class="format-badge">{{ format }}</span>
|
||||
}
|
||||
@if (getFileCount(book) > 1) {
|
||||
<span class="file-count">{{ t('fileCount', { count: getFileCount(book) }) }}</span>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
<div class="book-select">
|
||||
<p-radioButton
|
||||
[name]="'target-' + group.suggestedTargetBookId"
|
||||
[value]="book.id"
|
||||
[(ngModel)]="group.selectedTargetBookId"
|
||||
[disabled]="isMerging">
|
||||
</p-radioButton>
|
||||
@if (book.id === group.selectedTargetBookId) {
|
||||
<span class="target-label">{{ t('target') }}</span>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
@if (activeGroups.length > pageSize) {
|
||||
<p-paginator
|
||||
[rows]="pageSize"
|
||||
[totalRecords]="activeGroups.length"
|
||||
[first]="pageFirst"
|
||||
(onPageChange)="onPageChange($event)"
|
||||
[rowsPerPageOptions]="[10, 20, 50]">
|
||||
</p-paginator>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</ng-container>
|
||||
+308
@@ -0,0 +1,308 @@
|
||||
@use '../../../../shared/styles/panel-shared' as panel;
|
||||
|
||||
.duplicate-merger-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.panel-header {
|
||||
@include panel.panel-header;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.dialog-content {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
min-height: 0;
|
||||
padding: 1.5rem;
|
||||
background: var(--card-background);
|
||||
border: 1px solid var(--border-color);
|
||||
border-top: none;
|
||||
border-radius: 0 0 10px 10px;
|
||||
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.preset-section {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.advanced-section {
|
||||
.advanced-toggle {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
background: none;
|
||||
border: none;
|
||||
color: var(--p-text-muted-color);
|
||||
font-size: 0.875rem;
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
padding: 0.25rem 0;
|
||||
|
||||
&:hover {
|
||||
color: var(--p-text-color);
|
||||
}
|
||||
|
||||
i {
|
||||
font-size: 0.75rem;
|
||||
}
|
||||
}
|
||||
|
||||
.signal-checkboxes {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.75rem 1.5rem;
|
||||
padding: 0.75rem 0 0 0;
|
||||
}
|
||||
|
||||
.signal-checkbox {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
|
||||
label {
|
||||
font-size: 0.875rem;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.action-bar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 1rem;
|
||||
padding: 0.75rem 0;
|
||||
border-top: 1px solid var(--border-color);
|
||||
border-bottom: 1px solid var(--border-color);
|
||||
|
||||
.action-bar-left {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
|
||||
.action-bar-right {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.delete-option {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
|
||||
label {
|
||||
font-size: 0.875rem;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
white-space: nowrap;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.results-area {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 3rem 1rem;
|
||||
color: var(--p-text-muted-color);
|
||||
gap: 0.75rem;
|
||||
|
||||
i {
|
||||
font-size: 2.5rem;
|
||||
}
|
||||
|
||||
p {
|
||||
margin: 0;
|
||||
font-size: 0.9375rem;
|
||||
}
|
||||
}
|
||||
|
||||
.groups-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
|
||||
.duplicate-group {
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
|
||||
.group-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
padding: 0.5rem 0.75rem;
|
||||
border-bottom: 1px solid var(--border-color);
|
||||
|
||||
.group-label {
|
||||
font-weight: 600;
|
||||
font-size: 0.8125rem;
|
||||
color: var(--p-text-muted-color);
|
||||
}
|
||||
|
||||
.group-actions {
|
||||
margin-left: auto;
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
}
|
||||
|
||||
.group-books {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
}
|
||||
|
||||
.book-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
padding: 0.625rem 0.75rem;
|
||||
cursor: pointer;
|
||||
transition: background-color 0.1s;
|
||||
|
||||
&:not(:last-child) {
|
||||
border-bottom: 1px solid var(--border-color);
|
||||
}
|
||||
|
||||
&:hover {
|
||||
background: var(--p-content-hover-background);
|
||||
}
|
||||
|
||||
&.selected-target {
|
||||
background: var(--p-highlight-background);
|
||||
}
|
||||
|
||||
.book-cover {
|
||||
width: 36px;
|
||||
height: 52px;
|
||||
flex-shrink: 0;
|
||||
border-radius: 3px;
|
||||
object-fit: cover;
|
||||
background: var(--p-surface-200);
|
||||
}
|
||||
|
||||
.book-info {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.0625rem;
|
||||
|
||||
.book-title {
|
||||
font-weight: 600;
|
||||
font-size: 0.875rem;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.book-authors {
|
||||
font-size: 0.8125rem;
|
||||
color: var(--p-text-muted-color);
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.book-formats {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.25rem;
|
||||
margin-top: 0.125rem;
|
||||
|
||||
.format-badge {
|
||||
display: inline-block;
|
||||
font-size: 0.625rem;
|
||||
font-weight: 700;
|
||||
padding: 0.0625rem 0.3125rem;
|
||||
border-radius: 3px;
|
||||
background: var(--p-primary-100);
|
||||
color: var(--p-primary-700);
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.02em;
|
||||
}
|
||||
|
||||
.file-count {
|
||||
font-size: 0.75rem;
|
||||
color: var(--p-text-muted-color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.book-select {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.375rem;
|
||||
flex-shrink: 0;
|
||||
|
||||
.target-label {
|
||||
font-size: 0.6875rem;
|
||||
color: var(--p-primary-color);
|
||||
text-transform: uppercase;
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.03em;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.help-text {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 0.5rem;
|
||||
padding: 0.625rem 0.75rem;
|
||||
font-size: 0.8125rem;
|
||||
color: var(--p-text-muted-color);
|
||||
background: var(--p-content-hover-background);
|
||||
border-radius: 6px;
|
||||
line-height: 1.4;
|
||||
|
||||
i {
|
||||
flex-shrink: 0;
|
||||
margin-top: 0.125rem;
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
}
|
||||
|
||||
:host-context(.p-dark) {
|
||||
.book-row .book-cover {
|
||||
background: var(--p-surface-700);
|
||||
}
|
||||
|
||||
.book-row .book-formats .format-badge {
|
||||
background: rgba(var(--p-primary-500-rgb, 99, 102, 241), 0.15);
|
||||
color: var(--p-primary-400);
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 640px) {
|
||||
.action-bar {
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
|
||||
.action-bar-right {
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
}
|
||||
|
||||
.duplicate-group .group-header {
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
}
|
||||
+312
@@ -0,0 +1,312 @@
|
||||
import {Component, inject, OnDestroy, OnInit} from '@angular/core';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {DynamicDialogConfig, DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
import {Button} from 'primeng/button';
|
||||
import {Checkbox} from 'primeng/checkbox';
|
||||
import {RadioButton} from 'primeng/radiobutton';
|
||||
import {SelectButton} from 'primeng/selectbutton';
|
||||
import {ProgressBar} from 'primeng/progressbar';
|
||||
import {Tag} from 'primeng/tag';
|
||||
import {Paginator} from 'primeng/paginator';
|
||||
import {Subject, takeUntil} from 'rxjs';
|
||||
import {BookFileService} from '../../service/book-file.service';
|
||||
import {Book, DuplicateDetectionRequest, DuplicateGroup} from '../../model/book.model';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {TranslocoDirective, TranslocoPipe, TranslocoService} from '@jsverse/transloco';
|
||||
import {UrlHelperService} from '../../../../shared/service/url-helper.service';
|
||||
|
||||
type PresetMode = 'strict' | 'balanced' | 'aggressive' | 'custom';
|
||||
|
||||
interface DisplayGroup extends DuplicateGroup {
|
||||
selectedTargetBookId: number;
|
||||
dismissed: boolean;
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'app-duplicate-merger',
|
||||
standalone: true,
|
||||
imports: [
|
||||
FormsModule,
|
||||
Button,
|
||||
Checkbox,
|
||||
RadioButton,
|
||||
SelectButton,
|
||||
ProgressBar,
|
||||
Tag,
|
||||
Paginator,
|
||||
TranslocoDirective,
|
||||
TranslocoPipe,
|
||||
],
|
||||
templateUrl: './duplicate-merger.component.html',
|
||||
styleUrls: ['./duplicate-merger.component.scss']
|
||||
})
|
||||
export class DuplicateMergerComponent implements OnInit, OnDestroy {
|
||||
libraryId!: number;
|
||||
presetMode: PresetMode = 'balanced';
|
||||
showAdvanced = false;
|
||||
|
||||
matchByIsbn = true;
|
||||
matchByExternalId = true;
|
||||
matchByTitleAuthor = true;
|
||||
matchByDirectory = false;
|
||||
matchByFilename = false;
|
||||
|
||||
isScanning = false;
|
||||
isMerging = false;
|
||||
hasScanned = false;
|
||||
deleteSourceBooks = true;
|
||||
mergeProgress = 0;
|
||||
mergeTotal = 0;
|
||||
|
||||
groups: DisplayGroup[] = [];
|
||||
presetOptions: { label: string; value: PresetMode }[] = [];
|
||||
|
||||
pageFirst = 0;
|
||||
pageSize = 20;
|
||||
|
||||
private destroy$ = new Subject<void>();
|
||||
private readonly bookFileService = inject(BookFileService);
|
||||
private readonly messageService = inject(MessageService);
|
||||
private readonly dialogRef = inject(DynamicDialogRef);
|
||||
private readonly config = inject(DynamicDialogConfig);
|
||||
private readonly t = inject(TranslocoService);
|
||||
readonly urlHelper = inject(UrlHelperService);
|
||||
|
||||
ngOnInit(): void {
|
||||
this.libraryId = this.config.data.libraryId;
|
||||
this.presetOptions = [
|
||||
{label: this.t.translate('book.duplicateMerger.presetStrict'), value: 'strict'},
|
||||
{label: this.t.translate('book.duplicateMerger.presetBalanced'), value: 'balanced'},
|
||||
{label: this.t.translate('book.duplicateMerger.presetAggressive'), value: 'aggressive'},
|
||||
{label: this.t.translate('book.duplicateMerger.presetCustom'), value: 'custom'},
|
||||
];
|
||||
this.applyPreset('balanced');
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.destroy$.next();
|
||||
this.destroy$.complete();
|
||||
}
|
||||
|
||||
onPresetChange(): void {
|
||||
if (this.presetMode !== 'custom') {
|
||||
this.applyPreset(this.presetMode);
|
||||
}
|
||||
}
|
||||
|
||||
onSignalToggle(): void {
|
||||
this.presetMode = 'custom';
|
||||
}
|
||||
|
||||
applyPreset(mode: PresetMode): void {
|
||||
switch (mode) {
|
||||
case 'strict':
|
||||
this.matchByIsbn = true;
|
||||
this.matchByExternalId = true;
|
||||
this.matchByTitleAuthor = false;
|
||||
this.matchByDirectory = false;
|
||||
this.matchByFilename = false;
|
||||
break;
|
||||
case 'balanced':
|
||||
this.matchByIsbn = true;
|
||||
this.matchByExternalId = true;
|
||||
this.matchByTitleAuthor = true;
|
||||
this.matchByDirectory = false;
|
||||
this.matchByFilename = false;
|
||||
break;
|
||||
case 'aggressive':
|
||||
this.matchByIsbn = true;
|
||||
this.matchByExternalId = true;
|
||||
this.matchByTitleAuthor = true;
|
||||
this.matchByDirectory = true;
|
||||
this.matchByFilename = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
scan(): void {
|
||||
this.isScanning = true;
|
||||
this.hasScanned = false;
|
||||
this.groups = [];
|
||||
this.pageFirst = 0;
|
||||
|
||||
const request: DuplicateDetectionRequest = {
|
||||
libraryId: this.libraryId,
|
||||
matchByIsbn: this.matchByIsbn,
|
||||
matchByExternalId: this.matchByExternalId,
|
||||
matchByTitleAuthor: this.matchByTitleAuthor,
|
||||
matchByDirectory: this.matchByDirectory,
|
||||
matchByFilename: this.matchByFilename,
|
||||
};
|
||||
|
||||
this.bookFileService.findDuplicates(request).pipe(
|
||||
takeUntil(this.destroy$)
|
||||
).subscribe({
|
||||
next: (groups) => {
|
||||
this.groups = groups.map(g => ({
|
||||
...g,
|
||||
selectedTargetBookId: g.suggestedTargetBookId,
|
||||
dismissed: false,
|
||||
}));
|
||||
this.isScanning = false;
|
||||
this.hasScanned = true;
|
||||
},
|
||||
error: (err) => {
|
||||
this.isScanning = false;
|
||||
this.hasScanned = true;
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('book.duplicateMerger.toast.scanFailedSummary'),
|
||||
detail: err?.error?.message || this.t.translate('book.duplicateMerger.toast.scanFailedDetail'),
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
get activeGroups(): DisplayGroup[] {
|
||||
return this.groups.filter(g => !g.dismissed);
|
||||
}
|
||||
|
||||
get pagedGroups(): DisplayGroup[] {
|
||||
return this.activeGroups.slice(this.pageFirst, this.pageFirst + this.pageSize);
|
||||
}
|
||||
|
||||
get canScan(): boolean {
|
||||
return !this.isScanning && !this.isMerging &&
|
||||
(this.matchByIsbn || this.matchByExternalId || this.matchByTitleAuthor ||
|
||||
this.matchByDirectory || this.matchByFilename);
|
||||
}
|
||||
|
||||
onPageChange(event: any): void {
|
||||
this.pageFirst = event.first;
|
||||
this.pageSize = event.rows;
|
||||
}
|
||||
|
||||
getBookFormats(book: Book): string[] {
|
||||
const formats: string[] = [];
|
||||
if (book.primaryFile?.bookType) {
|
||||
formats.push(book.primaryFile.bookType);
|
||||
}
|
||||
if (book.alternativeFormats) {
|
||||
for (const alt of book.alternativeFormats) {
|
||||
if (alt.bookType) {
|
||||
formats.push(alt.bookType);
|
||||
}
|
||||
}
|
||||
}
|
||||
return formats;
|
||||
}
|
||||
|
||||
getFileCount(book: Book): number {
|
||||
let count = book.primaryFile ? 1 : 0;
|
||||
count += book.alternativeFormats?.length ?? 0;
|
||||
return count;
|
||||
}
|
||||
|
||||
getMatchReasonLabel(reason: string): string {
|
||||
return this.t.translate(`book.duplicateMerger.reason.${reason}`);
|
||||
}
|
||||
|
||||
getMatchReasonSeverity(reason: string): "success" | "info" | "warn" | "danger" | "secondary" | "contrast" {
|
||||
switch (reason) {
|
||||
case 'ISBN':
|
||||
case 'EXTERNAL_ID':
|
||||
return 'success';
|
||||
case 'TITLE_AUTHOR':
|
||||
return 'info';
|
||||
case 'DIRECTORY':
|
||||
return 'warn';
|
||||
case 'FILENAME':
|
||||
return 'secondary';
|
||||
default:
|
||||
return 'info';
|
||||
}
|
||||
}
|
||||
|
||||
dismissGroup(group: DisplayGroup): void {
|
||||
group.dismissed = true;
|
||||
if (this.pagedGroups.length === 0 && this.pageFirst > 0) {
|
||||
this.pageFirst = Math.max(0, this.pageFirst - this.pageSize);
|
||||
}
|
||||
}
|
||||
|
||||
async mergeGroup(group: DisplayGroup): Promise<void> {
|
||||
const targetId = group.selectedTargetBookId;
|
||||
const sourceIds = group.books
|
||||
.filter(b => b.id !== targetId)
|
||||
.map(b => b.id);
|
||||
|
||||
if (sourceIds.length === 0) return;
|
||||
|
||||
group.dismissed = true;
|
||||
try {
|
||||
await this.bookFileService.attachBookFiles(targetId, sourceIds, this.deleteSourceBooks)
|
||||
.pipe(takeUntil(this.destroy$))
|
||||
.toPromise();
|
||||
} catch {
|
||||
group.dismissed = false;
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('book.duplicateMerger.toast.mergeFailedSummary'),
|
||||
detail: this.t.translate('book.duplicateMerger.toast.mergeFailedDetail'),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async mergeAll(): Promise<void> {
|
||||
const toMerge = this.activeGroups;
|
||||
if (toMerge.length === 0) return;
|
||||
|
||||
this.isMerging = true;
|
||||
this.mergeTotal = toMerge.length;
|
||||
this.mergeProgress = 0;
|
||||
|
||||
let successCount = 0;
|
||||
let failCount = 0;
|
||||
|
||||
for (const group of toMerge) {
|
||||
const targetId = group.selectedTargetBookId;
|
||||
const sourceIds = group.books
|
||||
.filter(b => b.id !== targetId)
|
||||
.map(b => b.id);
|
||||
|
||||
if (sourceIds.length === 0) {
|
||||
group.dismissed = true;
|
||||
this.mergeProgress++;
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
await this.bookFileService.attachBookFiles(targetId, sourceIds, this.deleteSourceBooks)
|
||||
.pipe(takeUntil(this.destroy$))
|
||||
.toPromise();
|
||||
group.dismissed = true;
|
||||
successCount++;
|
||||
} catch {
|
||||
failCount++;
|
||||
}
|
||||
this.mergeProgress++;
|
||||
}
|
||||
|
||||
this.isMerging = false;
|
||||
|
||||
if (successCount > 0) {
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: this.t.translate('book.duplicateMerger.toast.mergeSuccessSummary'),
|
||||
detail: this.t.translate('book.duplicateMerger.toast.mergeSuccessDetail', {count: successCount}),
|
||||
});
|
||||
}
|
||||
if (failCount > 0) {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('book.duplicateMerger.toast.mergeFailedSummary'),
|
||||
detail: this.t.translate('book.duplicateMerger.toast.mergePartialDetail', {success: successCount, failed: failCount}),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
closeDialog(): void {
|
||||
this.dialogRef.close();
|
||||
}
|
||||
}
|
||||
@@ -381,13 +381,6 @@ export interface BookDeletionResponse {
|
||||
failedFileDeletions: number[];
|
||||
}
|
||||
|
||||
export interface BookSyncResponse {
|
||||
books: Book[];
|
||||
deletedIds: number[];
|
||||
syncTimestamp: string;
|
||||
totalBookCount: number;
|
||||
}
|
||||
|
||||
export enum ReadStatus {
|
||||
UNREAD = 'UNREAD',
|
||||
READING = 'READING',
|
||||
@@ -424,3 +417,18 @@ export interface PersonalRatingUpdateResponse {
|
||||
bookId: number;
|
||||
personalRating?: number;
|
||||
}
|
||||
|
||||
export interface DuplicateDetectionRequest {
|
||||
libraryId: number;
|
||||
matchByIsbn: boolean;
|
||||
matchByExternalId: boolean;
|
||||
matchByTitleAuthor: boolean;
|
||||
matchByDirectory: boolean;
|
||||
matchByFilename: boolean;
|
||||
}
|
||||
|
||||
export interface DuplicateGroup {
|
||||
suggestedTargetBookId: number;
|
||||
matchReason: string;
|
||||
books: Book[];
|
||||
}
|
||||
|
||||
@@ -1,76 +0,0 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {openDB, IDBPDatabase} from 'idb';
|
||||
import {Book} from '../model/book.model';
|
||||
|
||||
const DB_NAME = 'booklore-books';
|
||||
const DB_VERSION = 1;
|
||||
const BOOKS_STORE = 'books';
|
||||
const META_STORE = 'meta';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class BookCacheService {
|
||||
|
||||
private dbPromise: Promise<IDBPDatabase> = openDB(DB_NAME, DB_VERSION, {
|
||||
upgrade(db) {
|
||||
if (!db.objectStoreNames.contains(BOOKS_STORE)) {
|
||||
db.createObjectStore(BOOKS_STORE, {keyPath: 'id'});
|
||||
}
|
||||
if (!db.objectStoreNames.contains(META_STORE)) {
|
||||
db.createObjectStore(META_STORE);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
async getAll(): Promise<Book[]> {
|
||||
const db = await this.dbPromise;
|
||||
return db.getAll(BOOKS_STORE);
|
||||
}
|
||||
|
||||
async putAll(books: Book[]): Promise<void> {
|
||||
const db = await this.dbPromise;
|
||||
const tx = db.transaction(BOOKS_STORE, 'readwrite');
|
||||
for (const book of books) {
|
||||
tx.store.put(book);
|
||||
}
|
||||
await tx.done;
|
||||
}
|
||||
|
||||
async put(book: Book): Promise<void> {
|
||||
const db = await this.dbPromise;
|
||||
await db.put(BOOKS_STORE, book);
|
||||
}
|
||||
|
||||
async delete(id: number): Promise<void> {
|
||||
const db = await this.dbPromise;
|
||||
await db.delete(BOOKS_STORE, id);
|
||||
}
|
||||
|
||||
async deleteMany(ids: number[]): Promise<void> {
|
||||
const db = await this.dbPromise;
|
||||
const tx = db.transaction(BOOKS_STORE, 'readwrite');
|
||||
for (const id of ids) {
|
||||
tx.store.delete(id);
|
||||
}
|
||||
await tx.done;
|
||||
}
|
||||
|
||||
async getSyncTimestamp(): Promise<string | null> {
|
||||
const db = await this.dbPromise;
|
||||
return (await db.get(META_STORE, 'syncTimestamp')) ?? null;
|
||||
}
|
||||
|
||||
async setSyncTimestamp(ts: string): Promise<void> {
|
||||
const db = await this.dbPromise;
|
||||
await db.put(META_STORE, ts, 'syncTimestamp');
|
||||
}
|
||||
|
||||
async clear(): Promise<void> {
|
||||
const db = await this.dbPromise;
|
||||
const tx = db.transaction([BOOKS_STORE, META_STORE], 'readwrite');
|
||||
tx.objectStore(BOOKS_STORE).clear();
|
||||
tx.objectStore(META_STORE).clear();
|
||||
await tx.done;
|
||||
}
|
||||
}
|
||||
@@ -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} from '../model/book.model';
|
||||
import {AdditionalFile, AdditionalFileType, Book, 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,10 @@ export class BookFileService {
|
||||
this.fileDownloadService.downloadFile(downloadUrl, additionalFile?.fileName ?? 'file');
|
||||
}
|
||||
|
||||
findDuplicates(request: DuplicateDetectionRequest): Observable<DuplicateGroup[]> {
|
||||
return this.http.post<DuplicateGroup[]>(`${this.url}/duplicates`, request);
|
||||
}
|
||||
|
||||
attachBookFiles(targetBookId: number, sourceBookIds: number[], deleteSourceBooks: boolean): Observable<Book> {
|
||||
return this.http.post<Book>(`${this.url}/${targetBookId}/attach-file`, {
|
||||
sourceBookIds,
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import {inject, Injectable} from '@angular/core';
|
||||
import {BookStateService} from './book-state.service';
|
||||
import {BookCacheService} from './book-cache.service';
|
||||
import {Book, BookMetadata} from '../model/book.model';
|
||||
|
||||
@Injectable({
|
||||
@@ -8,7 +7,6 @@ import {Book, BookMetadata} from '../model/book.model';
|
||||
})
|
||||
export class BookSocketService {
|
||||
private bookStateService = inject(BookStateService);
|
||||
private bookCacheService = inject(BookCacheService);
|
||||
|
||||
handleNewlyCreatedBook(book: Book): void {
|
||||
const currentState = this.bookStateService.getCurrentBookState();
|
||||
@@ -20,14 +18,12 @@ export class BookSocketService {
|
||||
updatedBooks.push(book);
|
||||
}
|
||||
this.bookStateService.updateBookState({...currentState, books: updatedBooks});
|
||||
this.bookCacheService.put(book);
|
||||
}
|
||||
|
||||
handleRemovedBookIds(removedBookIds: number[]): void {
|
||||
const currentState = this.bookStateService.getCurrentBookState();
|
||||
const filteredBooks = (currentState.books || []).filter(book => !removedBookIds.includes(book.id));
|
||||
this.bookStateService.updateBookState({...currentState, books: filteredBooks});
|
||||
this.bookCacheService.deleteMany(removedBookIds);
|
||||
}
|
||||
|
||||
handleBookUpdate(updatedBook: Book): void {
|
||||
@@ -36,7 +32,6 @@ export class BookSocketService {
|
||||
book.id === updatedBook.id ? updatedBook : book
|
||||
);
|
||||
this.bookStateService.updateBookState({...currentState, books: updatedBooks});
|
||||
this.bookCacheService.put(updatedBook);
|
||||
}
|
||||
|
||||
handleMultipleBookUpdates(updatedBooks: Book[]): void {
|
||||
@@ -50,7 +45,6 @@ export class BookSocketService {
|
||||
);
|
||||
|
||||
this.bookStateService.updateBookState({...currentState, books: mergedBooks});
|
||||
this.bookCacheService.putAll(updatedBooks);
|
||||
}
|
||||
|
||||
handleBookMetadataUpdate(bookId: number, updatedMetadata: BookMetadata): void {
|
||||
@@ -59,30 +53,18 @@ export class BookSocketService {
|
||||
return book.id === bookId ? {...book, metadata: updatedMetadata} : book;
|
||||
});
|
||||
this.bookStateService.updateBookState({...currentState, books: updatedBooks});
|
||||
|
||||
// Mirror metadata update to cache
|
||||
const updatedBook = updatedBooks.find(b => b.id === bookId);
|
||||
if (updatedBook) {
|
||||
this.bookCacheService.put(updatedBook);
|
||||
}
|
||||
}
|
||||
|
||||
handleMultipleBookCoverPatches(patches: { id: number; coverUpdatedOn: string }[]): void {
|
||||
if (!patches || patches.length === 0) return;
|
||||
const currentState = this.bookStateService.getCurrentBookState();
|
||||
const books = currentState.books || [];
|
||||
const patchedBooks: Book[] = [];
|
||||
patches.forEach(p => {
|
||||
const index = books.findIndex(b => b.id === p.id);
|
||||
if (index !== -1 && books[index].metadata) {
|
||||
books[index].metadata.coverUpdatedOn = p.coverUpdatedOn;
|
||||
patchedBooks.push(books[index]);
|
||||
}
|
||||
});
|
||||
this.bookStateService.updateBookState({...currentState, books});
|
||||
if (patchedBooks.length > 0) {
|
||||
this.bookCacheService.putAll(patchedBooks);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import {inject, Injectable} from '@angular/core';
|
||||
import {first, from, Observable, of, throwError} from 'rxjs';
|
||||
import {first, Observable, of, throwError} from 'rxjs';
|
||||
import {HttpClient, HttpParams} from '@angular/common/http';
|
||||
import {catchError, distinctUntilChanged, filter, finalize, map, shareReplay, switchMap, tap} from 'rxjs/operators';
|
||||
import {Book, BookDeletionResponse, BookRecommendation, BookSetting, BookStatusUpdateResponse, BookSyncResponse, BookType, CreatePhysicalBookRequest, PersonalRatingUpdateResponse, ReadStatus} from '../model/book.model';
|
||||
import {catchError, distinctUntilChanged, filter, finalize, map, shareReplay, tap} from 'rxjs/operators';
|
||||
import {Book, BookDeletionResponse, BookRecommendation, BookSetting, BookStatusUpdateResponse, BookType, CreatePhysicalBookRequest, PersonalRatingUpdateResponse, ReadStatus} from '../model/book.model';
|
||||
import {BookState} from '../model/state/book-state.model';
|
||||
import {API_CONFIG} from '../../../core/config/api-config';
|
||||
import {MessageService} from 'primeng/api';
|
||||
@@ -12,7 +12,6 @@ import {Router} from '@angular/router';
|
||||
import {BookStateService} from './book-state.service';
|
||||
import {BookSocketService} from './book-socket.service';
|
||||
import {BookPatchService} from './book-patch.service';
|
||||
import {BookCacheService} from './book-cache.service';
|
||||
import {TranslocoService} from '@jsverse/transloco';
|
||||
|
||||
@Injectable({
|
||||
@@ -29,7 +28,6 @@ export class BookService {
|
||||
private bookStateService = inject(BookStateService);
|
||||
private bookSocketService = inject(BookSocketService);
|
||||
private bookPatchService = inject(BookPatchService);
|
||||
private bookCacheService = inject(BookCacheService);
|
||||
private readonly t = inject(TranslocoService);
|
||||
|
||||
private loading$: Observable<Book[]> | null = null;
|
||||
@@ -41,7 +39,6 @@ export class BookService {
|
||||
if (token === null) {
|
||||
this.bookStateService.resetBookState();
|
||||
this.loading$ = null;
|
||||
this.bookCacheService.clear();
|
||||
} else {
|
||||
const current = this.bookStateService.getCurrentBookState();
|
||||
if (current.loaded && !current.books) {
|
||||
@@ -61,7 +58,7 @@ export class BookService {
|
||||
bookState$ = this.bookStateService.bookState$.pipe(
|
||||
tap(state => {
|
||||
if (!state.loaded && !state.error && !this.loading$) {
|
||||
this.loading$ = this.fetchBooksWithCache().pipe(
|
||||
this.loading$ = this.fetchBooks().pipe(
|
||||
shareReplay(1),
|
||||
finalize(() => (this.loading$ = null))
|
||||
);
|
||||
@@ -74,52 +71,14 @@ export class BookService {
|
||||
return this.bookStateService.getCurrentBookState();
|
||||
}
|
||||
|
||||
private fetchBooksWithCache(): Observable<Book[]> {
|
||||
return from(this.bookCacheService.getAll()).pipe(
|
||||
switchMap(cachedBooks => from(this.bookCacheService.getSyncTimestamp()).pipe(
|
||||
map(syncTs => ({cachedBooks, syncTs}))
|
||||
)),
|
||||
switchMap(({cachedBooks, syncTs}) => {
|
||||
if (cachedBooks.length > 0 && syncTs) {
|
||||
this.bookStateService.updateBookState({
|
||||
books: cachedBooks,
|
||||
loaded: true,
|
||||
error: null,
|
||||
});
|
||||
|
||||
this.deltaSync(syncTs);
|
||||
return of(cachedBooks);
|
||||
}
|
||||
return this.fetchBooksFullAndCache();
|
||||
}),
|
||||
catchError(error => {
|
||||
return this.fetchBooksFullAndCache().pipe(
|
||||
catchError(fetchError => {
|
||||
const curr = this.bookStateService.getCurrentBookState();
|
||||
this.bookStateService.updateBookState({
|
||||
books: curr.books,
|
||||
loaded: true,
|
||||
error: fetchError.message,
|
||||
});
|
||||
throw fetchError;
|
||||
})
|
||||
);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
private fetchBooksFullAndCache(): Observable<Book[]> {
|
||||
return this.http.get<Book[]>(this.url, {observe: 'response'}).pipe(
|
||||
map(response => {
|
||||
const bookList = response.body || [];
|
||||
private fetchBooks(): Observable<Book[]> {
|
||||
return this.http.get<Book[]>(this.url).pipe(
|
||||
map(bookList => {
|
||||
this.bookStateService.updateBookState({
|
||||
books: bookList,
|
||||
loaded: true,
|
||||
error: null,
|
||||
});
|
||||
const serverDate = response.headers.get('Date');
|
||||
const syncTs = serverDate ? new Date(serverDate).toISOString() : new Date().toISOString();
|
||||
this.writeBooksToCache(bookList, syncTs);
|
||||
return bookList;
|
||||
}),
|
||||
catchError(error => {
|
||||
@@ -134,72 +93,14 @@ export class BookService {
|
||||
);
|
||||
}
|
||||
|
||||
private deltaSync(syncTs: string): void {
|
||||
const params = new HttpParams().set('since', syncTs);
|
||||
this.http.get<BookSyncResponse>(`${this.url}/delta`, {params}).pipe(
|
||||
tap(delta => {
|
||||
const currentState = this.bookStateService.getCurrentBookState();
|
||||
let books = [...(currentState.books || [])];
|
||||
|
||||
if (delta.deletedIds?.length) {
|
||||
const deletedSet = new Set(delta.deletedIds);
|
||||
books = books.filter(b => !deletedSet.has(b.id));
|
||||
this.bookCacheService.deleteMany(delta.deletedIds);
|
||||
}
|
||||
|
||||
if (delta.books?.length) {
|
||||
const updatedMap = new Map(delta.books.map(b => [b.id, b]));
|
||||
books = books.map(b => updatedMap.get(b.id) ?? b);
|
||||
const existingIds = new Set(books.map(b => b.id));
|
||||
for (const book of delta.books) {
|
||||
if (!existingIds.has(book.id)) {
|
||||
books.push(book);
|
||||
}
|
||||
}
|
||||
this.bookCacheService.putAll(delta.books);
|
||||
}
|
||||
|
||||
if (delta.totalBookCount !== books.length) {
|
||||
this.refreshBooks();
|
||||
return;
|
||||
}
|
||||
|
||||
this.bookStateService.updateBookState({
|
||||
books,
|
||||
loaded: true,
|
||||
error: null,
|
||||
});
|
||||
|
||||
if (delta.syncTimestamp) {
|
||||
this.bookCacheService.setSyncTimestamp(delta.syncTimestamp);
|
||||
}
|
||||
}),
|
||||
catchError(() => {
|
||||
this.refreshBooks();
|
||||
return of(null);
|
||||
})
|
||||
).subscribe();
|
||||
}
|
||||
|
||||
private writeBooksToCache(books: Book[], syncTimestamp: string): void {
|
||||
this.bookCacheService.clear().then(() => {
|
||||
this.bookCacheService.putAll(books);
|
||||
this.bookCacheService.setSyncTimestamp(syncTimestamp);
|
||||
});
|
||||
}
|
||||
|
||||
refreshBooks(): void {
|
||||
this.http.get<Book[]>(this.url, {observe: 'response'}).pipe(
|
||||
tap(response => {
|
||||
const bookList = response.body || [];
|
||||
this.http.get<Book[]>(this.url).pipe(
|
||||
tap(bookList => {
|
||||
this.bookStateService.updateBookState({
|
||||
books: bookList,
|
||||
loaded: true,
|
||||
error: null,
|
||||
});
|
||||
const serverDate = response.headers.get('Date');
|
||||
const syncTs = serverDate ? new Date(serverDate).toISOString() : new Date().toISOString();
|
||||
this.writeBooksToCache(bookList, syncTs);
|
||||
}),
|
||||
catchError(error => {
|
||||
this.bookStateService.updateBookState({
|
||||
|
||||
@@ -111,6 +111,13 @@ export class LibraryShelfMenuService {
|
||||
}).subscribe();
|
||||
}
|
||||
},
|
||||
{
|
||||
label: this.t.translate('book.shelfMenuService.library.findDuplicates'),
|
||||
icon: 'pi pi-copy',
|
||||
command: () => {
|
||||
this.bookDialogHelperService.openDuplicateMergerDialog(entity?.id as number);
|
||||
}
|
||||
},
|
||||
{
|
||||
separator: true
|
||||
},
|
||||
|
||||
@@ -100,6 +100,7 @@ export class LibraryService {
|
||||
const curr = this.libraryStateSubject.value;
|
||||
const list = curr.libraries?.map(l => (l.id === updated.id ? updated : l)) || [updated];
|
||||
this.libraryStateSubject.next({...curr, libraries: list});
|
||||
this.bookService.refreshBooks();
|
||||
return updated;
|
||||
})
|
||||
);
|
||||
|
||||
@@ -241,7 +241,9 @@ export class LibraryCreatorComponent implements OnInit {
|
||||
};
|
||||
|
||||
if (this.mode === 'edit') {
|
||||
this.libraryService.updateLibrary(library, this.library?.id).subscribe({
|
||||
this.libraryService.updateLibrary(library, this.library?.id).pipe(
|
||||
switchMap(() => this.libraryService.refreshLibrary(this.library!.id!))
|
||||
).subscribe({
|
||||
next: () => {
|
||||
this.messageService.add({severity: 'success', summary: this.t.translate('libraryCreator.creator.toast.updatedSummary'), detail: this.t.translate('libraryCreator.creator.toast.updatedDetail')});
|
||||
this.dynamicDialogRef.close();
|
||||
|
||||
@@ -262,6 +262,7 @@
|
||||
"rescanLibrary": "Re-scan Library",
|
||||
"customFetchMetadata": "Custom Fetch Metadata",
|
||||
"autoFetchMetadata": "Auto Fetch Metadata",
|
||||
"findDuplicates": "Find Duplicates",
|
||||
"deleteLibrary": "Delete Library"
|
||||
},
|
||||
"shelf": {
|
||||
@@ -771,5 +772,48 @@
|
||||
"deselectAll": "Deselect all books",
|
||||
"deleteSelected": "Delete selected books"
|
||||
}
|
||||
},
|
||||
"duplicateMerger": {
|
||||
"title": "Find Duplicates",
|
||||
"description": "Detect and merge duplicate books in this library",
|
||||
"presetStrict": "Strict",
|
||||
"presetBalanced": "Balanced",
|
||||
"presetAggressive": "Aggressive",
|
||||
"presetCustom": "Custom",
|
||||
"advanced": "Advanced",
|
||||
"signalIsbn": "ISBN",
|
||||
"signalExternalId": "External ID",
|
||||
"signalTitleAuthor": "Title + Author",
|
||||
"signalDirectory": "Same Directory",
|
||||
"signalFilename": "Filename",
|
||||
"scan": "Scan",
|
||||
"scanning": "Scanning for duplicates...",
|
||||
"scanPrompt": "Select a detection mode and click Scan to find duplicates.",
|
||||
"noDuplicates": "No duplicates found.",
|
||||
"allMerged": "All duplicate groups have been processed.",
|
||||
"deleteSource": "Delete source books",
|
||||
"mergeAll": "Merge All ({{ count }})",
|
||||
"merge": "Merge",
|
||||
"dismiss": "Dismiss",
|
||||
"target": "Target",
|
||||
"helpText": "Each group contains books that appear to be duplicates. Select the target book (the one to keep), then click Merge. The other books' files will be attached to the target as alternative formats.",
|
||||
"groupLabel": "Group {{ index }}",
|
||||
"fileCount": "{{ count }} files",
|
||||
"reason": {
|
||||
"ISBN": "ISBN Match",
|
||||
"EXTERNAL_ID": "External ID Match",
|
||||
"TITLE_AUTHOR": "Title + Author",
|
||||
"DIRECTORY": "Same Directory",
|
||||
"FILENAME": "Filename Match"
|
||||
},
|
||||
"toast": {
|
||||
"scanFailedSummary": "Scan Failed",
|
||||
"scanFailedDetail": "Could not scan for duplicates.",
|
||||
"mergeSuccessSummary": "Merge Complete",
|
||||
"mergeSuccessDetail": "Successfully merged {{ count }} group(s).",
|
||||
"mergeFailedSummary": "Merge Failed",
|
||||
"mergeFailedDetail": "Could not merge this group.",
|
||||
"mergePartialDetail": "{{ success }} merged, {{ failed }} failed."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -262,6 +262,7 @@
|
||||
"rescanLibrary": "Re-escanear biblioteca",
|
||||
"customFetchMetadata": "Obtención personalizada de metadatos",
|
||||
"autoFetchMetadata": "Obtener metadatos automáticamente",
|
||||
"findDuplicates": "Buscar duplicados",
|
||||
"deleteLibrary": "Eliminar biblioteca"
|
||||
},
|
||||
"shelf": {
|
||||
@@ -771,5 +772,48 @@
|
||||
"deselectAll": "Deseleccionar todos los libros",
|
||||
"deleteSelected": "Eliminar libros seleccionados"
|
||||
}
|
||||
},
|
||||
"duplicateMerger": {
|
||||
"title": "Buscar duplicados",
|
||||
"description": "Detectar y fusionar libros duplicados en esta biblioteca",
|
||||
"presetStrict": "Estricto",
|
||||
"presetBalanced": "Equilibrado",
|
||||
"presetAggressive": "Agresivo",
|
||||
"presetCustom": "Personalizado",
|
||||
"advanced": "Avanzado",
|
||||
"signalIsbn": "ISBN",
|
||||
"signalExternalId": "ID externo",
|
||||
"signalTitleAuthor": "Título + Autor",
|
||||
"signalDirectory": "Mismo directorio",
|
||||
"signalFilename": "Nombre de archivo",
|
||||
"scan": "Escanear",
|
||||
"scanning": "Buscando duplicados...",
|
||||
"scanPrompt": "Seleccione un modo de detección y haga clic en Escanear para buscar duplicados.",
|
||||
"noDuplicates": "No se encontraron duplicados.",
|
||||
"allMerged": "Todos los grupos duplicados han sido procesados.",
|
||||
"deleteSource": "Eliminar libros de origen",
|
||||
"mergeAll": "Fusionar todo ({{ count }})",
|
||||
"merge": "Fusionar",
|
||||
"dismiss": "Descartar",
|
||||
"target": "Destino",
|
||||
"helpText": "Cada grupo contiene libros que parecen ser duplicados. Seleccione el libro destino (el que se conserva) y haga clic en Fusionar. Los archivos de los otros libros se adjuntarán al destino como formatos alternativos.",
|
||||
"groupLabel": "Grupo {{ index }}",
|
||||
"fileCount": "{{ count }} archivos",
|
||||
"reason": {
|
||||
"ISBN": "Coincidencia ISBN",
|
||||
"EXTERNAL_ID": "Coincidencia ID externo",
|
||||
"TITLE_AUTHOR": "Título + Autor",
|
||||
"DIRECTORY": "Mismo directorio",
|
||||
"FILENAME": "Coincidencia de nombre"
|
||||
},
|
||||
"toast": {
|
||||
"scanFailedSummary": "Error de escaneo",
|
||||
"scanFailedDetail": "No se pudieron buscar duplicados.",
|
||||
"mergeSuccessSummary": "Fusión completada",
|
||||
"mergeSuccessDetail": "Se fusionaron {{ count }} grupo(s) correctamente.",
|
||||
"mergeFailedSummary": "Error de fusión",
|
||||
"mergeFailedDetail": "No se pudo fusionar este grupo.",
|
||||
"mergePartialDetail": "{{ success }} fusionados, {{ failed }} fallidos."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user