Implement streaming EPUB reader with on-demand loading (#2350)
Co-authored-by: acx10 <acx10@users.noreply.github.com>
This commit is contained in:
@@ -235,14 +235,14 @@ describe('BookService', () => {
|
||||
|
||||
describe('Reading & Viewer Settings', () => {
|
||||
it('should navigate to correct reader and update last read time', () => {
|
||||
service.readBook(1, 'ngx');
|
||||
expect(routerMock.navigate).toHaveBeenCalledWith(['/pdf-reader/book/1']);
|
||||
service.readBook(1);
|
||||
expect(routerMock.navigate).toHaveBeenCalledWith(['/pdf-reader/book/1'], undefined);
|
||||
expect(bookPatchServiceMock.updateLastReadTime).toHaveBeenCalledWith(1);
|
||||
});
|
||||
|
||||
it('should not navigate if book not found', () => {
|
||||
bookStateServiceMock.getCurrentBookState.mockReturnValue({books: [], loaded: true, error: null});
|
||||
service.readBook(999, 'ngx');
|
||||
service.readBook(999);
|
||||
expect(routerMock.navigate).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
|
||||
@@ -244,7 +244,7 @@ export class BookService {
|
||||
|
||||
/*------------------ Reading & Viewer Settings ------------------*/
|
||||
|
||||
readBook(bookId: number, reader: 'ngx' | 'streaming' = 'ngx'): void {
|
||||
readBook(bookId: number, reader?: 'pdf-streaming' | 'epub-streaming'): void {
|
||||
const book = this.bookStateService
|
||||
.getCurrentBookState()
|
||||
.books?.find(b => b.id === bookId);
|
||||
@@ -254,23 +254,39 @@ export class BookService {
|
||||
return;
|
||||
}
|
||||
|
||||
const baseUrl =
|
||||
book.bookType === 'PDF'
|
||||
? reader === 'ngx'
|
||||
? 'pdf-reader'
|
||||
: 'cbx-reader'
|
||||
: book.bookType === 'EPUB' || book.bookType === 'FB2' || book.bookType === 'MOBI' || book.bookType === 'AZW3'
|
||||
? 'ebook-reader'
|
||||
: book.bookType === 'CBX'
|
||||
? 'cbx-reader'
|
||||
: null;
|
||||
let baseUrl: string | null = null;
|
||||
let queryParams: Record<string, any> | undefined;
|
||||
|
||||
switch (book.bookType) {
|
||||
case 'PDF':
|
||||
baseUrl = reader === 'pdf-streaming' ? 'cbx-reader' : 'pdf-reader';
|
||||
break;
|
||||
|
||||
case 'EPUB':
|
||||
baseUrl = 'ebook-reader';
|
||||
if (reader === 'epub-streaming') {
|
||||
queryParams = { streaming: true };
|
||||
}
|
||||
break;
|
||||
|
||||
case 'FB2':
|
||||
case 'MOBI':
|
||||
case 'AZW3':
|
||||
baseUrl = 'ebook-reader';
|
||||
break;
|
||||
|
||||
case 'CBX':
|
||||
baseUrl = 'cbx-reader';
|
||||
break;
|
||||
}
|
||||
|
||||
if (!baseUrl) {
|
||||
console.error('Unsupported book type:', book.bookType);
|
||||
return;
|
||||
}
|
||||
|
||||
this.router.navigate([`/${baseUrl}/book/${book.id}`]);
|
||||
this.router.navigate([`/${baseUrl}/book/${book.id}`], queryParams ? { queryParams } : undefined);
|
||||
|
||||
this.updateLastReadTime(book.id);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user