refactor(types): replace most usages of 'any' with 'unknown' and improve type safety across services and components (#2050)

* refactor(types): replace most usages of 'any' with 'unknown' and improve type safety across services and components

- Update method signatures, variables, and interfaces to use 'unknown' instead of 'any'
- Refine event and observable typings for better type inference
- Add or adjust explicit types for function parameters and return values
- Update Chart.js tooltip and context typings for chart services
- Improve type safety in Book, BookState, and related models
- Adjust template bindings and method calls to match stricter typings
- Add SecureSrcDirective for secure image loading with fallback and error handling

Signed-off-by: Balázs Szücs <bszucs1209@gmail.com>

* chore(angular): remove proxy configuration from development build settings

Signed-off-by: Balázs Szücs <bszucs1209@gmail.com>

* refactor(book-browser): streamline entity and book state management with reactive streams

- Refactor entity type and entity fetching logic to use observables and combine route params
- Simplify book state handling by consolidating filtering and fetching into a single reactive pipeline
- Remove redundant applySortOption logic and related subscriptions
- Fix book card index binding in template for improved rendering performance
- Ensure proper cleanup of epub rendition in epub-reader component

Signed-off-by: Balázs Szücs <bszucs1209@gmail.com>

* fix(book-browser, book-uploader): improve permission checks and enhance file upload handling

- Use optional chaining for user permission checks in book-browser.component.html to prevent runtime errors when user data is undefined
- Refactor book-uploader.component.ts to pass destination and IDs explicitly to uploadBatch, reconstruct files for strict type handling, and ensure proper upload flow and UI feedback

Signed-off-by: Balázs Szücs <bszucs1209@gmail.com>

* refactor(charts, services): improve type safety for book state validation and update form field checks

- Refactor isValidBookState methods across chart components and services to use type predicates and stricter type checks for BookState
- Update metadata-picker.component to simplify array field checks for authors, categories, moods, and tags
- Adjust magic-shelf-utils to remove unnecessary fallback in object spread
- Update notification-event.service to use correct timeout type for highlightTimeout

Signed-off-by: Balázs Szücs <bszucs1209@gmail.com>

* fix(theme): ensure safe merging of theme properties and improve type definition for themesMap

Signed-off-by: Balázs Szücs <bszucs1209@gmail.com>

* refactor(epub-reader): streamline book and rendition initialization logic

Signed-off-by: Balázs Szücs <bszucs1209@gmail.com>

---------

Signed-off-by: Balázs Szücs <bszucs1209@gmail.com>
This commit is contained in:
Balázs Szücs
2026-01-02 18:22:54 -07:00
committed by GitHub
parent 998b07d243
commit ab96eee5bc
86 changed files with 853 additions and 638 deletions
@@ -1,4 +1,4 @@
import {HttpErrorResponse, HttpHandlerFn, HttpInterceptorFn, HttpRequest} from '@angular/common/http';
import {HttpErrorResponse, HttpEvent, HttpHandlerFn, HttpInterceptorFn, HttpRequest} from '@angular/common/http';
import {inject} from '@angular/core';
import {Router} from '@angular/router';
import {catchError, filter, switchMap, take} from 'rxjs/operators';
@@ -31,7 +31,7 @@ export const AuthInterceptorService: HttpInterceptorFn = (req, next: HttpHandler
let isRefreshing = false;
const refreshTokenSubject = new BehaviorSubject<string | null>(null);
function handle401Error(authService: AuthService, request: HttpRequest<any>, next: HttpHandlerFn, router: Router, isInternal: boolean): Observable<any> {
function handle401Error(authService: AuthService, request: HttpRequest<unknown>, next: HttpHandlerFn, router: Router, isInternal: boolean): Observable<HttpEvent<unknown>> {
if (!isRefreshing && isInternal) {
isRefreshing = true;
refreshTokenSubject.next(null);
@@ -0,0 +1,63 @@
import { Directive, ElementRef, Input, OnChanges, OnDestroy, inject, SimpleChanges } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Subscription } from 'rxjs';
@Directive({
selector: '[appSecureSrc]',
standalone: true
})
export class SecureSrcDirective implements OnChanges, OnDestroy {
@Input('appSecureSrc') src!: string;
private currentUrl: string | null = null;
private subscription: Subscription | null = null;
private el = inject(ElementRef);
private http = inject(HttpClient);
ngOnChanges(changes: SimpleChanges): void {
if (changes['src']) {
this.loadImage();
}
}
private loadImage(): void {
this.cleanup();
if (!this.src) {
return;
}
this.subscription = this.http.get(this.src, { responseType: 'blob' }).subscribe({
next: (blob) => {
this.currentUrl = URL.createObjectURL(blob);
this.el.nativeElement.src = this.currentUrl;
},
error: (err) => {
// Only log non-CORS errors to avoid console spam
// CORS errors are expected in development and will be resolved by backend CORS config
if (err.status !== 0 && err.status !== 403) {
console.error('Error loading secure image:', err);
}
// Set a fallback placeholder image if available
const fallbackSrc = this.el.nativeElement.getAttribute('data-fallback-src') || 'assets/images/missing-cover.jpg';
this.el.nativeElement.src = fallbackSrc;
}
});
}
private cleanup(): void {
if (this.subscription) {
this.subscription.unsubscribe();
this.subscription = null;
}
if (this.currentUrl) {
URL.revokeObjectURL(this.currentUrl);
this.currentUrl = null;
}
}
ngOnDestroy(): void {
this.cleanup();
}
}