Introduce a new eBook reader with support for EPUB, MOBI, AZW3, and FB2 formats (#2258)
Co-authored-by: acx10 <acx10@users.noreply.github.com>
This commit is contained in:
@@ -68,12 +68,10 @@ describe('BookPatchService', () => {
|
||||
|
||||
it('should save EPUB progress', () => {
|
||||
httpMock.post.mockReturnValue(of(void 0));
|
||||
service.saveEpubProgress(2, 'cfi123', 0.8).subscribe(result => {
|
||||
expect(result).toBeUndefined();
|
||||
expect(httpMock.post).toHaveBeenCalledWith(expect.stringContaining('/progress'), {
|
||||
bookId: 2,
|
||||
epubProgress: {cfi: 'cfi123', percentage: 0.8}
|
||||
});
|
||||
service.saveEpubProgress(2, 'cfi123', 'href123', 0.8);
|
||||
expect(httpMock.post).toHaveBeenCalledWith(expect.stringContaining('/progress'), {
|
||||
bookId: 2,
|
||||
epubProgress: {cfi: 'cfi123', href: 'href123', percentage: 0.8}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import {inject, Injectable} from '@angular/core';
|
||||
import {HttpClient, HttpParams} from '@angular/common/http';
|
||||
import {Observable} from 'rxjs';
|
||||
import {tap} from 'rxjs/operators';
|
||||
import {Observable, Subject} from 'rxjs';
|
||||
import {distinctUntilChanged, exhaustMap, share, tap} from 'rxjs/operators';
|
||||
import {Book, ReadStatus} from '../model/book.model';
|
||||
import {BookStateService} from './book-state.service';
|
||||
import {API_CONFIG} from '../../../core/config/api-config';
|
||||
@@ -17,6 +17,33 @@ export class BookPatchService {
|
||||
private http = inject(HttpClient);
|
||||
private bookStateService = inject(BookStateService);
|
||||
|
||||
private epubProgressSubject = new Subject<{ bookId: number; cfi: string; href: string; percentage: number }>();
|
||||
|
||||
private epubProgress$ = this.epubProgressSubject.pipe(
|
||||
distinctUntilChanged((prev, curr) =>
|
||||
prev.bookId === curr.bookId &&
|
||||
prev.cfi === curr.cfi &&
|
||||
prev.href === curr.href &&
|
||||
prev.percentage === curr.percentage
|
||||
),
|
||||
exhaustMap(payload => {
|
||||
const body = {
|
||||
bookId: payload.bookId,
|
||||
epubProgress: {
|
||||
cfi: payload.cfi,
|
||||
href: payload.href,
|
||||
percentage: payload.percentage
|
||||
}
|
||||
};
|
||||
return this.http.post<void>(`${this.url}/progress`, body);
|
||||
}),
|
||||
share()
|
||||
);
|
||||
|
||||
constructor() {
|
||||
this.epubProgress$.subscribe();
|
||||
}
|
||||
|
||||
updateBookShelves(bookIds: Set<number | undefined>, shelvesToAssign: Set<number | null | undefined>, shelvesToUnassign: Set<number | null | undefined>): Observable<Book[]> {
|
||||
const requestPayload = {
|
||||
bookIds: Array.from(bookIds),
|
||||
@@ -49,15 +76,8 @@ export class BookPatchService {
|
||||
return this.http.post<void>(`${this.url}/progress`, body);
|
||||
}
|
||||
|
||||
saveEpubProgress(bookId: number, cfi: string, percentage: number): Observable<void> {
|
||||
const body = {
|
||||
bookId: bookId,
|
||||
epubProgress: {
|
||||
cfi: cfi,
|
||||
percentage: percentage
|
||||
}
|
||||
};
|
||||
return this.http.post<void>(`${this.url}/progress`, body);
|
||||
saveEpubProgress(bookId: number, cfi: string, href: string, percentage: number): void {
|
||||
this.epubProgressSubject.next({bookId, cfi, href, percentage});
|
||||
}
|
||||
|
||||
saveCbxProgress(bookId: number, page: number, percentage: number): Observable<void> {
|
||||
@@ -197,4 +217,3 @@ export class BookPatchService {
|
||||
this.bookStateService.updateBookState({...currentState, books: updatedBooks});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -329,12 +329,6 @@ describe('BookService', () => {
|
||||
expect(result).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should save epub progress', async () => {
|
||||
bookPatchServiceMock.saveEpubProgress.mockReturnValue(of(void 0));
|
||||
const result = await firstValueFrom(service.saveEpubProgress(1, 'cfi', 0.5));
|
||||
expect(result).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should save cbx progress', async () => {
|
||||
bookPatchServiceMock.saveCbxProgress.mockReturnValue(of(void 0));
|
||||
const result = await firstValueFrom(service.saveCbxProgress(1, 2, 0.5));
|
||||
|
||||
@@ -259,8 +259,8 @@ export class BookService {
|
||||
? reader === 'ngx'
|
||||
? 'pdf-reader'
|
||||
: 'cbx-reader'
|
||||
: book.bookType === 'EPUB'
|
||||
? 'epub-reader'
|
||||
: book.bookType === 'EPUB' || book.bookType === 'FB2' || book.bookType === 'MOBI' || book.bookType === 'AZW3'
|
||||
? 'ebook-reader'
|
||||
: book.bookType === 'CBX'
|
||||
? 'cbx-reader'
|
||||
: null;
|
||||
@@ -414,9 +414,9 @@ export class BookService {
|
||||
return this.bookPatchService.savePdfProgress(bookId, page, percentage);
|
||||
}
|
||||
|
||||
saveEpubProgress(bookId: number, cfi: string, percentage: number): Observable<void> {
|
||||
return this.bookPatchService.saveEpubProgress(bookId, cfi, percentage);
|
||||
}
|
||||
/*saveEpubProgress(bookId: number, cfi: string, href: string, percentage: number): Observable<void> {
|
||||
return this.bookPatchService.saveEpubProgress(bookId, cfi, href, percentage);
|
||||
}*/
|
||||
|
||||
saveCbxProgress(bookId: number, page: number, percentage: number): Observable<void> {
|
||||
return this.bookPatchService.saveCbxProgress(bookId, page, percentage);
|
||||
|
||||
Reference in New Issue
Block a user