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
@@ -20,7 +20,7 @@ export class KoreaderService {
private http = inject(HttpClient);
createUser(username: string, password: string): Observable<KoreaderUser> {
const payload: any = {username, password};
const payload: unknown = {username, password};
return this.http.put<KoreaderUser>(`${this.url}/me`, payload);
}
@@ -35,7 +35,7 @@ export class EmailV2ProviderComponent implements OnInit {
private emailProvidersService = inject(EmailV2ProviderService);
private messageService = inject(MessageService);
private userService = inject(UserService);
defaultProviderId: any;
defaultProviderId: unknown;
currentUserId: number | null = null;
isAdmin: boolean = false;
@@ -31,7 +31,7 @@ export class EmailV2RecipientComponent implements OnInit {
private dialogLauncherService = inject(DialogLauncherService);
private emailRecipientService = inject(EmailV2RecipientService);
private messageService = inject(MessageService);
defaultRecipientId: any;
defaultRecipientId: unknown;
ngOnInit(): void {
this.loadRecipientEmails();
@@ -23,7 +23,7 @@ export class ReaderPreferencesService implements OnDestroy {
this.destroy$.complete();
}
updatePreference(path: string[], value: any): void {
updatePreference(path: string[], value: unknown): void {
if (!this.currentUser) return;
let target: any = this.currentUser.userSettings;
@@ -76,8 +76,8 @@
<i class="pi pi-clock"></i>
<span class="cron-label">Scheduled:</span>
@if (!isEditingCron(taskInfo.taskType)) {
@if (getCronConfig(taskInfo.taskType).cronExpression) {
<span class="cron-expression">{{ getCronConfig(taskInfo.taskType).cronExpression }}</span>
@if (getCronConfig(taskInfo.taskType)?.cronExpression) {
<span class="cron-expression">{{ getCronConfig(taskInfo.taskType)!.cronExpression }}</span>
} @else {
<span class="cron-expression empty">Not configured</span>
}
@@ -131,7 +131,7 @@
</div>
}
<p-toggleswitch
[ngModel]="getCronConfig(taskInfo.taskType).enabled"
[ngModel]="getCronConfig(taskInfo.taskType)?.enabled ?? false"
[disabled]="isEditingCron(taskInfo.taskType) || cronUpdating"
(ngModelChange)="toggleCronEnabled(taskInfo.taskType)">
</p-toggleswitch>
@@ -5,7 +5,8 @@ import {ProgressBar} from 'primeng/progressbar';
import {MessageService} from 'primeng/api';
import {Select} from 'primeng/select';
import {FormsModule} from '@angular/forms';
import {TaskInfo, MetadataReplaceMode, TaskHistory, TASK_TYPE_CONFIG, TaskCreateRequest, TaskCronConfigRequest, TaskProgressPayload, TaskService, TaskStatus, TaskType} from './task.service';
import {TaskInfo, MetadataReplaceMode, TaskHistory, TASK_TYPE_CONFIG, TaskCreateRequest, TaskCronConfigRequest, TaskProgressPayload, TaskService, TaskStatus, TaskType, LibraryRescanOptions} from './task.service';
import {MetadataRefreshRequest} from '../../metadata/model/request/metadata-refresh-request.model';
import {finalize, forkJoin, Subscription} from 'rxjs';
import {ExternalDocLinkComponent} from '../../../shared/components/external-doc-link/external-doc-link.component';
import {ToggleSwitch} from 'primeng/toggleswitch';
@@ -174,7 +175,7 @@ export class TaskManagementComponent implements OnInit, OnDestroy {
this.runTaskWithOptions(type, options);
}
private runTaskWithOptions(type: string, options: any): void {
private runTaskWithOptions(type: string, options: LibraryRescanOptions | MetadataRefreshRequest | null): void {
const request: TaskCreateRequest = {
taskType: type as TaskType,
options: options
@@ -273,9 +274,15 @@ export class TaskManagementComponent implements OnInit, OnDestroy {
return taskInfo?.cronSupported || false;
}
getCronConfig(taskType: string): any {
getCronConfig(taskType: string): { enabled?: boolean; cronExpression?: string } | null | undefined {
const taskInfo = this.taskInfos.find(t => t.taskType === taskType);
return taskInfo?.cronConfig;
if (!taskInfo?.cronConfig) return null;
const cronConfig = taskInfo.cronConfig;
return {
enabled: cronConfig.enabled,
cronExpression: cronConfig.cronExpression ?? undefined
};
}
toggleCronEnabled(taskType: string): void {
@@ -283,7 +290,7 @@ export class TaskManagementComponent implements OnInit, OnDestroy {
if (!cronConfig) return;
const request: TaskCronConfigRequest = {
enabled: !cronConfig.enabled
enabled: !(cronConfig.enabled ?? false)
};
this.updateCronConfig(taskType, request);
@@ -66,7 +66,7 @@ export interface CronConfig {
taskType: string;
cronExpression: string | null;
enabled: boolean;
options: Record<string, any> | null;
options: Record<string, unknown> | null;
createdAt: string | null;
updatedAt: string | null;
}
@@ -5,6 +5,12 @@ import {DynamicDialogRef} from 'primeng/dynamicdialog';
import {TableModule} from 'primeng/table';
import {LowerCasePipe, TitleCasePipe} from '@angular/common';
import {User, UserService} from './user.service';
interface UserWithEditing extends User {
isEditing?: boolean;
selectedLibraryIds?: number[];
libraryNames?: string;
}
import {MessageService} from 'primeng/api';
import {Checkbox} from 'primeng/checkbox';
import {MultiSelect} from 'primeng/multiselect';
@@ -43,7 +49,7 @@ export class UserManagementComponent implements OnInit, OnDestroy {
private messageService = inject(MessageService);
private readonly destroy$ = new Subject<void>();
users: User[] = [];
users: UserWithEditing[] = [];
currentUser: User | null = null;
editingLibraryIds: number[] = [];
allLibraries: Library[] = [];
@@ -91,7 +97,7 @@ export class UserManagementComponent implements OnInit, OnDestroy {
this.users = data.map((user) => ({
...user,
isEditing: false,
selectedLibraryIds: user.assignedLibraries?.map((lib) => lib.id) || [],
selectedLibraryIds: user.assignedLibraries?.map((lib) => lib.id!).filter(id => id !== undefined) as number[] || [],
libraryNames:
user.assignedLibraries?.map((lib) => lib.name).join(', ') || '',
}));
@@ -115,10 +121,10 @@ export class UserManagementComponent implements OnInit, OnDestroy {
});
}
toggleEdit(user: any) {
toggleEdit(user: UserWithEditing) {
user.isEditing = !user.isEditing;
if (user.isEditing) {
this.editingLibraryIds = [...user.selectedLibraryIds];
this.editingLibraryIds = [...(user.selectedLibraryIds || [])];
} else {
user.libraryNames =
user.assignedLibraries
@@ -127,14 +133,14 @@ export class UserManagementComponent implements OnInit, OnDestroy {
}
}
saveUser(user: any) {
saveUser(user: UserWithEditing) {
user.selectedLibraryIds = [...this.editingLibraryIds];
this.userService
.updateUser(user.id, {
name: user.name,
email: user.email,
permissions: user.permissions,
assignedLibraries: user.selectedLibraryIds,
assignedLibraries: this.allLibraries.filter(lib => lib.id && user.selectedLibraryIds?.includes(lib.id)),
})
.subscribe({
next: () => {
@@ -291,7 +297,7 @@ export class UserManagementComponent implements OnInit, OnDestroy {
return this.expandedRows[user.id];
}
onAdminCheckboxChange(user: any) {
onAdminCheckboxChange(user: User) {
if (user.permissions.admin) {
user.permissions.canUpload = true;
user.permissions.canDownload = true;
@@ -322,7 +328,7 @@ export class UserManagementComponent implements OnInit, OnDestroy {
}
}
isPermissionDisabled(user: any): boolean {
isPermissionDisabled(user: UserWithEditing): boolean {
return !user.isEditing || user.permissions.admin;
}
}
@@ -84,12 +84,12 @@ export class UserStatsService {
}
getFavoriteDays(year?: number, month?: number): Observable<FavoriteDaysResponse[]> {
let params: any = {};
let params: Record<string, string> = {};
if (year !== undefined && year !== null) {
params.year = year.toString();
params['year'] = year.toString();
}
if (month !== undefined && month !== null) {
params.month = month.toString();
params['month'] = month.toString();
}
return this.http.get<FavoriteDaysResponse[]>(
@@ -99,12 +99,12 @@ export class UserStatsService {
}
getPeakHours(year?: number, month?: number): Observable<PeakHoursResponse[]> {
let params: any = {};
let params: Record<string, string> = {};
if (year !== undefined && year !== null) {
params.year = year.toString();
params['year'] = year.toString();
}
if (month !== undefined && month !== null) {
params.month = month.toString();
params['month'] = month.toString();
}
return this.http.get<PeakHoursResponse[]>(
@@ -311,7 +311,7 @@ export class UserService {
);
}
updateUserSetting(userId: number, key: string, value: any): void {
updateUserSetting(userId: number, key: string, value: unknown): void {
const payload = {
key,
value
@@ -60,7 +60,7 @@ export class FilterPreferencesComponent implements OnInit, OnDestroy {
this.selectedFilterSortingMode = settings.filterSortingMode ?? 'alphabetical';
}
private updatePreference(path: string[], value: any): void {
private updatePreference(path: string[], value: unknown): void {
if (!this.currentUser) return;
let target: any = this.currentUser.userSettings;
@@ -56,7 +56,7 @@ export class SidebarSortingPreferencesComponent implements OnInit, OnDestroy {
this.selectedMagicShelfSorting = settings.sidebarMagicShelfSorting;
}
private updatePreference(path: string[], value: any): void {
private updatePreference(path: string[], value: unknown): void {
if (!this.currentUser) return;
let target: any = this.currentUser.userSettings;
for (let i = 0; i < path.length - 1; i++) {