Add koreader sync support for book progress tracking

This commit is contained in:
Aditya Chandel
2025-08-08 09:38:20 -06:00
committed by GitHub
parent fa54fdec34
commit 9ae1c6e2dc
74 changed files with 1826 additions and 179 deletions
@@ -6,7 +6,7 @@
<div class="relative w-[175px] md:w-[250px]">
<img
[attr.src]="urlHelper.getCoverUrl(book?.metadata!.bookId, book?.metadata!.coverUpdatedOn)"
class="rounded-xl w-full object-cover"
class="rounded-lg w-full object-cover"
alt="Cover of {{ book?.metadata!.title }}"
loading="lazy"
/>
@@ -17,19 +17,32 @@
</div>
}
@if (getProgressPercent(book) !== null) {
<div class="absolute bottom-0 left-0 right-0">
<p-progressBar
[value]="getProgressPercent(book)"
[showValue]="false"
[ngClass]="{
'rounded-b-xl': true,
'progress-complete': getProgressPercent(book) === 100,
'progress-incomplete': getProgressPercent(book)! < 100
}"
[style]="{ height: '8px' }">
</p-progressBar>
</div>
@let progress = getProgressPercent(book);
@if (progress !== null) {
<p-progressBar
[value]="progress"
[showValue]="false"
class="cover-progress-bar"
[ngClass]="{
'rounded-b-xl': false,
'progress-complete': progress === 100,
'progress-incomplete': progress < 100
}"
[style]="{ height: '6px' }"
></p-progressBar>
}
@if (getKoProgressPercent(book) !== null) {
<p-progressBar
[value]="getKoProgressPercent(book)"
[showValue]="false"
[ngClass]="[
getProgressPercent(book) == null ? 'cover-progress-bar-ko-only' : 'cover-progress-bar-ko-both',
getKoProgressPercent(book) === 100 ? 'progress-complete-ko' : 'progress-incomplete-ko'
]"
[style]="{ height: '6px' }"
>
</p-progressBar>
}
</div>
</div>
@@ -213,7 +226,7 @@
}
<div class="px-1 md:px-0">
<div class="grid md:grid-cols-3 gap-y-2.5 text-sm pt-2 md:pt-4 pb-2 text-gray-300 max-w-6xl">
<div class="grid md:grid-cols-4 gap-y-2.5 text-sm pt-2 md:pt-4 pb-2 text-gray-300 max-w-7xl">
<p class="whitespace-nowrap max-w-[250px] overflow-hidden text-ellipsis">
<span class="font-bold">Publisher: </span>
@if (book?.metadata?.publisher) {
@@ -226,6 +239,7 @@
</p>
<p><strong>Published:</strong> {{ book?.metadata!.publishedDate || '-' }}</p>
<p><strong>Language:</strong> {{ book?.metadata!.language || '-' }}</p>
<p><strong>File Size:</strong> {{ getFileSizeInMB(book) }}</p>
<p class="whitespace-nowrap flex items-center gap-2">
<span class="font-bold">File Type:</span>
<span
@@ -234,7 +248,40 @@
{{ getFileExtension(book?.filePath) || '-' }}
</span>
</p>
<p><strong>File Size:</strong> {{ getFileSizeInMB(book) }}</p>
<p class="whitespace-nowrap flex items-center">
<span class="font-bold mr-2">BookLore Progress:</span>
<span class="inline-flex items-center">
<span
class="inline-block px-2 py-0.5 rounded-full text-xs font-bold text-white"
[ngClass]="getProgressColorClass(getProgressPercent(book))">
{{ getProgressPercent(book) !== null ? getProgressPercent(book) + '%' : 'N/A' }}
</span>
@if (getProgressPercent(book) !== null) {
<p-button
pTooltip="Reset progress"
tooltipPosition="bottom"
icon="pi pi-refresh"
size="small"
severity="danger"
text
class="ml-1 custom-button-padding"
(onClick)="resetProgress(book, ResetProgressTypes.BOOKLORE)">
</p-button>
}
</span>
</p>
<p class="whitespace-nowrap flex items-center gap-2">
<span class="font-bold">Metadata Match:</span>
@if (book?.metadataMatchScore != null) {
<span
class="inline-block px-2 py-0.5 rounded-lg text-xs font-bold text-gray-200 border"
[ngClass]="getMatchScoreColorClass(book?.metadataMatchScore!)">
{{ (book?.metadataMatchScore!) | number:'1.0-0' }}%
</span>
} @else {
<span>-</span>
}
</p>
<p>
<strong>ISBN:</strong>
@if (book?.metadata?.isbn13 || book?.metadata?.isbn10) {
@@ -262,40 +309,30 @@
</span>
}
</p>
<p class="whitespace-nowrap flex items-center">
<span class="font-bold mr-2">Progress:</span>
<span class="inline-flex items-center">
@if (book?.koreaderProgress && book.koreaderProgress?.percentage != null) {
<p class="whitespace-nowrap flex items-center">
<span class="font-bold mr-2">KOReader Progress:</span>
<span class="inline-flex items-center">
<span
class="inline-block px-2 py-0.5 rounded-full text-xs font-bold text-white"
[ngClass]="getProgressColorClass(getProgressPercent(book))">
{{ getProgressPercent(book) !== null ? getProgressPercent(book) + '%' : 'N/A' }}
[ngClass]="getKoProgressColorClass(getKOReaderPercentage(book))">
{{ getKOReaderPercentage(book) + '%' }}
</span>
@if (getProgressPercent(book) !== null) {
<p-button
pTooltip="Reset progress"
tooltipPosition="bottom"
icon="pi pi-refresh"
size="small"
severity="danger"
text
class="ml-1 custom-button-padding"
(onClick)="resetProgress(book)">
@if (getKOReaderPercentage(book) !== null) {
<p-button
pTooltip="Reset progress"
tooltipPosition="bottom"
icon="pi pi-refresh"
size="small"
severity="danger"
text
class="ml-1 custom-button-padding"
(onClick)="resetProgress(book, ResetProgressTypes.KOREADER)">
</p-button>
}
}
</span>
</p>
<p class="whitespace-nowrap flex items-center gap-2">
<span class="font-bold">Metadata Match:</span>
@if (book?.metadataMatchScore != null) {
<span
class="inline-block px-2 py-0.5 rounded-lg text-xs font-bold text-gray-200 border"
[ngClass]="getMatchScoreColorClass(book?.metadataMatchScore!)">
{{ (book?.metadataMatchScore!) | number:'1.0-0' }}%
</span>
} @else {
<span>-</span>
}
</p>
</p>
}
</div>
<div class="flex items-center gap-2">
@@ -80,10 +80,50 @@
z-index: 3;
}
.cover-progress-bar,
.cover-progress-bar-ko-both,
.cover-progress-bar-ko-only {
position: absolute;
left: 0;
right: 0;
z-index: 2;
pointer-events: none;
}
.cover-progress-bar {
bottom: 0;
}
.cover-progress-bar-ko-both {
bottom: 0;
height: 12px;
z-index: 3;
}
.cover-progress-bar-ko-only {
bottom: 0;
}
::ng-deep .p-inputchips {
width: 100%;
}
::ng-deep .progress-incomplete .p-progressbar-value {
background-color: #3b82f6;
}
::ng-deep .progress-complete .p-progressbar-value {
background-color: #22c55e;
}
::ng-deep .progress-incomplete-ko .p-progressbar-value {
background-color: #fbbf24;
}
::ng-deep .progress-complete-ko .p-progressbar-value {
background-color: #8b5cf6;
}
::ng-deep .custom-button-padding .p-button {
padding-block: 0rem !important;
}
@@ -28,6 +28,7 @@ import {filter, map, switchMap, take, tap} from 'rxjs/operators';
import {Menu} from 'primeng/menu';
import {InfiniteScrollDirective} from 'ngx-infinite-scroll';
import {BookCardLiteComponent} from '../../../book/components/book-card-lite/book-card-lite-component';
import {ResetProgressType, ResetProgressTypes} from '../../../shared/constants/reset-progress-type';
@Component({
selector: 'app-metadata-viewer',
@@ -74,6 +75,7 @@ export class MetadataViewerComponent implements OnInit, OnChanges {
{value: ReadStatus.PARTIALLY_READ, label: 'Partially Read'},
{value: ReadStatus.ABANDONED, label: 'Abandoned'},
{value: ReadStatus.WONT_READ, label: 'Won\'t Read'},
{value: ReadStatus.UNSET, label: 'Unset'},
];
ngOnInit(): void {
@@ -301,7 +303,7 @@ export class MetadataViewerComponent implements OnInit, OnChanges {
});
}
resetProgress(book: Book): void {
resetProgress(book: Book, type: ResetProgressType): void {
this.confirmationService.confirm({
message: `Reset reading progress for "${book.metadata?.title}"?`,
header: 'Confirm Reset',
@@ -310,7 +312,7 @@ export class MetadataViewerComponent implements OnInit, OnChanges {
rejectLabel: 'Cancel',
acceptButtonStyleClass: 'p-button-danger',
accept: () => {
this.bookService.resetProgress(book.id).subscribe({
this.bookService.resetProgress(book.id, type).subscribe({
next: () => {
this.messageService.add({
severity: 'success',
@@ -429,11 +431,24 @@ export class MetadataViewerComponent implements OnInit, OnChanges {
return sizeKb != null ? `${(sizeKb / 1024).toFixed(2)} MB` : '-';
}
getProgressPercent(book: Book | null): number | undefined {
if (!book) return;
return book.bookType === 'PDF' ? book.pdfProgress?.percentage
: book.bookType === 'CBX' ? book.cbxProgress?.percentage
: book.epubProgress?.percentage;
getProgressPercent(book: Book): number | null {
if (book.epubProgress?.percentage != null) {
return book.epubProgress.percentage;
}
if (book.pdfProgress?.percentage != null) {
return book.pdfProgress.percentage;
}
if (book.cbxProgress?.percentage != null) {
return book.cbxProgress.percentage;
}
return null;
}
getKoProgressPercent(book: Book): number | null {
if (book.koreaderProgress?.percentage != null) {
return book.koreaderProgress.percentage;
}
return null;
}
getFileExtension(filePath?: string): string | null {
@@ -520,6 +535,16 @@ export class MetadataViewerComponent implements OnInit, OnChanges {
return 'bg-blue-500';
}
getKoProgressColorClass(progress: number | null | undefined): string {
if (progress == null) return 'bg-gray-600';
return 'bg-amber-500';
}
getKOReaderPercentage(book: Book): number | null {
const p = book?.koreaderProgress?.percentage;
return p != null ? Math.round(p * 10) / 10 : null;
}
getRatingTooltip(book: Book, source: 'amazon' | 'goodreads' | 'hardcover'): string {
const meta = book?.metadata;
if (!meta) return '';
@@ -566,4 +591,6 @@ export class MetadataViewerComponent implements OnInit, OnChanges {
day: 'numeric'
});
}
protected readonly ResetProgressTypes = ResetProgressTypes;
}