Refactor book service in BE and FE (#2013)

* Refactor book service in BE and FE

* Add missing method

---------

Co-authored-by: acx10 <acx10@users.noreply.github.com>
This commit is contained in:
ACX
2025-12-28 19:37:35 -07:00
committed by GitHub
co-authored by acx10
parent 60095c2173
commit 01446c2537
37 changed files with 2085 additions and 807 deletions
@@ -3,7 +3,7 @@ import {Tooltip} from 'primeng/tooltip';
export type DocType = 'kobo' | 'opds' | 'metadataManager' | 'koReader' | 'email'
| 'amazonCookie' | 'fetchConfig' | 'hardcover' | 'taskManagement' | 'fileNamePatterns'
| 'authentication';
| 'authentication' | 'telemetry';
@Component({
selector: 'app-external-doc-link',
@@ -39,6 +39,7 @@ export class ExternalDocLinkComponent {
taskManagement: `${this.BASE_URL}/tools/task-manager`,
fileNamePatterns: `${this.BASE_URL}/metadata/file-naming-patterns`,
authentication: `${this.BASE_URL}/authentication/overview#setting-up-oidc`,
telemetry: `${this.BASE_URL}/tools/telemetry`
};
@Input() docType!: DocType;
@@ -12,7 +12,7 @@ import {DomSanitizer, SafeHtml} from '@angular/platform-browser';
template: `
@if (icon) {
@if (icon.type === 'PRIME_NG') {
<i [class]="getPrimeNgIconClass(icon.value)" [ngClass]="iconClass" [ngStyle]="iconStyle"></i>
<i [class]="getPrimeNgIconClass(icon.value)" [ngClass]="iconClass" [ngStyle]="getPrimeNgStyle()"></i>
} @else {
<div
class="svg-icon-inline"
@@ -67,7 +67,7 @@ export class IconDisplayComponent implements OnInit, OnChanges {
const previousIcon = changes['icon'].previousValue;
if (currentIcon?.type === 'CUSTOM_SVG' &&
currentIcon?.value !== previousIcon?.value) {
currentIcon?.value !== previousIcon?.value) {
this.loadIconIfNeeded();
}
}
@@ -114,4 +114,20 @@ export class IconDisplayComponent implements OnInit, OnChanges {
...this.iconStyle
};
}
getPrimeNgStyle(): Record<string, string> {
const fontSize = this.size.endsWith('px')
? `${parseInt(this.size) * 0.85}px`
: `calc(${this.size} * 0.85)`;
return {
fontSize: fontSize,
width: this.size,
height: this.size,
display: 'inline-flex',
alignItems: 'center',
justifyContent: 'center',
...this.iconStyle
};
}
}
@@ -44,16 +44,20 @@
@if (versionInfo) {
<div style="margin-top: auto;" class="p-4 text-center w-full text-sm">
<div class="text-gray-200">
<a
[href]="getVersionUrl(versionInfo.current)"
target="_blank"
rel="noopener noreferrer"
class="hover:underline hover:text-gray-100 text-sm"
>
{{ versionInfo.current }}
</a>
@if (isSemanticVersion(versionInfo.current)) {
<a
[href]="getVersionUrl(versionInfo.current)"
target="_blank"
rel="noopener noreferrer"
class="hover:underline hover:text-gray-100 text-sm"
>
{{ versionInfo.current }}
</a>
} @else {
<span class="text-sm">{{ versionInfo.current }}</span>
}
</div>
@if (versionInfo.latest && versionInfo.latest !== versionInfo.current) {
@if (isSemanticVersion(versionInfo.current) && versionInfo.latest && versionInfo.latest !== versionInfo.current) {
<div>
<a
(click)="openChangelogDialog()"
@@ -208,6 +208,12 @@ export class AppMenuComponent implements OnInit {
: `https://github.com/booklore-app/booklore/commit/${version}`;
}
isSemanticVersion(version: string | undefined): boolean {
if (!version) return false;
const semanticVersionPattern = /^v\d+\.\d+\.\d+$/;
return semanticVersionPattern.test(version);
}
private sortArray<T>(array: T[], field: 'name' | 'id', order: 'asc' | 'desc'): T[] {
return [...array].sort((a, b) => {
const aVal = (a as any)[field] ?? '';
@@ -56,7 +56,7 @@
<app-icon-display
[icon]="getIconSelection()"
iconClass="layout-menuitem-icon"
size="16px"
size="18px"
></app-icon-display>
<span class="layout-menuitem-text menu-item-text">
{{ item.label }}
@@ -71,7 +71,7 @@
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
margin-left: 0.5rem;
margin-left: 0.35rem;
}
.menu-item-end-content {
@@ -11,7 +11,7 @@
}
@if (!loading && changelog.length > 0) {
<div class="space-y-6 p-4 max-h-[70vh] overflow-auto">
<div class="space-y-6 p-4 overflow-auto">
@for (release of changelog; track release) {
<div class="border-b pb-4">
<p class="font-bold text-2xl pb-2">
@@ -59,7 +59,12 @@
(click)="shouldShowStatsMenu ? statsMenu.toggle($event) : handleStatsButtonClick($event)"
[pTooltip]="statsTooltip"
tooltipPosition="bottom">
<i class="pi pi-chart-bar text-surface-100"></i>
<svg class="multi-color-chart-icon" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
<rect x="1.25" y="10" width="2.5" height="9" rx="0.5" fill="#ef4444"/>
<rect x="6.25" y="7" width="2.5" height="12" rx="0.5" fill="#f59e0b"/>
<rect x="11.25" y="3" width="2.5" height="16" rx="0.5" fill="#10b981"/>
<rect x="16.25" y="5" width="2.5" height="14" rx="0.5" fill="#3b82f6"/>
</svg>
</button>
@if (shouldShowStatsMenu) {
<p-menu #statsMenu [model]="statsMenuItems" [popup]="true" appendTo="body" />
@@ -213,7 +218,12 @@
class="flex items-center gap-2 w-full text-left p-2 hover:bg-surface-200 dark:hover:bg-surface-700 rounded"
(click)="shouldShowStatsMenu ? statsMenuMobile.toggle($event) : handleStatsButtonClick($event)"
>
<i class="pi pi-chart-bar text-surface-100"></i>
<svg class="multi-color-chart-icon" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
<rect x="1" y="13" width="2.5" height="6" rx="0.5" fill="#ef4444"/>
<rect x="5" y="10" width="2.5" height="9" rx="0.5" fill="#f59e0b"/>
<rect x="9" y="6" width="2.5" height="13" rx="0.5" fill="#10b981"/>
<rect x="13" y="8" width="2.5" height="11" rx="0.5" fill="#3b82f6"/>
</svg>
Charts
</button>
@if (shouldShowStatsMenu) {
@@ -135,6 +135,7 @@ export interface AppSettings {
koboSettings: KoboSettings;
coverCroppingSettings: CoverCroppingSettings;
metadataDownloadOnBookdrop: boolean;
telemetryEnabled: boolean;
}
export enum AppSettingKey {
@@ -155,5 +156,6 @@ export enum AppSettingKey {
METADATA_DOWNLOAD_ON_BOOKDROP = 'METADATA_DOWNLOAD_ON_BOOKDROP',
METADATA_PUBLIC_REVIEWS_SETTINGS = 'METADATA_PUBLIC_REVIEWS_SETTINGS',
KOBO_SETTINGS = 'KOBO_SETTINGS',
COVER_CROPPING_SETTINGS = 'COVER_CROPPING_SETTINGS'
COVER_CROPPING_SETTINGS = 'COVER_CROPPING_SETTINGS',
TELEMETRY_ENABLED = 'TELEMETRY_ENABLED',
}
@@ -6,6 +6,7 @@ import {API_CONFIG} from '../../core/config/api-config';
import {createRxStompConfig} from '../websocket/rx-stomp.config';
import {OAuthService, OAuthStorage} from 'angular-oauth2-oidc';
import {Router} from '@angular/router';
import {PostLoginInitializerService} from '../../core/services/post-login-initializer.service';
@Injectable({
providedIn: 'root',
@@ -14,23 +15,25 @@ export class AuthService {
private apiUrl = `${API_CONFIG.BASE_URL}/api/v1/auth`;
private rxStompService?: RxStompService;
private postLoginInitialized = false;
private http = inject(HttpClient);
private injector = inject(Injector);
private oAuthService = inject(OAuthService);
private oAuthStorage = inject(OAuthStorage);
private router = inject(Router);
private postLoginInitializer = inject(PostLoginInitializerService);
public tokenSubject = new BehaviorSubject<string | null>(this.getOidcAccessToken() || this.getInternalAccessToken());
public token$ = this.tokenSubject.asObservable();
internalLogin(credentials: { username: string; password: string }): Observable<{ accessToken: string; refreshToken: string, isDefaultPassword: string }> {
return this.http.post<{ accessToken: string; refreshToken: string, isDefaultPassword: string }>(`${this.apiUrl}/login`, credentials).pipe(
tap((response) => {
if (response.accessToken && response.refreshToken) {
this.saveInternalTokens(response.accessToken, response.refreshToken);
this.initializeWebSocketConnection();
this.handleSuccessfulAuth();
}
})
);
@@ -53,6 +56,7 @@ export class AuthService {
if (response.accessToken && response.refreshToken) {
this.saveInternalTokens(response.accessToken, response.refreshToken);
this.initializeWebSocketConnection();
this.handleSuccessfulAuth();
}
})
);
@@ -93,9 +97,8 @@ export class AuthService {
this.oAuthStorage.removeItem("refresh_token");
this.oAuthStorage.removeItem("id_token");
this.tokenSubject.next(null);
this.postLoginInitialized = false;
this.getRxStompService().deactivate();
// Force reload so user's data is not cached for next user that logs in
window.location.href = '/login';
}
@@ -114,6 +117,19 @@ export class AuthService {
const config = createRxStompConfig(this);
stompService.updateConfig(config);
stompService.activate();
if (!this.postLoginInitialized) {
this.handleSuccessfulAuth();
}
}
private handleSuccessfulAuth() {
if (this.postLoginInitialized) return;
this.postLoginInitialized = true;
this.postLoginInitializer.initialize().subscribe({
next: () => console.log('AuthService: Post-login initialization completed'),
error: (err) => console.error('AuthService: Post-login initialization failed:', err)
});
}
}
@@ -145,7 +145,7 @@ export class DialogLauncherService {
openVersionChangelogDialog(): DynamicDialogRef | null {
return this.openDialog(VersionChangelogDialogComponent, {
header: "What's New",
styleClass: 'dialog-maximal',
styleClass: 'dialog-medium',
});
}