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:
ACX
2026-01-15 20:39:52 -07:00
committed by GitHub
co-authored by acx10
parent 775887b55f
commit 8c35f2415c
107 changed files with 13351 additions and 1733 deletions
@@ -124,6 +124,16 @@
{{ coverScalePreferenceService.scaleFactor.toFixed(2) }}x
</div>
</div>
<!-- Book type pill toggle control -->
<div class="flex flex-col gap-2">
<label for="show-book-type-pill-checkbox" class="font-medium">Show book type pill</label>
<p-checkbox
inputId="show-book-type-pill-checkbox"
[binary]="true"
[ngModel]="bookCardOverlayPreferenceService.showBookTypePill"
(onChange)="bookCardOverlayPreferenceService.setShowBookTypePill($event.checked)">
</p-checkbox>
</div>
</div>
</p-popover>
</div>
@@ -273,7 +283,8 @@
[onBookSelect]="handleBookSelect.bind(this)"
[isSeriesCollapsed]="seriesCollapseFilter.isSeriesCollapsed"
(checkboxClick)="onCheckboxClicked($event)"
[isSelected]="selectedBooks.has(book.id)">
[isSelected]="selectedBooks.has(book.id)"
[overlayPreferenceService]="bookCardOverlayPreferenceService">
</app-book-card>
</div>
}
@@ -51,6 +51,7 @@ import {TaskHelperService} from '../../../settings/task-management/task-helper.s
import {FilterLabelHelper} from './filter-label.helper';
import {LoadingService} from '../../../../core/services/loading.service';
import {BookNavigationService} from '../../service/book-navigation.service';
import {BookCardOverlayPreferenceService} from './book-card-overlay-preference.service';
export enum EntityType {
LIBRARY = 'Library',
@@ -123,6 +124,7 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
private pageTitle = inject(PageTitleService);
private loadingService = inject(LoadingService);
private bookNavigationService = inject(BookNavigationService);
protected bookCardOverlayPreferenceService = inject(BookCardOverlayPreferenceService);
bookState$: Observable<BookState> | undefined;
entity$: Observable<Library | Shelf | MagicShelf | null> | undefined;
@@ -0,0 +1,126 @@
import {inject, Injectable} from '@angular/core';
import {BehaviorSubject, Subject} from 'rxjs';
import {debounceTime, filter, takeUntil} from 'rxjs/operators';
import {UserService} from '../../../settings/user-management/user.service';
@Injectable({
providedIn: 'root'
})
export class BookCardOverlayPreferenceService {
private readonly userService = inject(UserService);
private readonly _showBookTypePill = new BehaviorSubject<boolean>(true);
readonly showBookTypePill$ = this._showBookTypePill.asObservable();
private destroy$ = new Subject<void>();
private hasUserToggled = false;
private currentContext: { type: 'LIBRARY' | 'SHELF' | 'MAGIC_SHELF', id: number } | null = null;
constructor() {
this.userService.userState$
.pipe(
filter(userState => !!userState?.user && userState.loaded),
takeUntil(this.destroy$)
)
.subscribe(() => {
this.loadPreferencesFromUser();
});
this.showBookTypePill$
.pipe(debounceTime(500))
.subscribe(show => {
if (this.hasUserToggled) {
this.persistPreference(show);
}
});
}
setShowBookTypePill(show: boolean): void {
this.hasUserToggled = true;
this._showBookTypePill.next(show);
}
get showBookTypePill(): boolean {
return this._showBookTypePill.value;
}
private loadPreferencesFromUser(): void {
const user = this.userService.getCurrentUser();
const prefs = user?.userSettings?.entityViewPreferences;
let show = true;
if (prefs) {
const globalAny = prefs.global as any;
show = prefs.global?.overlayBookType ?? globalAny?.showBookTypePill ?? true;
if (this.currentContext) {
const override = prefs.overrides?.find(o =>
o.entityType === this.currentContext?.type && o.entityId === this.currentContext?.id
);
if (override) {
const prefAny = override.preferences as any;
if (override.preferences.overlayBookType !== undefined) {
show = override.preferences.overlayBookType;
} else if (prefAny?.showBookTypePill !== undefined) {
show = prefAny.showBookTypePill;
}
}
}
}
this.hasUserToggled = false;
if (this._showBookTypePill.value !== show) {
this._showBookTypePill.next(show);
}
}
private persistPreference(show: boolean): void {
const user = this.userService.getCurrentUser();
if (!user) return;
const prefs = structuredClone(user.userSettings.entityViewPreferences ?? {
global: {
sortKey: 'addedOn',
sortDir: 'DESC',
view: 'GRID',
coverSize: 1.0,
seriesCollapsed: false,
overlayBookType: true
},
overrides: []
});
if (!prefs.overrides) {
prefs.overrides = [];
}
if (this.currentContext) {
let override = prefs.overrides.find(o =>
o.entityType === this.currentContext?.type && o.entityId === this.currentContext?.id
);
if (!override) {
override = {
entityType: this.currentContext.type,
entityId: this.currentContext.id,
preferences: {
...prefs.global,
overlayBookType: show
}
};
prefs.overrides.push(override);
} else {
override.preferences.overlayBookType = show;
}
} else {
prefs.global.overlayBookType = show;
}
this.userService.updateUserSetting(user.id, 'entityViewPreferences', prefs);
}
ngOnDestroy(): void {
this.destroy$.next();
this.destroy$.complete();
}
}
@@ -12,17 +12,23 @@
decoding="async"
(load)="onImageLoad()"/>
@if (!book.seriesCount && book.metadata?.seriesNumber != null) {
<div class="series-number-overlay">
#{{ book.metadata?.seriesNumber }}
</div>
}
@if (book.seriesCount && book.seriesCount >= 1) {
<div class="series-items-count-overlay" [pTooltip]="seriesCountTooltip" tooltipPosition="right">
<i class="pi pi-book" style="font-size: 0.65rem; margin-right: 2px;"></i>{{ book.seriesCount }}
</div>
}
<div class="top-left-overlay-stack">
@if (showBookTypePill && book.bookType) {
<div class="book-type-pill-overlay" [ngClass]="'book-type-' + book.bookType.toLowerCase()">
{{ book.bookType }}
</div>
}
@if (!book.seriesCount && book.metadata?.seriesNumber != null) {
<div class="series-number-overlay">
#{{ book.metadata?.seriesNumber }}
</div>
}
@if (book.seriesCount && book.seriesCount >= 1) {
<div class="series-items-count-overlay">
<i class="pi pi-book series-items-count-icon"></i>{{ book.seriesCount }}
</div>
}
</div>
@if (_isSeriesViewActive) {
<p-button [rounded]="true" icon="pi pi-info" class="info-btn" (click)="openSeriesInfo()"></p-button>
@@ -30,7 +36,7 @@
<p-button [rounded]="true" icon="pi pi-info" class="info-btn" (click)="openBookInfo(book)"></p-button>
}
@if (!_isSeriesViewActive && _canReadBook) {
@if (!_isSeriesViewActive) {
<p-button [rounded]="true" icon="pi pi-book" class="read-btn" (click)="readBook(book)"></p-button>
}
@@ -21,10 +21,6 @@
justify-content: center;
}
.cover-container.loaded {
background-color: transparent;
}
.book-cover {
width: 100%;
height: 100%;
@@ -157,13 +153,11 @@
.series-items-count-overlay {
position: absolute;
top: 8px;
left: 8px;
background-color: var(--primary-color);
color: var(--primary-text-color-dark);
font-size: 0.75rem;
padding: 3px 8px;
border-radius: 4px;
font-size: 0.7rem;
padding: 0 5px;
border-radius: 6px;
z-index: 3;
white-space: nowrap;
user-select: none;
@@ -176,6 +170,76 @@
gap: 2px;
}
.series-items-count-icon {
font-size: 0.6rem;
margin-right: 2px;
}
.book-type-pill-overlay {
position: absolute;
background: var(--primary-color, #6366f1);
color: var(--primary-text-color-dark, #fff);
font-size: 0.675rem;
font-weight: 700;
padding: 1px 6px;
border-radius: 6px;
z-index: 3;
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
letter-spacing: 0.03em;
user-select: none;
pointer-events: none;
text-transform: uppercase;
transition: background 0.2s;
}
.top-left-overlay-stack {
position: absolute;
top: 7px;
left: 7px;
display: flex;
flex-direction: column;
align-items: flex-start;
gap: 4px;
z-index: 4;
}
.book-type-pill-overlay,
.series-number-overlay,
.series-items-count-overlay {
position: static;
margin: 0;
}
.book-type-epub {
background: #16a34a; /* medium green */
color: #fff;
}
.book-type-pdf {
background: #dc2626; /* medium red */
color: #fff;
}
.book-type-cbx {
background: #d97706; /* amber/orange */
color: #fff;
}
.book-type-mobi {
background: #2563eb; /* medium blue */
color: #fff;
}
.book-type-azw3 {
background: #0891b2; /* cyan/teal */
color: #fff;
}
.book-type-fb2 {
background: #7c3aed; /* vibrant purple */
color: #fff;
}
.read-status-indicator {
display: flex;
align-items: center;
@@ -23,6 +23,7 @@ import {ReadStatusHelper} from '../../../helpers/read-status.helper';
import {BookDialogHelperService} from '../book-dialog-helper.service';
import {TaskHelperService} from '../../../../settings/task-management/task-helper.service';
import {BookNavigationService} from '../../../service/book-navigation.service';
import {BookCardOverlayPreferenceService} from '../book-card-overlay-preference.service';
@Component({
selector: 'app-book-card',
@@ -45,6 +46,7 @@ export class BookCardComponent implements OnInit, OnChanges, OnDestroy {
@Input() bottomBarHidden: boolean = false;
@Input() seriesViewEnabled: boolean = false;
@Input() isSeriesCollapsed: boolean = false;
@Input() overlayPreferenceService?: BookCardOverlayPreferenceService;
@ViewChild('checkboxElem') checkboxElem!: ElementRef<HTMLInputElement>;
@@ -69,7 +71,6 @@ export class BookCardComponent implements OnInit, OnChanges, OnDestroy {
protected _koProgressPercentage: number | null = null;
protected _koboProgressPercentage: number | null = null;
protected _displayTitle: string | undefined = undefined;
protected _canReadBook: boolean = true;
protected _isSeriesViewActive: boolean = false;
protected _coverImageUrl: string = '';
protected _readStatusIcon: string = '';
@@ -86,6 +87,10 @@ export class BookCardComponent implements OnInit, OnChanges, OnDestroy {
private user: User | null = null;
private menuInitialized = false;
showBookTypePill = true;
private overlayPrefSub?: any;
ngOnInit(): void {
this.computeAllMemoizedValues();
this.userService.userState$
@@ -98,6 +103,13 @@ export class BookCardComponent implements OnInit, OnChanges, OnDestroy {
this.user = userState.user;
this.metadataCenterViewMode = userState.user?.userSettings?.metadataCenterViewMode ?? 'route';
});
if (this.overlayPreferenceService) {
this.overlayPrefSub = this.overlayPreferenceService.showBookTypePill$.subscribe(val => {
this.showBookTypePill = val;
this.cdr.markForCheck();
});
}
}
ngOnChanges(changes: SimpleChanges): void {
@@ -131,7 +143,6 @@ export class BookCardComponent implements OnInit, OnChanges, OnDestroy {
this._displayTitle = (this.isSeriesCollapsed && this.book.metadata?.seriesName)
? this.book.metadata?.seriesName
: this.book.metadata?.title;
this._canReadBook = this.book?.bookType !== 'FB2';
this._coverImageUrl = this.urlHelper.getThumbnailUrl(this.book.id, this.book.metadata?.coverUpdatedOn);
this._readStatusIcon = this.readStatusHelper.getReadStatusIcon(this.book.readStatus);
@@ -770,5 +781,8 @@ export class BookCardComponent implements OnInit, OnChanges, OnDestroy {
ngOnDestroy(): void {
this.destroy$.next();
this.destroy$.complete();
if (this.overlayPrefSub) {
this.overlayPrefSub.unsubscribe();
}
}
}
@@ -3,7 +3,7 @@ import {CbxBackgroundColor, CbxFitMode, CbxPageSpread, CbxPageViewMode, CbxScrol
import {BookReview} from '../components/book-reviews/book-review-service';
import {ZoomType} from 'ngx-extended-pdf-viewer';
export type BookType = "PDF" | "EPUB" | "CBX" | "FB2";
export type BookType = "PDF" | "EPUB" | "CBX" | "FB2" | "MOBI" | "AZW3";
export enum AdditionalFileType {
ALTERNATIVE_FORMAT = 'ALTERNATIVE_FORMAT',
@@ -48,6 +48,7 @@ export interface Book extends FileInfo {
libraryPath?: { id: number };
alternativeFormats?: AdditionalFile[];
supplementaryFiles?: AdditionalFile[];
[key: string]: unknown;
}
@@ -150,6 +151,7 @@ export interface BookMetadata {
tagsLocked?: boolean;
coverLocked?: boolean;
reviewsLocked?: boolean;
[key: string]: unknown;
}
@@ -210,6 +212,21 @@ export interface EpubViewerSetting {
customFontId?: number | null;
}
export interface EbookViewerSetting {
lineHeight: number;
justify: boolean;
hyphenate: boolean;
maxColumnCount: number;
gap: number;
fontSize: number;
theme: string
maxInlineSize: number;
maxBlockSize: number;
fontFamily: string | null;
isDark: boolean;
flow: 'paginated' | 'scrolled';
}
export interface CbxViewerSetting {
pageSpread: CbxPageSpread;
pageViewMode: CbxPageViewMode;
@@ -221,8 +238,10 @@ export interface CbxViewerSetting {
export interface BookSetting {
pdfSettings?: PdfViewerSetting;
epubSettings?: EpubViewerSetting;
ebookSettings?: EbookViewerSetting;
cbxSettings?: CbxViewerSetting;
newPdfSettings?: NewPdfReaderSetting;
[key: string]: unknown;
}
@@ -1,7 +1,7 @@
import {SortOption} from './sort.model';
export type LibraryScanMode = 'FILE_AS_BOOK' | 'FOLDER_AS_BOOK';
export type BookFileType = 'PDF' | 'EPUB' | 'CBX' | 'FB2';
export type BookFileType = 'PDF' | 'EPUB' | 'CBX' | 'FB2' | 'MOBI' | 'AZW3';
export interface Library {
id?: number;
@@ -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);