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
@@ -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 ------------------*/