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
@@ -1,7 +1,7 @@
<div class="book-card"
[class.selected]="isSelected"
(mouseover)="isHovered = true"
(mouseout)="isHovered = false">
[class.selected]="isSelected"
(mouseover)="isHovered = true"
(mouseout)="isHovered = false">
<div class="cover-container" [ngClass]="{ 'shimmer': !isImageLoaded, 'center-info-btn': readButtonHidden }">
<div
@@ -16,7 +16,7 @@
[class.loaded]="isImageLoaded"
alt="Cover of {{ book.metadata?.title }}"
loading="lazy"
(load)="onImageLoad()" />
(load)="onImageLoad()"/>
</div>
@if (book.metadata?.seriesNumber != null) {
@@ -52,6 +52,16 @@
[ngClass]="{ 'progress-complete': progressPercentage === 100, 'progress-incomplete': progressPercentage < 100 }">
</p-progressBar>
}
@if (koProgressPercentage !== null) {
<p-progressBar
[value]="koProgressPercentage"
[showValue]="false"
[ngClass]="[
progressPercentage == null ? 'cover-progress-bar-ko-only' : 'cover-progress-bar-ko-both',
koProgressPercentage === 100 ? 'progress-complete-ko' : 'progress-incomplete-ko'
]">
</p-progressBar>
}
</div>
<div [hidden]="bottomBarHidden">
@@ -119,16 +119,29 @@
visibility: visible;
}
.cover-progress-bar {
.cover-progress-bar,
.cover-progress-bar-ko-both,
.cover-progress-bar-ko-only {
position: absolute;
bottom: 0;
left: 0;
right: 0;
height: 5px;
height: 2.5px;
z-index: 1;
opacity: 0.9;
}
.cover-progress-bar {
bottom: 2.5px;
}
.cover-progress-bar-ko-both {
bottom: 0;
}
.cover-progress-bar-ko-only {
bottom: 2.5px;
}
.series-number-overlay {
position: absolute;
top: 4px;
@@ -166,6 +179,14 @@
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 p-progressbar {
--p-progressbar-border-radius: 0 !important;
}
@@ -23,6 +23,7 @@ import {ProgressBar} from 'primeng/progressbar';
import {BookMetadataCenterComponent} from '../../../../metadata/book-metadata-center-component/book-metadata-center.component';
import {takeUntil} from 'rxjs/operators';
import {readStatusLabels} from '../book-filter/book-filter.component';
import {ResetProgressTypes} from '../../../../shared/constants/reset-progress-type';
@Component({
selector: 'app-book-card',
@@ -83,6 +84,16 @@ export class BookCardComponent implements OnInit, OnDestroy {
if (this.book.pdfProgress?.percentage != null) {
return this.book.pdfProgress.percentage;
}
if (this.book.cbxProgress?.percentage != null) {
return this.book.cbxProgress.percentage;
}
return null;
}
get koProgressPercentage(): number | null {
if (this.book.koreaderProgress?.percentage != null) {
return this.book.koreaderProgress.percentage;
}
return null;
}
@@ -266,7 +277,7 @@ export class BookCardComponent implements OnInit, OnDestroy {
if (this.hasEditMetadataPermission()) {
items.push({
label: 'More Actions',
icon: 'pi pi-ellipsis-v',
icon: 'pi pi-ellipsis-h',
items: [
{
label: 'Read Status',
@@ -296,15 +307,15 @@ export class BookCardComponent implements OnInit, OnDestroy {
}))
},
{
label: 'Reset Progress',
label: 'Reset Booklore Progress',
icon: 'pi pi-undo',
command: () => {
this.bookService.resetProgress(this.book.id).subscribe({
this.bookService.resetProgress(this.book.id, ResetProgressTypes.BOOKLORE).subscribe({
next: () => {
this.messageService.add({
severity: 'success',
summary: 'Progress Reset',
detail: 'Reading progress has been reset.',
detail: 'Booklore reading progress has been reset.',
life: 1500
});
},
@@ -312,7 +323,31 @@ export class BookCardComponent implements OnInit, OnDestroy {
this.messageService.add({
severity: 'error',
summary: 'Failed',
detail: 'Could not reset progress.',
detail: 'Could not reset Booklore progress.',
life: 1500
});
}
});
},
},
{
label: 'Reset KOReader Progress',
icon: 'pi pi-undo',
command: () => {
this.bookService.resetProgress(this.book.id, ResetProgressTypes.KOREADER).subscribe({
next: () => {
this.messageService.add({
severity: 'success',
summary: 'Progress Reset',
detail: 'KOReader reading progress has been reset.',
life: 1500
});
},
error: () => {
this.messageService.add({
severity: 'error',
summary: 'Failed',
detail: 'Could not reset KOReader progress.',
life: 1500
});
}
@@ -14,6 +14,7 @@ export interface Book {
epubProgress?: EpubProgress;
pdfProgress?: PdfProgress;
cbxProgress?: CbxProgress;
koreaderProgress?: KoReaderProgress;
filePath?: string;
fileSubPath?: string;
fileName?: string;
@@ -40,6 +41,10 @@ export interface CbxProgress {
percentage: number;
}
export interface KoReaderProgress {
percentage: number;
}
export interface BookMetadata {
bookId: number;
title?: string;
@@ -4,6 +4,7 @@ import {MenuItem} from 'primeng/api';
import {BookService} from './book.service';
import {readStatusLabels} from '../components/book-browser/book-filter/book-filter.component';
import {ReadStatus} from '../model/book.model';
import {ResetProgressTypes} from '../../shared/constants/reset-progress-type';
@Injectable({
providedIn: 'root'
@@ -74,22 +75,55 @@ export class BookMenuService {
}))
},
{
label: 'Reset Progress',
label: 'Reset Booklore Progress',
icon: 'pi pi-undo',
command: () => {
this.confirmationService.confirm({
message: 'Are you sure you want to reset progress for selected books?',
message: 'Are you sure you want to reset Booklore reading progress for selected books?',
header: 'Confirm Reset',
icon: 'pi pi-exclamation-triangle',
acceptLabel: 'Yes',
rejectLabel: 'No',
accept: () => {
this.bookService.resetProgress(Array.from(selectedBooks)).subscribe({
this.bookService.resetProgress(Array.from(selectedBooks), ResetProgressTypes.BOOKLORE).subscribe({
next: () => {
this.messageService.add({
severity: 'success',
summary: 'Progress Reset',
detail: 'Reading progress has been reset.',
detail: 'Booklore reading progress has been reset.',
life: 1500
});
},
error: () => {
this.messageService.add({
severity: 'error',
summary: 'Failed',
detail: 'Could not reset progress.',
life: 1500
});
}
});
}
});
}
},
{
label: 'Reset KOReader Progress',
icon: 'pi pi-undo',
command: () => {
this.confirmationService.confirm({
message: 'Are you sure you want to reset KOReader reading progress for selected books?',
header: 'Confirm Reset',
icon: 'pi pi-exclamation-triangle',
acceptLabel: 'Yes',
rejectLabel: 'No',
accept: () => {
this.bookService.resetProgress(Array.from(selectedBooks), ResetProgressTypes.KOREADER).subscribe({
next: () => {
this.messageService.add({
severity: 'success',
summary: 'Progress Reset',
detail: 'KOReader reading progress has been reset.',
life: 1500
});
},
@@ -8,6 +8,7 @@ import {API_CONFIG} from '../../config/api-config';
import {FetchMetadataRequest} from '../../metadata/model/request/fetch-metadata-request.model';
import {MetadataRefreshRequest} from '../../metadata/model/request/metadata-refresh-request.model';
import {MessageService} from 'primeng/api';
import {ResetProgressType, ResetProgressTypes} from '../../shared/constants/reset-progress-type';
@Injectable({
providedIn: 'root',
@@ -401,9 +402,10 @@ export class BookService {
);
}
resetProgress(bookIds: number | number[]): Observable<Book[]> {
resetProgress(bookIds: number | number[], type: ResetProgressType): Observable<Book[]> {
const ids = Array.isArray(bookIds) ? bookIds : [bookIds];
return this.http.post<Book[]>(`${this.url}/reset-progress`, ids).pipe(
const params = new HttpParams().set('type', ResetProgressTypes[type]);
return this.http.post<Book[]>(`${this.url}/reset-progress`, ids, {params}).pipe(
tap(updatedBooks => updatedBooks.forEach(book => this.handleBookUpdate(book)))
);
}
@@ -412,16 +414,11 @@ export class BookService {
const ids = Array.isArray(bookIds) ? bookIds : [bookIds];
return this.http.put<Book[]>(`${this.url}/read-status`, {ids, status}).pipe(
tap(updatedBooks => {
// Update the books in the state with the actual response from the API
updatedBooks.forEach(updatedBook => this.handleBookUpdate(updatedBook));
})
);
}
getMagicShelfBookCount(number: number) {
}
/*------------------ All the websocket handlers go below ------------------*/