refactor(frontend): rename booklore-ui to frontend
- Frontend path: - rename the tracked Angular app tree from `booklore-ui/` to `frontend/` - preserve file contents during the move so this commit stays focused on the path change itself - Frontend docs: - update the moved frontend README and contribution guide where they refer to the renamed folder - keep those edits limited to path references introduced by the directory rename
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import {inject, Injectable} from '@angular/core';
|
||||
import {HttpClient} from '@angular/common/http';
|
||||
import {Observable} from 'rxjs';
|
||||
import {API_CONFIG} from '../../core/config/api-config';
|
||||
|
||||
export interface CoverImage {
|
||||
url: string;
|
||||
source?: string;
|
||||
width?: number;
|
||||
height?: number;
|
||||
index: number;
|
||||
}
|
||||
|
||||
export interface CoverFetchRequest {
|
||||
title?: string;
|
||||
author?: string;
|
||||
coverType?: 'ebook' | 'audiobook';
|
||||
}
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class BookCoverService {
|
||||
private readonly baseUrl = `${API_CONFIG.BASE_URL}/api/v1/books`;
|
||||
|
||||
private http = inject(HttpClient);
|
||||
|
||||
fetchBookCovers(request: CoverFetchRequest): Observable<CoverImage[]> {
|
||||
return this.http.post<CoverImage[]>(`${this.baseUrl}/1/metadata/covers`, request);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,204 @@
|
||||
import {inject, Injectable, Type} from '@angular/core';
|
||||
import {DialogService, DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
import {LibraryCreatorComponent} from '../../features/library-creator/library-creator.component';
|
||||
import {BookUploaderComponent} from '../components/book-uploader/book-uploader.component';
|
||||
import {UserProfileDialogComponent} from '../../features/settings/user-profile-dialog/user-profile-dialog.component';
|
||||
import {MagicShelfComponent} from '../../features/magic-shelf/component/magic-shelf-component';
|
||||
import {DashboardSettingsComponent} from '../../features/dashboard/components/dashboard-settings/dashboard-settings.component';
|
||||
import {VersionChangelogDialogComponent} from '../layout/component/layout-menu/version-changelog-dialog/version-changelog-dialog.component';
|
||||
import {CreateUserDialogComponent} from '../../features/settings/user-management/create-user-dialog/create-user-dialog.component';
|
||||
import {CreateEmailRecipientDialogComponent} from '../../features/settings/email-v2/create-email-recipient-dialog/create-email-recipient-dialog.component';
|
||||
import {CreateEmailProviderDialogComponent} from '../../features/settings/email-v2/create-email-provider-dialog/create-email-provider-dialog.component';
|
||||
import {DirectoryPickerComponent} from '../components/directory-picker/directory-picker.component';
|
||||
import {BookdropFinalizeResultDialogComponent} from '../../features/bookdrop/component/bookdrop-finalize-result-dialog/bookdrop-finalize-result-dialog.component';
|
||||
import {BookdropFinalizeResult} from '../../features/bookdrop/service/bookdrop.service';
|
||||
import {MetadataReviewDialogComponent} from '../../features/metadata/component/metadata-review-dialog/metadata-review-dialog-component';
|
||||
import {MetadataRefreshType} from '../../features/metadata/model/request/metadata-refresh-type.enum';
|
||||
import {MetadataFetchOptionsComponent} from '../../features/metadata/component/metadata-options-dialog/metadata-fetch-options/metadata-fetch-options.component';
|
||||
import {ShelfEditDialogComponent} from '../../features/book/components/shelf-edit-dialog/shelf-edit-dialog.component';
|
||||
import {IconPickerComponent} from '../components/icon-picker/icon-picker-component';
|
||||
|
||||
/**
|
||||
* Dialog size classes - use these to control dialog dimensions
|
||||
*/
|
||||
export const DialogSize = {
|
||||
XS: 'dialog-xs', // ~400px - confirmations, simple alerts
|
||||
SM: 'dialog-sm', // ~550px - simple forms, pickers
|
||||
MD: 'dialog-md', // ~700px - standard dialogs
|
||||
LG: 'dialog-lg', // ~900px - complex forms, lists
|
||||
XL: 'dialog-xl', // ~1200px - data-heavy views
|
||||
FULL: 'dialog-full', // viewport - fullscreen editors
|
||||
} as const;
|
||||
|
||||
/**
|
||||
* Dialog style modifiers - composable with size classes
|
||||
*/
|
||||
export const DialogStyle = {
|
||||
MINIMAL: 'dialog-minimal', // removes padding for custom headers
|
||||
} as const;
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class DialogLauncherService {
|
||||
|
||||
dialogService = inject(DialogService);
|
||||
|
||||
private defaultDialogOptions = {
|
||||
baseZIndex: 10,
|
||||
closable: true,
|
||||
dismissableMask: true,
|
||||
draggable: false,
|
||||
modal: true,
|
||||
resizable: false,
|
||||
showHeader: true,
|
||||
maximizable: false,
|
||||
}
|
||||
|
||||
openDialog(component: unknown, options: {}): DynamicDialogRef | null {
|
||||
return this.dialogService.open(component as Type<any>, {
|
||||
...this.defaultDialogOptions,
|
||||
...options,
|
||||
});
|
||||
}
|
||||
|
||||
openDashboardSettingsDialog(): DynamicDialogRef | null {
|
||||
return this.openDialog(DashboardSettingsComponent, {
|
||||
showHeader: false,
|
||||
styleClass: `${DialogSize.XL} ${DialogStyle.MINIMAL}`,
|
||||
});
|
||||
}
|
||||
|
||||
openLibraryCreateDialog(): DynamicDialogRef | null {
|
||||
return this.openDialog(LibraryCreatorComponent, {
|
||||
showHeader: false,
|
||||
styleClass: `${DialogSize.MD} ${DialogStyle.MINIMAL}`,
|
||||
});
|
||||
}
|
||||
|
||||
openDirectoryPickerDialog(): DynamicDialogRef | null {
|
||||
return this.openDialog(DirectoryPickerComponent, {
|
||||
showHeader: false,
|
||||
styleClass: `${DialogSize.MD} ${DialogStyle.MINIMAL}`,
|
||||
});
|
||||
}
|
||||
|
||||
openLibraryEditDialog(libraryId: number): DynamicDialogRef | null {
|
||||
return this.openDialog(LibraryCreatorComponent, {
|
||||
showHeader: false,
|
||||
styleClass: `${DialogSize.MD} ${DialogStyle.MINIMAL}`,
|
||||
data: {
|
||||
mode: 'edit',
|
||||
libraryId: libraryId
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
openLibraryMetadataFetchDialog(libraryId: number): DynamicDialogRef | null {
|
||||
return this.openDialog(MetadataFetchOptionsComponent, {
|
||||
showHeader: false,
|
||||
styleClass: `${DialogSize.SM} ${DialogStyle.MINIMAL}`,
|
||||
data: {
|
||||
libraryId: libraryId,
|
||||
metadataRefreshType: MetadataRefreshType.LIBRARY,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
openShelfEditDialog(shelfId: number): DynamicDialogRef | null {
|
||||
return this.openDialog(ShelfEditDialogComponent, {
|
||||
showHeader: false,
|
||||
styleClass: `${DialogSize.SM} ${DialogStyle.MINIMAL}`,
|
||||
data: {
|
||||
shelfId: shelfId
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
openFileUploadDialog(): DynamicDialogRef | null {
|
||||
return this.openDialog(BookUploaderComponent, {
|
||||
showHeader: false,
|
||||
styleClass: `${DialogSize.MD} ${DialogStyle.MINIMAL}`,
|
||||
});
|
||||
}
|
||||
|
||||
openCreateUserDialog(): DynamicDialogRef | null {
|
||||
return this.openDialog(CreateUserDialogComponent, {
|
||||
showHeader: false,
|
||||
styleClass: `${DialogSize.LG} ${DialogStyle.MINIMAL}`,
|
||||
});
|
||||
}
|
||||
|
||||
openUserProfileDialog(): DynamicDialogRef | null {
|
||||
return this.openDialog(UserProfileDialogComponent, {
|
||||
showHeader: false,
|
||||
styleClass: `${DialogSize.SM} ${DialogStyle.MINIMAL}`,
|
||||
});
|
||||
}
|
||||
|
||||
openMagicShelfCreateDialog(): DynamicDialogRef | null {
|
||||
return this.openDialog(MagicShelfComponent, {
|
||||
showHeader: false,
|
||||
styleClass: `${DialogSize.XL} ${DialogStyle.MINIMAL}`,
|
||||
});
|
||||
}
|
||||
|
||||
openMagicShelfEditDialog(shelfId: number): DynamicDialogRef | null {
|
||||
return this.openDialog(MagicShelfComponent, {
|
||||
showHeader: false,
|
||||
styleClass: `${DialogSize.XL} ${DialogStyle.MINIMAL}`,
|
||||
data: {
|
||||
id: shelfId,
|
||||
editMode: true,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
openVersionChangelogDialog(): DynamicDialogRef | null {
|
||||
return this.openDialog(VersionChangelogDialogComponent, {
|
||||
showHeader: false,
|
||||
styleClass: `${DialogSize.LG} ${DialogStyle.MINIMAL}`,
|
||||
});
|
||||
}
|
||||
|
||||
openEmailRecipientDialog(): DynamicDialogRef | null {
|
||||
return this.openDialog(CreateEmailRecipientDialogComponent, {
|
||||
showHeader: false,
|
||||
styleClass: `${DialogSize.MD} ${DialogStyle.MINIMAL}`,
|
||||
});
|
||||
}
|
||||
|
||||
openEmailProviderDialog(): DynamicDialogRef | null {
|
||||
return this.openDialog(CreateEmailProviderDialogComponent, {
|
||||
showHeader: false,
|
||||
styleClass: `${DialogSize.MD} ${DialogStyle.MINIMAL}`,
|
||||
});
|
||||
}
|
||||
|
||||
openBookdropFinalizeResultDialog(result: BookdropFinalizeResult): DynamicDialogRef | null {
|
||||
return this.openDialog(BookdropFinalizeResultDialogComponent, {
|
||||
showHeader: false,
|
||||
styleClass: `${DialogSize.MD} ${DialogStyle.MINIMAL}`,
|
||||
data: {
|
||||
result: result,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
openMetadataReviewDialog(taskId: string): DynamicDialogRef | null {
|
||||
return this.openDialog(MetadataReviewDialogComponent, {
|
||||
showHeader: false,
|
||||
styleClass: `${DialogSize.FULL} ${DialogStyle.MINIMAL}`,
|
||||
data: {
|
||||
taskId,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
openIconPickerDialog(): DynamicDialogRef | null {
|
||||
return this.openDialog(IconPickerComponent, {
|
||||
showHeader: false,
|
||||
styleClass: `${DialogSize.LG} ${DialogStyle.MINIMAL}`,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {SafeHtml} from '@angular/platform-browser';
|
||||
import {BehaviorSubject} from 'rxjs';
|
||||
|
||||
interface CachedIcon {
|
||||
content: string;
|
||||
sanitized: SafeHtml;
|
||||
}
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class IconCacheService {
|
||||
private cache = new Map<string, CachedIcon>();
|
||||
|
||||
private cacheUpdate$ = new BehaviorSubject<string | null>(null);
|
||||
|
||||
getCachedSanitized(iconName: string): SafeHtml | null {
|
||||
const cached = this.cache.get(iconName);
|
||||
|
||||
if (!cached) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return cached.sanitized;
|
||||
}
|
||||
|
||||
cacheIcon(iconName: string, content: string, sanitized: SafeHtml): void {
|
||||
this.cache.set(iconName, {
|
||||
content,
|
||||
sanitized
|
||||
});
|
||||
this.cacheUpdate$.next(iconName);
|
||||
}
|
||||
|
||||
removeIcon(iconName: string): boolean {
|
||||
return this.cache.delete(iconName);
|
||||
}
|
||||
|
||||
getAllIconNames(): string[] {
|
||||
return Array.from(this.cache.keys()).sort();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
import { inject, Injectable } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { finalize, map, shareReplay, tap } from 'rxjs/operators';
|
||||
import { API_CONFIG } from '../../core/config/api-config';
|
||||
import { IconCacheService } from './icon-cache.service';
|
||||
import { DomSanitizer, SafeHtml } from '@angular/platform-browser';
|
||||
import DOMPurify from 'dompurify';
|
||||
|
||||
interface SvgIconData {
|
||||
svgName: string;
|
||||
svgData: string;
|
||||
}
|
||||
|
||||
interface IconSaveResult {
|
||||
iconName: string;
|
||||
success: boolean;
|
||||
errorMessage: string;
|
||||
}
|
||||
|
||||
interface SvgIconBatchResponse {
|
||||
totalRequested: number;
|
||||
successCount: number;
|
||||
failureCount: number;
|
||||
results: IconSaveResult[];
|
||||
}
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class IconService {
|
||||
|
||||
private readonly baseUrl = `${API_CONFIG.BASE_URL}/api/v1/icons`;
|
||||
private requestCache = new Map<string, Observable<string>>();
|
||||
|
||||
private http = inject(HttpClient);
|
||||
private iconCache = inject(IconCacheService);
|
||||
private sanitizer = inject(DomSanitizer);
|
||||
|
||||
/**
|
||||
* Sanitizes SVG content using DOMPurify.
|
||||
*/
|
||||
private sanitizeSvgContent(content: string): string {
|
||||
return DOMPurify.sanitize(content, {
|
||||
USE_PROFILES: { svg: true },
|
||||
FORBID_TAGS: ['script', 'style', 'foreignObject']
|
||||
});
|
||||
}
|
||||
|
||||
getIconNames(page: number = 0, size: number = 1000): Observable<string[]> {
|
||||
return this.http.get<{ content: string[] }>(`${this.baseUrl}?page=${page}&size=${size}`).pipe(
|
||||
map(response => response.content)
|
||||
);
|
||||
}
|
||||
|
||||
getSvgIconContent(iconName: string): Observable<string> {
|
||||
const cached = this.iconCache.getCachedSanitized(iconName);
|
||||
if (cached) {
|
||||
return of('');
|
||||
}
|
||||
|
||||
if (!this.requestCache.has(iconName)) {
|
||||
const request$ = this.http.get(`${this.baseUrl}/${encodeURIComponent(iconName)}/content`, {
|
||||
responseType: 'text'
|
||||
}).pipe(
|
||||
tap(content => {
|
||||
const sanitized = this.sanitizer.bypassSecurityTrustHtml(this.sanitizeSvgContent(content));
|
||||
this.iconCache.cacheIcon(iconName, content, sanitized);
|
||||
}),
|
||||
shareReplay({ bufferSize: 1, refCount: true }),
|
||||
finalize(() => this.requestCache.delete(iconName))
|
||||
);
|
||||
|
||||
this.requestCache.set(iconName, request$);
|
||||
}
|
||||
|
||||
return this.requestCache.get(iconName)!;
|
||||
}
|
||||
|
||||
getSanitizedSvgContent(iconName: string): Observable<SafeHtml> {
|
||||
const cached = this.iconCache.getCachedSanitized(iconName);
|
||||
if (cached) {
|
||||
return of(cached);
|
||||
}
|
||||
|
||||
return new Observable<SafeHtml>(observer => {
|
||||
this.getSvgIconContent(iconName).subscribe({
|
||||
next: () => {
|
||||
const sanitized = this.iconCache.getCachedSanitized(iconName);
|
||||
if (sanitized) {
|
||||
observer.next(sanitized);
|
||||
observer.complete();
|
||||
}
|
||||
},
|
||||
error: (err) => observer.error(err)
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
deleteSvgIcon(svgName: string): Observable<unknown> {
|
||||
return this.http.delete(`${this.baseUrl}/${encodeURIComponent(svgName)}`).pipe(
|
||||
tap(() => {
|
||||
this.iconCache.removeIcon(svgName);
|
||||
this.requestCache.delete(svgName);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
saveBatchSvgIcons(icons: SvgIconData[]): Observable<SvgIconBatchResponse> {
|
||||
return this.http.post<SvgIconBatchResponse>(`${this.baseUrl}/batch`, { icons }).pipe(
|
||||
tap((response) => {
|
||||
response.results.forEach(result => {
|
||||
if (result.success) {
|
||||
const iconData = icons.find(icon => icon.svgName === result.iconName);
|
||||
if (iconData) {
|
||||
const sanitized = this.sanitizer.bypassSecurityTrustHtml(this.sanitizeSvgContent(iconData.svgData));
|
||||
this.iconCache.cacheIcon(iconData.svgName, iconData.svgData, sanitized);
|
||||
}
|
||||
}
|
||||
});
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user