refactor(ui): replace SVG artwork placeholders with CSS (#292)
* chore(ui): replace SVG placeholders with CSS alternative * fix(ui): Placeholder review followup
This commit is contained in:
+11
-7
@@ -6,13 +6,17 @@
|
||||
(keydown.enter)="onCardClick($event)">
|
||||
|
||||
<div class="cover-container" [ngClass]="{ 'center-info-btn': _isSeriesViewActive || !hasDigitalFile(), 'audiobook-cover': _isAudiobook, 'square-library-cover': useSquareCovers }">
|
||||
<img
|
||||
[src]="coverImageUrl"
|
||||
class="book-cover"
|
||||
[class.square-cover]="_isAudiobook || useSquareCovers"
|
||||
[alt]="('book.card.alt.cover' | transloco: { title: displayTitle })"
|
||||
loading="lazy"
|
||||
decoding="async"/>
|
||||
@if (coverImageUrl) {
|
||||
<img
|
||||
[src]="coverImageUrl"
|
||||
class="book-cover"
|
||||
[class.square-cover]="_isAudiobook || useSquareCovers"
|
||||
[alt]="('book.card.alt.cover' | transloco: { title: displayTitle })"
|
||||
loading="lazy"
|
||||
decoding="async"/>
|
||||
} @else {
|
||||
<app-cover-placeholder class="book-cover" [class.square-cover]="_isAudiobook || useSquareCovers" [title]="book.metadata?.title ?? ''" [author]="(book.metadata?.authors ?? []).join(', ')" />
|
||||
}
|
||||
|
||||
<div class="top-left-overlay-stack">
|
||||
@if ((overlayPreferenceService?.showBookTypePill() ?? true) && getDisplayFormat(); as displayFormat) {
|
||||
|
||||
+4
-3
@@ -11,6 +11,7 @@ import {CheckboxChangeEvent, CheckboxModule} from 'primeng/checkbox';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {MetadataRefreshType} from '../../../../metadata/model/request/metadata-refresh-type.enum';
|
||||
import {UrlHelperService} from '../../../../../shared/service/url-helper.service';
|
||||
import {CoverPlaceholderComponent} from '../../../../../shared/components/cover-generator/cover-generator.component';
|
||||
import {NgClass} from '@angular/common';
|
||||
import {User, UserService} from '../../../../settings/user-management/user.service';
|
||||
import {EmailService} from '../../../../settings/email-v2/email.service';
|
||||
@@ -33,7 +34,7 @@ import {QueryClient} from '@tanstack/angular-query-experimental';
|
||||
selector: 'app-book-card',
|
||||
templateUrl: './book-card.component.html',
|
||||
styleUrls: ['./book-card.component.scss'],
|
||||
imports: [Button, MenuModule, CheckboxModule, FormsModule, NgClass, TieredMenu, ProgressBar, TooltipModule, RouterLink, TranslocoPipe],
|
||||
imports: [Button, MenuModule, CheckboxModule, FormsModule, NgClass, TieredMenu, ProgressBar, TooltipModule, RouterLink, TranslocoPipe, CoverPlaceholderComponent],
|
||||
standalone: true,
|
||||
changeDetection: ChangeDetectionStrategy.OnPush
|
||||
})
|
||||
@@ -82,7 +83,7 @@ export class BookCardComponent implements OnInit, OnChanges {
|
||||
protected _koboProgressPercentage: number | null = null;
|
||||
protected _displayTitle: string | undefined = undefined;
|
||||
protected _isSeriesViewActive: boolean = false;
|
||||
protected _coverImageUrl: string = '';
|
||||
protected _coverImageUrl: string | null = null;
|
||||
protected _readStatusIcon: string = '';
|
||||
protected _readStatusClass: string = '';
|
||||
protected _readStatusTooltip: string = '';
|
||||
@@ -214,7 +215,7 @@ export class BookCardComponent implements OnInit, OnChanges {
|
||||
return this._displayTitle;
|
||||
}
|
||||
|
||||
get coverImageUrl(): string {
|
||||
get coverImageUrl(): string | null {
|
||||
return this._coverImageUrl;
|
||||
}
|
||||
|
||||
|
||||
+21
-13
@@ -51,22 +51,30 @@
|
||||
</td>
|
||||
<td>
|
||||
<a [routerLink]="urlHelper.getBookUrl(book)">
|
||||
<img
|
||||
[attr.src]="urlHelper.getThumbnailUrl(metadata.bookId, metadata.coverUpdatedOn)"
|
||||
[alt]="t('bookCoverAlt')"
|
||||
class="cover-thumbnail"
|
||||
tooltipPosition="left"
|
||||
[pTooltip]="tooltipContent"
|
||||
tooltipStyleClass="cover-tooltip"
|
||||
/>
|
||||
@if (urlHelper.getThumbnailUrl(metadata.bookId, metadata.coverUpdatedOn); as coverUrl) {
|
||||
<img
|
||||
[attr.src]="coverUrl"
|
||||
[alt]="t('bookCoverAlt')"
|
||||
class="cover-thumbnail"
|
||||
tooltipPosition="left"
|
||||
[pTooltip]="tooltipContent"
|
||||
tooltipStyleClass="cover-tooltip"
|
||||
/>
|
||||
} @else {
|
||||
<app-cover-placeholder class="cover-thumbnail" [title]="metadata.title ?? ''" [author]="(metadata.authors ?? []).join(', ')" size="sm" />
|
||||
}
|
||||
</a>
|
||||
<ng-template #tooltipContent>
|
||||
<div class="tooltip-cover-container">
|
||||
<img
|
||||
[attr.src]="urlHelper.getThumbnailUrl(metadata.bookId, metadata.coverUpdatedOn)"
|
||||
[alt]="t('bookCoverAlt')"
|
||||
class="tooltip-cover-image"
|
||||
/>
|
||||
@if (urlHelper.getThumbnailUrl(metadata.bookId, metadata.coverUpdatedOn); as coverUrl) {
|
||||
<img
|
||||
[attr.src]="coverUrl"
|
||||
[alt]="t('bookCoverAlt')"
|
||||
class="tooltip-cover-image"
|
||||
/>
|
||||
} @else {
|
||||
<app-cover-placeholder class="tooltip-cover-image" [title]="metadata.title ?? ''" [author]="(metadata.authors ?? []).join(', ')" />
|
||||
}
|
||||
<em class="tooltip-cover-title">{{ metadata.title }}</em>
|
||||
</div>
|
||||
</ng-template>
|
||||
|
||||
+3
-1
@@ -7,6 +7,7 @@ import {TooltipModule} from "primeng/tooltip";
|
||||
import {Book, BookMetadata, ReadStatus} from '../../../model/book.model';
|
||||
import {SortOption} from '../../../model/sort.model';
|
||||
import {UrlHelperService} from '../../../../../shared/service/url-helper.service';
|
||||
import {CoverPlaceholderComponent} from '../../../../../shared/components/cover-generator/cover-generator.component';
|
||||
import {Button} from 'primeng/button';
|
||||
import {BookService} from '../../../service/book.service';
|
||||
import {BookMetadataManageService} from '../../../service/book-metadata-manage.service';
|
||||
@@ -29,7 +30,8 @@ import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
||||
TooltipModule,
|
||||
NgClass,
|
||||
RouterLink,
|
||||
TranslocoDirective
|
||||
TranslocoDirective,
|
||||
CoverPlaceholderComponent
|
||||
],
|
||||
styleUrls: ['./book-table.component.scss'],
|
||||
providers: [DatePipe]
|
||||
|
||||
+9
-5
@@ -1,9 +1,13 @@
|
||||
<div class="book-cover-wrapper" [class.audiobook-only]="isAudiobookOnly()" (mouseenter)="isHovered = true" (mouseleave)="isHovered = false">
|
||||
<img
|
||||
[src]="getThumbnailUrl()"
|
||||
class="book-cover"
|
||||
alt="Cover of {{ book.metadata?.title }}"
|
||||
loading="lazy"/>
|
||||
@if (getThumbnailUrl(); as coverUrl) {
|
||||
<img
|
||||
[src]="coverUrl"
|
||||
class="book-cover"
|
||||
alt="Cover of {{ book.metadata?.title }}"
|
||||
loading="lazy"/>
|
||||
} @else {
|
||||
<app-cover-placeholder class="book-cover" [title]="book.metadata?.title ?? ''" [author]="(book.metadata?.authors ?? []).join(', ')" size="sm" />
|
||||
}
|
||||
|
||||
@if (showSeriesNumber && !book.seriesCount && book.metadata?.seriesNumber !== null && book.metadata?.seriesNumber !== undefined) {
|
||||
<div class="series-number-overlay">
|
||||
|
||||
+4
-2
@@ -1,6 +1,7 @@
|
||||
import {ChangeDetectionStrategy, Component, computed, inject, Input} from '@angular/core';
|
||||
import {Book} from '../../model/book.model';
|
||||
import {UrlHelperService} from '../../../../shared/service/url-helper.service';
|
||||
import {CoverPlaceholderComponent} from '../../../../shared/components/cover-generator/cover-generator.component';
|
||||
import {Button} from 'primeng/button';
|
||||
import {UserService} from '../../../settings/user-management/user.service';
|
||||
import {Router} from '@angular/router';
|
||||
@@ -14,7 +15,8 @@ import {TooltipModule} from 'primeng/tooltip';
|
||||
imports: [
|
||||
Button,
|
||||
NgClass,
|
||||
TooltipModule
|
||||
TooltipModule,
|
||||
CoverPlaceholderComponent
|
||||
],
|
||||
templateUrl: './book-card-lite-component.html',
|
||||
styleUrl: './book-card-lite-component.scss'
|
||||
@@ -40,7 +42,7 @@ export class BookCardLiteComponent {
|
||||
return primaryIsAudiobook && !hasEbookAlternative;
|
||||
}
|
||||
|
||||
getThumbnailUrl(): string {
|
||||
getThumbnailUrl(): string | null {
|
||||
if (this.isAudiobookOnly()) {
|
||||
return this.urlHelper.getAudiobookThumbnailUrl(this.book.id, this.book.metadata?.audiobookCoverUpdatedOn);
|
||||
}
|
||||
|
||||
+9
-5
@@ -49,11 +49,15 @@
|
||||
(click)="onBookClick(book)"
|
||||
(keydown.enter)="onBookClick(book)">
|
||||
<div class="search-item-content">
|
||||
<img
|
||||
[attr.src]="urlHelper.getThumbnailUrl(book.id, book.metadata?.coverUpdatedOn)"
|
||||
[alt]="t('bookCoverAlt')"
|
||||
class="search-book-cover"
|
||||
/>
|
||||
@if (urlHelper.getThumbnailUrl(book.id, book.metadata?.coverUpdatedOn); as coverUrl) {
|
||||
<img
|
||||
[attr.src]="coverUrl"
|
||||
[alt]="t('bookCoverAlt')"
|
||||
class="search-book-cover"
|
||||
/>
|
||||
} @else {
|
||||
<app-cover-placeholder class="search-book-cover" [title]="book.metadata?.title ?? ''" [author]="(book.metadata?.authors ?? []).join(', ')" size="sm" />
|
||||
}
|
||||
<div class="search-book-details">
|
||||
<div class="search-book-title-container">
|
||||
<p class="search-book-name">
|
||||
|
||||
@@ -9,6 +9,7 @@ import {Button} from 'primeng/button';
|
||||
import {SlicePipe} from '@angular/common';
|
||||
import {Skeleton} from 'primeng/skeleton';
|
||||
import {UrlHelperService} from '../../../../shared/service/url-helper.service';
|
||||
import {CoverPlaceholderComponent} from '../../../../shared/components/cover-generator/cover-generator.component';
|
||||
import {Router} from '@angular/router';
|
||||
import {IconField} from 'primeng/iconfield';
|
||||
import {InputIcon} from 'primeng/inputicon';
|
||||
@@ -27,6 +28,7 @@ import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
||||
IconField,
|
||||
InputIcon,
|
||||
TranslocoDirective,
|
||||
CoverPlaceholderComponent,
|
||||
],
|
||||
styleUrls: ['./book-searcher.component.scss'],
|
||||
standalone: true
|
||||
|
||||
+8
-4
@@ -186,10 +186,14 @@
|
||||
class="delete-checkbox">
|
||||
</p-checkbox>
|
||||
}
|
||||
<img class="book-cover"
|
||||
[src]="urlHelper.getThumbnailUrl(book.id, book.metadata?.coverUpdatedOn)"
|
||||
[alt]="book.metadata?.title || ''"
|
||||
loading="lazy"/>
|
||||
@if (urlHelper.getThumbnailUrl(book.id, book.metadata?.coverUpdatedOn); as coverUrl) {
|
||||
<img class="book-cover"
|
||||
[src]="coverUrl"
|
||||
[alt]="book.metadata?.title || ''"
|
||||
loading="lazy"/>
|
||||
} @else {
|
||||
<app-cover-placeholder class="book-cover" [title]="book.metadata?.title ?? ''" [author]="(book.metadata?.authors ?? []).join(', ')" size="sm" />
|
||||
}
|
||||
<div class="book-info">
|
||||
<div class="book-title">{{ book.metadata?.title || ('book.fileAttacher.unknownTitle' | transloco) }}</div>
|
||||
@if (book.metadata?.authors?.length) {
|
||||
|
||||
+2
@@ -15,6 +15,7 @@ import {Book, DuplicateDetectionRequest, DuplicateGroup} from '../../model/book.
|
||||
import {ConfirmationService, MessageService} from 'primeng/api';
|
||||
import {TranslocoDirective, TranslocoPipe, TranslocoService} from '@jsverse/transloco';
|
||||
import {UrlHelperService} from '../../../../shared/service/url-helper.service';
|
||||
import {CoverPlaceholderComponent} from '../../../../shared/components/cover-generator/cover-generator.component';
|
||||
import {AppSettingsService} from '../../../../shared/service/app-settings.service';
|
||||
|
||||
type PresetMode = 'strict' | 'balanced' | 'aggressive' | 'custom';
|
||||
@@ -39,6 +40,7 @@ interface DisplayGroup extends DuplicateGroup {
|
||||
Paginator,
|
||||
TranslocoDirective,
|
||||
TranslocoPipe,
|
||||
CoverPlaceholderComponent,
|
||||
],
|
||||
templateUrl: './duplicate-merger.component.html',
|
||||
styleUrls: ['./duplicate-merger.component.scss']
|
||||
|
||||
@@ -32,12 +32,16 @@
|
||||
<div class="series-hero">
|
||||
@if (coverBook(); as coverBook) {
|
||||
<div class="hero-cover-section">
|
||||
<img
|
||||
[src]="getBookThumbnailUrl(coverBook)"
|
||||
class="hero-cover-img"
|
||||
[alt]="coverBook.metadata?.title || ''"
|
||||
loading="lazy"
|
||||
decoding="async"/>
|
||||
@if (getBookThumbnailUrl(coverBook); as coverUrl) {
|
||||
<img
|
||||
[src]="coverUrl"
|
||||
class="hero-cover-img"
|
||||
[alt]="coverBook.metadata?.title || ''"
|
||||
loading="lazy"
|
||||
decoding="async"/>
|
||||
} @else {
|
||||
<app-cover-placeholder class="hero-cover-img" [title]="coverBook.metadata?.title ?? ''" [author]="(coverBook.metadata?.authors ?? []).join(', ')" size="lg" />
|
||||
}
|
||||
</div>
|
||||
}
|
||||
|
||||
@@ -186,10 +190,14 @@
|
||||
tabindex="0"
|
||||
(click)="readBook(nextUp.book.id)"
|
||||
(keydown.enter)="readBook(nextUp.book.id)">
|
||||
<img [src]="nextUp.thumbnailUrl"
|
||||
[alt]="nextUp.book.metadata?.title || ''"
|
||||
class="next-up-thumb"
|
||||
loading="lazy"/>
|
||||
@if (nextUp.thumbnailUrl) {
|
||||
<img [src]="nextUp.thumbnailUrl"
|
||||
[alt]="nextUp.book.metadata?.title || ''"
|
||||
class="next-up-thumb"
|
||||
loading="lazy"/>
|
||||
} @else {
|
||||
<app-cover-placeholder class="next-up-thumb" [title]="nextUp.book.metadata?.title ?? ''" [author]="(nextUp.book.metadata?.authors ?? []).join(', ')" size="sm" />
|
||||
}
|
||||
<div class="next-up-info">
|
||||
<span class="next-up-label">
|
||||
<i class="pi pi-bookmark-fill"></i>
|
||||
@@ -310,10 +318,14 @@
|
||||
{{ book.metadata?.seriesNumber !== null && book.metadata?.seriesNumber !== undefined ? '#' + book.metadata?.seriesNumber : '-' }}
|
||||
</span>
|
||||
</div>
|
||||
<img [src]="getBookThumbnailUrl(book)"
|
||||
[alt]="book.metadata?.title || ''"
|
||||
class="list-thumb"
|
||||
loading="lazy"/>
|
||||
@if (getBookThumbnailUrl(book); as coverUrl) {
|
||||
<img [src]="coverUrl"
|
||||
[alt]="book.metadata?.title || ''"
|
||||
class="list-thumb"
|
||||
loading="lazy"/>
|
||||
} @else {
|
||||
<app-cover-placeholder class="list-thumb" [title]="book.metadata?.title ?? ''" [author]="(book.metadata?.authors ?? []).join(', ')" size="sm" />
|
||||
}
|
||||
<div class="list-book-info">
|
||||
<span class="list-book-title">{{ book.metadata?.title || '' }}</span>
|
||||
<div class="list-book-meta">
|
||||
|
||||
@@ -31,6 +31,7 @@ import {animate, style, transition, trigger} from "@angular/animations";
|
||||
import {AfterViewChecked, Component, computed, effect, ElementRef, inject, ViewChild} from '@angular/core';
|
||||
import {BookCardOverlayPreferenceService} from '../book-browser/book-card-overlay-preference.service';
|
||||
import {UrlHelperService} from '../../../../shared/service/url-helper.service';
|
||||
import {CoverPlaceholderComponent} from '../../../../shared/components/cover-generator/cover-generator.component';
|
||||
import {injectQuery} from '@tanstack/angular-query-experimental';
|
||||
|
||||
interface ReadStatusSegment {
|
||||
@@ -48,7 +49,7 @@ interface SeriesCompletion {
|
||||
|
||||
interface NextUpBook {
|
||||
book: Book;
|
||||
thumbnailUrl: string;
|
||||
thumbnailUrl: string | null;
|
||||
isReading: boolean;
|
||||
progressPercent: number | null;
|
||||
}
|
||||
@@ -88,7 +89,8 @@ interface SeriesStats {
|
||||
Tooltip,
|
||||
Divider,
|
||||
TranslocoDirective,
|
||||
TagComponent
|
||||
TagComponent,
|
||||
CoverPlaceholderComponent
|
||||
],
|
||||
animations: [
|
||||
trigger('slideInOut', [
|
||||
@@ -479,7 +481,7 @@ export class SeriesPageComponent implements AfterViewChecked {
|
||||
}
|
||||
}
|
||||
|
||||
getBookThumbnailUrl(book: Book): string {
|
||||
getBookThumbnailUrl(book: Book): string | null {
|
||||
const isAudiobook = book.primaryFile?.bookType === 'AUDIOBOOK';
|
||||
return isAudiobook
|
||||
? this.urlHelper.getAudiobookThumbnailUrl(book.id, book.metadata?.audiobookCoverUpdatedOn)
|
||||
|
||||
+25
-17
@@ -17,14 +17,18 @@
|
||||
<i class="pi pi-book"></i> {{ t('ebookCover') }}
|
||||
</div>
|
||||
}
|
||||
<p-image
|
||||
[src]="urlHelper.getCoverUrl(book.id, book.metadata?.coverUpdatedOn)"
|
||||
alt="Cover Image"
|
||||
width="200"
|
||||
appendTo="body"
|
||||
lazyLoad
|
||||
[preview]="true">
|
||||
</p-image>
|
||||
@if (urlHelper.getCoverUrl(book.id, book.metadata?.coverUpdatedOn); as coverUrl) {
|
||||
<p-image
|
||||
[src]="coverUrl"
|
||||
alt="Cover Image"
|
||||
width="200"
|
||||
appendTo="body"
|
||||
lazyLoad
|
||||
[preview]="true">
|
||||
</p-image>
|
||||
} @else {
|
||||
<app-cover-placeholder style="width: 200px; height: 280px;" [title]="book.metadata?.title ?? ''" [author]="(book.metadata?.authors ?? []).join(', ')" size="lg" />
|
||||
}
|
||||
@if (isUploading) {
|
||||
<p-progressSpinner class="upload-spinner"></p-progressSpinner>
|
||||
}
|
||||
@@ -94,15 +98,19 @@
|
||||
<div class="cover-type-label audiobook">
|
||||
<i class="pi pi-headphones"></i> {{ t('audiobookCover') }}
|
||||
</div>
|
||||
<p-image
|
||||
[src]="urlHelper.getAudiobookCoverUrl(book.id, book.metadata?.audiobookCoverUpdatedOn)"
|
||||
alt="Audiobook Cover"
|
||||
width="200"
|
||||
appendTo="body"
|
||||
lazyLoad
|
||||
[preview]="true"
|
||||
class="square-cover">
|
||||
</p-image>
|
||||
@if (urlHelper.getAudiobookCoverUrl(book.id, book.metadata?.audiobookCoverUpdatedOn); as coverUrl) {
|
||||
<p-image
|
||||
[src]="coverUrl"
|
||||
alt="Audiobook Cover"
|
||||
width="200"
|
||||
appendTo="body"
|
||||
lazyLoad
|
||||
[preview]="true"
|
||||
class="square-cover">
|
||||
</p-image>
|
||||
} @else {
|
||||
<app-cover-placeholder style="width: 200px; height: 200px;" [title]="book.metadata?.title ?? ''" [author]="(book.metadata?.authors ?? []).join(', ')" size="lg" />
|
||||
}
|
||||
@if (isUploading) {
|
||||
<p-progressSpinner class="upload-spinner"></p-progressSpinner>
|
||||
}
|
||||
|
||||
+2
@@ -7,6 +7,7 @@ import {Observable, sample} from "rxjs";
|
||||
import {MessageService} from "primeng/api";
|
||||
import {Book, BookMetadata, ComicMetadata, MetadataClearFlags, MetadataUpdateWrapper,} from "../../../../book/model/book.model";
|
||||
import {UrlHelperService} from "../../../../../shared/service/url-helper.service";
|
||||
import {CoverPlaceholderComponent} from "../../../../../shared/components/cover-generator/cover-generator.component";
|
||||
import {ALL_COMIC_METADATA_FIELDS, AUDIOBOOK_METADATA_FIELDS, COMIC_FORM_TO_MODEL_LOCK, COMIC_TEXT_METADATA_FIELDS, COMIC_ARRAY_METADATA_FIELDS, COMIC_TEXTAREA_METADATA_FIELDS, isFieldEmbeddable, hasMetadataWriter} from '../../../../../shared/metadata';
|
||||
import {FileUpload, FileUploadErrorEvent, FileUploadEvent,} from "primeng/fileupload";
|
||||
import {HttpResponse} from "@angular/common/http";
|
||||
@@ -57,6 +58,7 @@ import {CdkDragDrop, CdkDropList, CdkDrag, moveItemInArray} from '@angular/cdk/d
|
||||
TranslocoDirective,
|
||||
CdkDropList,
|
||||
CdkDrag,
|
||||
CoverPlaceholderComponent,
|
||||
],
|
||||
})
|
||||
export class MetadataEditorComponent implements OnInit {
|
||||
|
||||
+23
-15
@@ -73,26 +73,34 @@
|
||||
<div class="cover-label">
|
||||
<i class="pi pi-book"></i> {{ t('ebookCover') }}
|
||||
</div>
|
||||
<p-image
|
||||
[src]="urlHelper.getCoverUrl(book.id, book.metadata?.coverUpdatedOn)"
|
||||
[alt]="t('ebookCover')"
|
||||
width="200"
|
||||
appendTo="body"
|
||||
[preview]="true">
|
||||
</p-image>
|
||||
@if (urlHelper.getCoverUrl(book.id, book.metadata?.coverUpdatedOn); as coverUrl) {
|
||||
<p-image
|
||||
[src]="coverUrl"
|
||||
[alt]="t('ebookCover')"
|
||||
width="200"
|
||||
appendTo="body"
|
||||
[preview]="true">
|
||||
</p-image>
|
||||
} @else {
|
||||
<app-cover-placeholder style="width: 200px; height: 280px;" [title]="book.metadata?.title ?? ''" [author]="(book.metadata?.authors ?? []).join(', ')" size="lg" />
|
||||
}
|
||||
</div>
|
||||
<div class="cover-item">
|
||||
<div class="cover-label audiobook">
|
||||
<i class="pi pi-headphones"></i> {{ t('audiobookCover') }}
|
||||
</div>
|
||||
<p-image
|
||||
[src]="urlHelper.getAudiobookCoverUrl(book.id, book.metadata?.audiobookCoverUpdatedOn)"
|
||||
[alt]="t('audiobookCover')"
|
||||
width="200"
|
||||
appendTo="body"
|
||||
[preview]="true"
|
||||
class="square-cover">
|
||||
</p-image>
|
||||
@if (urlHelper.getAudiobookCoverUrl(book.id, book.metadata?.audiobookCoverUpdatedOn); as coverUrl) {
|
||||
<p-image
|
||||
[src]="coverUrl"
|
||||
[alt]="t('audiobookCover')"
|
||||
width="200"
|
||||
appendTo="body"
|
||||
[preview]="true"
|
||||
class="square-cover">
|
||||
</p-image>
|
||||
} @else {
|
||||
<app-cover-placeholder style="width: 200px; height: 200px;" [title]="book.metadata?.title ?? ''" [author]="(book.metadata?.authors ?? []).join(', ')" size="lg" />
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
+3
-1
@@ -11,6 +11,7 @@ import {Button} from 'primeng/button';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
import {Image} from 'primeng/image';
|
||||
import {UrlHelperService} from '../../../../../../shared/service/url-helper.service';
|
||||
import {CoverPlaceholderComponent} from '../../../../../../shared/components/cover-generator/cover-generator.component';
|
||||
import {BookMetadataManageService} from '../../../../../book/service/book-metadata-manage.service';
|
||||
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
||||
import {AudiobookService} from '../../../../../readers/audiobook-player/audiobook.service';
|
||||
@@ -73,7 +74,8 @@ export interface DetachBookFileEvent {
|
||||
Tooltip,
|
||||
UpperCasePipe,
|
||||
Image,
|
||||
TranslocoDirective
|
||||
TranslocoDirective,
|
||||
CoverPlaceholderComponent
|
||||
],
|
||||
templateUrl: './metadata-tabs.component.html',
|
||||
styleUrl: './metadata-tabs.component.scss'
|
||||
|
||||
+11
-7
@@ -5,13 +5,17 @@
|
||||
<div class="cover-section">
|
||||
<div class="cover-wrapper">
|
||||
|
||||
<p-image
|
||||
[src]="getBookCoverUrl(book)"
|
||||
alt="Image"
|
||||
width="250"
|
||||
appendTo="body"
|
||||
[preview]="true">
|
||||
</p-image>
|
||||
@if (getBookCoverUrl(book); as coverUrl) {
|
||||
<p-image
|
||||
[src]="coverUrl"
|
||||
[alt]="book.metadata?.title ? ('Cover of ' + book.metadata?.title) : ''"
|
||||
width="250"
|
||||
appendTo="body"
|
||||
[preview]="true">
|
||||
</p-image>
|
||||
} @else {
|
||||
<app-cover-placeholder style="width: 250px; height: 350px;" [title]="book.metadata?.title ?? ''" [author]="(book.metadata?.authors ?? []).join(', ')" size="lg" />
|
||||
}
|
||||
|
||||
@if (book?.metadata!.seriesNumber !== null && book?.metadata!.seriesNumber !== undefined) {
|
||||
<div class="series-badge">
|
||||
|
||||
+3
-2
@@ -7,6 +7,7 @@ import {Rating, RatingRateEvent} from 'primeng/rating';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {Book, BookFile, BookMetadata, BookRecommendation, BookType, ComicMetadata, FileInfo, ReadStatus} from '../../../../book/model/book.model';
|
||||
import {UrlHelperService} from '../../../../../shared/service/url-helper.service';
|
||||
import {CoverPlaceholderComponent} from '../../../../../shared/components/cover-generator/cover-generator.component';
|
||||
import {UserService} from '../../../../settings/user-management/user.service';
|
||||
import {SplitButton} from 'primeng/splitbutton';
|
||||
import {ConfirmationService, MenuItem, MessageService} from 'primeng/api';
|
||||
@@ -45,7 +46,7 @@ import DOMPurify from 'dompurify';
|
||||
standalone: true,
|
||||
templateUrl: './metadata-viewer.component.html',
|
||||
styleUrl: './metadata-viewer.component.scss',
|
||||
imports: [Button, Rating, FormsModule, SplitButton, NgClass, Tooltip, DecimalPipe, ProgressBar, Menu, DatePicker, ProgressSpinner, TieredMenu, Image, TagComponent, MetadataTabsComponent, TranslocoDirective, TranslocoPipe, Dialog, Checkbox]
|
||||
imports: [Button, Rating, FormsModule, SplitButton, NgClass, Tooltip, DecimalPipe, ProgressBar, Menu, DatePicker, ProgressSpinner, TieredMenu, Image, TagComponent, MetadataTabsComponent, TranslocoDirective, TranslocoPipe, Dialog, Checkbox, CoverPlaceholderComponent]
|
||||
})
|
||||
export class MetadataViewerComponent implements OnInit, OnChanges, AfterViewChecked {
|
||||
private currentBook = signal<Book | null>(null);
|
||||
@@ -1281,7 +1282,7 @@ export class MetadataViewerComponent implements OnInit, OnChanges, AfterViewChec
|
||||
return !this.hasAnyFiles(book);
|
||||
}
|
||||
|
||||
getBookCoverUrl(book: Book): string {
|
||||
getBookCoverUrl(book: Book): string | null {
|
||||
const isAudiobook = book.primaryFile?.bookType === 'AUDIOBOOK';
|
||||
return isAudiobook
|
||||
? this.urlHelper.getAudiobookCoverUrl(book.id, book.metadata?.audiobookCoverUpdatedOn)
|
||||
|
||||
@@ -138,7 +138,11 @@
|
||||
<div class="settings-card book-group-card">
|
||||
<!-- Book Header -->
|
||||
<div class="book-group-header" role="button" tabindex="0" (click)="toggleGroup(group.bookId)" (keydown.enter)="toggleGroup(group.bookId)">
|
||||
<img [src]="group.thumbnailUrl" [alt]="group.bookTitle" class="book-thumbnail" />
|
||||
@if (group.thumbnailUrl) {
|
||||
<img [src]="group.thumbnailUrl" [alt]="group.bookTitle" class="book-thumbnail" />
|
||||
} @else {
|
||||
<app-cover-placeholder class="book-thumbnail" [title]="group.bookTitle" size="sm" />
|
||||
}
|
||||
<div class="book-info">
|
||||
<span class="book-title">{{ group.bookTitle }}</span>
|
||||
<span class="book-entry-count">
|
||||
|
||||
@@ -12,12 +12,13 @@ import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
||||
import {NotebookService} from '../../service/notebook.service';
|
||||
import {NotebookEntry, NotebookPage} from '../../model/notebook.model';
|
||||
import {UrlHelperService} from '../../../../shared/service/url-helper.service';
|
||||
import {CoverPlaceholderComponent} from '../../../../shared/components/cover-generator/cover-generator.component';
|
||||
import {PageTitleService} from '../../../../shared/service/page-title.service';
|
||||
|
||||
interface BookGroup {
|
||||
bookId: number;
|
||||
bookTitle: string;
|
||||
thumbnailUrl: string;
|
||||
thumbnailUrl: string | null;
|
||||
entries: NotebookEntry[];
|
||||
}
|
||||
|
||||
@@ -43,6 +44,7 @@ const EMPTY_PAGE: NotebookPage = {
|
||||
TooltipModule,
|
||||
Paginator,
|
||||
TranslocoDirective,
|
||||
CoverPlaceholderComponent,
|
||||
],
|
||||
templateUrl: './notebook.component.html',
|
||||
styleUrls: ['./notebook.component.scss'],
|
||||
@@ -184,7 +186,7 @@ export class NotebookComponent implements OnInit, OnDestroy {
|
||||
bookId: entry.bookId,
|
||||
bookTitle: entry.bookTitle,
|
||||
thumbnailUrl: isAudiobook
|
||||
? this.urlHelper.getAudiobookThumbnailUrl(entry.bookId)
|
||||
? this.urlHelper.getDirectAudiobookThumbnailUrl(entry.bookId)
|
||||
: this.urlHelper.getDirectThumbnailUrl(entry.bookId),
|
||||
entries: [],
|
||||
});
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
alt="Book cover"
|
||||
class="book-cover"
|
||||
/>
|
||||
} @else {
|
||||
<app-cover-placeholder class="book-cover" [title]="bookInfo().title" [author]="bookInfo().authors" size="sm" />
|
||||
}
|
||||
<div class="book-meta">
|
||||
<h2 class="book-title">{{ bookInfo().title }}</h2>
|
||||
|
||||
+2
-1
@@ -5,13 +5,14 @@ import {TranslocoPipe} from '@jsverse/transloco';
|
||||
import {CbxSidebarService, CbxSidebarTab} from './cbx-sidebar.service';
|
||||
import {BookNoteV2} from '../../../../../shared/service/book-note-v2.service';
|
||||
import {ReaderIconComponent} from '../../../ebook-reader';
|
||||
import {CoverPlaceholderComponent} from '../../../../../shared/components/cover-generator/cover-generator.component';
|
||||
|
||||
@Component({
|
||||
selector: 'app-cbx-sidebar',
|
||||
standalone: true,
|
||||
templateUrl: './cbx-sidebar.component.html',
|
||||
styleUrls: ['./cbx-sidebar.component.scss'],
|
||||
imports: [CommonModule, FormsModule, TranslocoPipe, ReaderIconComponent, DatePipe]
|
||||
imports: [CommonModule, FormsModule, TranslocoPipe, ReaderIconComponent, DatePipe, CoverPlaceholderComponent]
|
||||
})
|
||||
export class CbxSidebarComponent {
|
||||
private readonly sidebarService = inject(CbxSidebarService);
|
||||
|
||||
+1
-3
@@ -12,9 +12,7 @@
|
||||
@if (bookCoverUrl) {
|
||||
<img [src]="bookCoverUrl" [alt]="metadata?.title || t('unknown')" class="book-cover">
|
||||
} @else {
|
||||
<div class="cover-placeholder">
|
||||
<span class="placeholder-icon">📚</span>
|
||||
</div>
|
||||
<app-cover-placeholder class="cover-placeholder" [title]="metadata?.title ?? ''" [author]="(metadata?.authors ?? []).join(', ')" />
|
||||
}
|
||||
</div>
|
||||
|
||||
|
||||
@@ -179,14 +179,6 @@ $transition-normal: 200ms ease;
|
||||
max-height: 240px;
|
||||
}
|
||||
|
||||
.placeholder-icon {
|
||||
font-size: 56px;
|
||||
opacity: 0.3;
|
||||
|
||||
@media (width <= 768px) {
|
||||
font-size: 44px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.metadata-section {
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import {Component, EventEmitter, inject, Input, Output} from '@angular/core';
|
||||
import {CommonModule} from '@angular/common';
|
||||
import {TranslocoDirective} from '@jsverse/transloco';
|
||||
import {TranslocoService} from '@jsverse/transloco';
|
||||
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
||||
import {Book} from '../../../book/model/book.model';
|
||||
import {UrlHelperService} from '../../../../shared/service/url-helper.service';
|
||||
import {CoverPlaceholderComponent} from '../../../../shared/components/cover-generator/cover-generator.component';
|
||||
|
||||
@Component({
|
||||
selector: 'app-reader-book-metadata-dialog',
|
||||
standalone: true,
|
||||
imports: [CommonModule, TranslocoDirective],
|
||||
imports: [CommonModule, TranslocoDirective, CoverPlaceholderComponent],
|
||||
templateUrl: './metadata-dialog.component.html',
|
||||
styleUrls: ['./metadata-dialog.component.scss']
|
||||
})
|
||||
|
||||
@@ -14,6 +14,16 @@
|
||||
tabindex="0"
|
||||
(keydown.enter)="onCoverClick()"
|
||||
/>
|
||||
} @else {
|
||||
<app-cover-placeholder
|
||||
class="book-cover"
|
||||
[title]="bookInfo().title"
|
||||
[author]="bookInfo().authors"
|
||||
size="sm"
|
||||
role="button"
|
||||
tabindex="0"
|
||||
(click)="onCoverClick()"
|
||||
(keydown.enter)="onCoverClick()" />
|
||||
}
|
||||
<div class="book-meta">
|
||||
<h2 class="book-title">{{ bookInfo().title }}</h2>
|
||||
|
||||
@@ -5,13 +5,14 @@ import {TranslocoDirective} from '@jsverse/transloco';
|
||||
import {TocItem} from 'epubjs';
|
||||
import {ReaderSidebarService, SidebarTab} from './sidebar.service';
|
||||
import {ReaderIconComponent} from '../../shared/icon.component';
|
||||
import {CoverPlaceholderComponent} from '../../../../../shared/components/cover-generator/cover-generator.component';
|
||||
|
||||
@Component({
|
||||
selector: 'app-reader-sidebar',
|
||||
standalone: true,
|
||||
templateUrl: './sidebar.component.html',
|
||||
styleUrls: ['./sidebar.component.scss'],
|
||||
imports: [CommonModule, FormsModule, TranslocoDirective, ReaderIconComponent]
|
||||
imports: [CommonModule, FormsModule, TranslocoDirective, ReaderIconComponent, CoverPlaceholderComponent]
|
||||
})
|
||||
export class ReaderSidebarComponent {
|
||||
private readonly sidebarService = inject(ReaderSidebarService);
|
||||
|
||||
+16
-7
@@ -1,13 +1,22 @@
|
||||
<div class="series-card" role="button" tabindex="0" (click)="onCardClick($event)" (keydown.enter)="onCardClick($event)">
|
||||
<div class="stacked-covers" [ngClass]="'covers-' + series.coverBooks.length">
|
||||
@for (book of series.coverBooks; track book.id; let i = $index) {
|
||||
<img
|
||||
[src]="getCoverUrl(i)"
|
||||
class="cover-img"
|
||||
[ngClass]="'cover-' + i"
|
||||
[alt]="series.seriesName"
|
||||
loading="lazy"
|
||||
decoding="async"/>
|
||||
@if (getCoverUrl(i); as coverUrl) {
|
||||
<img
|
||||
[src]="coverUrl"
|
||||
class="cover-img"
|
||||
[ngClass]="'cover-' + i"
|
||||
[alt]="series.seriesName"
|
||||
loading="lazy"
|
||||
decoding="async"/>
|
||||
} @else {
|
||||
<app-cover-placeholder
|
||||
class="cover-img"
|
||||
[ngClass]="'cover-' + i"
|
||||
[title]="book.metadata?.title ?? ''"
|
||||
[author]="(book.metadata?.authors ?? []).join(', ')"
|
||||
size="sm" />
|
||||
}
|
||||
}
|
||||
</div>
|
||||
|
||||
|
||||
+1
-1
@@ -93,7 +93,7 @@ describe('SeriesCardComponent', () => {
|
||||
it('builds thumbnail URLs from ebook and audiobook covers', () => {
|
||||
expect(component.getCoverUrl(0)).toBe('thumb:1:2026-03-01');
|
||||
expect(component.getCoverUrl(1)).toBe('audio:2:2026-03-02');
|
||||
expect(component.getCoverUrl(99)).toBe('');
|
||||
expect(component.getCoverUrl(99)).toBeNull();
|
||||
});
|
||||
|
||||
it('emits a card click and stops propagation', () => {
|
||||
|
||||
+4
-3
@@ -7,6 +7,7 @@ import {TranslocoPipe} from '@jsverse/transloco';
|
||||
import {SeriesSummary} from '../../model/series.model';
|
||||
import {BookService} from '../../../book/service/book.service';
|
||||
import {UrlHelperService} from '../../../../shared/service/url-helper.service';
|
||||
import {CoverPlaceholderComponent} from '../../../../shared/components/cover-generator/cover-generator.component';
|
||||
|
||||
@Component({
|
||||
selector: 'app-series-card',
|
||||
@@ -14,7 +15,7 @@ import {UrlHelperService} from '../../../../shared/service/url-helper.service';
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
templateUrl: './series-card.component.html',
|
||||
styleUrls: ['./series-card.component.scss'],
|
||||
imports: [NgClass, ProgressBar, Button, Tooltip, TranslocoPipe]
|
||||
imports: [NgClass, ProgressBar, Button, Tooltip, TranslocoPipe, CoverPlaceholderComponent]
|
||||
})
|
||||
export class SeriesCardComponent {
|
||||
|
||||
@@ -34,9 +35,9 @@ export class SeriesCardComponent {
|
||||
return this.series.authors.slice(0, 2).join(', ') + ' +' + (this.series.authors.length - 2);
|
||||
}
|
||||
|
||||
getCoverUrl(index: number): string {
|
||||
getCoverUrl(index: number): string | null {
|
||||
const book = this.series.coverBooks[index];
|
||||
if (!book) return '';
|
||||
if (!book) return null;
|
||||
const isAudiobook = book.primaryFile?.bookType === 'AUDIOBOOK';
|
||||
return isAudiobook
|
||||
? this.urlHelper.getAudiobookThumbnailUrl(book.id, book.metadata?.audiobookCoverUpdatedOn)
|
||||
|
||||
+39
-48
@@ -1,76 +1,67 @@
|
||||
import {ComponentFixture, TestBed} from '@angular/core/testing';
|
||||
import {afterEach, beforeEach, describe, expect, it} from 'vitest';
|
||||
|
||||
import {CoverGeneratorComponent} from './cover-generator.component';
|
||||
import {CoverPlaceholderComponent, coverColorFor} from './cover-generator.component';
|
||||
|
||||
describe('CoverGeneratorComponent', () => {
|
||||
let fixture: ComponentFixture<CoverGeneratorComponent>;
|
||||
let component: CoverGeneratorComponent;
|
||||
describe('CoverPlaceholderComponent', () => {
|
||||
let fixture: ComponentFixture<CoverPlaceholderComponent>;
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [CoverGeneratorComponent],
|
||||
imports: [CoverPlaceholderComponent],
|
||||
}).compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(CoverGeneratorComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture = TestBed.createComponent(CoverPlaceholderComponent);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
TestBed.resetTestingModule();
|
||||
});
|
||||
|
||||
function decodeCover(dataUrl: string): string {
|
||||
const encoded = dataUrl.replace('data:image/svg+xml;base64,', '');
|
||||
return decodeURIComponent(
|
||||
Array.from(atob(encoded))
|
||||
.map(char => `%${char.charCodeAt(0).toString(16).padStart(2, '0')}`)
|
||||
.join('')
|
||||
);
|
||||
}
|
||||
it('renders the title and author text', () => {
|
||||
fixture.componentRef.setInput('title', 'Dune');
|
||||
fixture.componentRef.setInput('author', 'Frank Herbert');
|
||||
fixture.detectChanges();
|
||||
|
||||
it('generates a base64-encoded ebook cover with escaped title and author text', () => {
|
||||
component.title = 'Dune & <Messiah>';
|
||||
component.author = 'Frank "Herbert"';
|
||||
|
||||
const svg = decodeCover(component.generateCover());
|
||||
|
||||
expect(svg).toContain('<svg');
|
||||
expect(svg).toContain('Dune &');
|
||||
expect(svg).toContain('<Messiah>');
|
||||
expect(svg).toContain('"Herbert"');
|
||||
expect(svg).toContain('width="250" height="350"');
|
||||
const el: HTMLElement = fixture.nativeElement;
|
||||
expect(el.textContent).toContain('Dune');
|
||||
expect(el.textContent).toContain('Frank Herbert');
|
||||
});
|
||||
|
||||
it('generates a square audiobook cover when requested', () => {
|
||||
component.title = 'Project Hail Mary';
|
||||
component.author = 'Andy Weir';
|
||||
component.isSquare = true;
|
||||
it('applies the computed background color', () => {
|
||||
fixture.componentRef.setInput('title', 'Dune');
|
||||
fixture.componentRef.setInput('author', 'Frank Herbert');
|
||||
fixture.detectChanges();
|
||||
|
||||
const svg = decodeCover(component.generateCover());
|
||||
|
||||
expect(svg).toContain('width="250" height="250"');
|
||||
expect(svg).toContain('L-6,8 L8,0 Z');
|
||||
const container = fixture.nativeElement.querySelector('.placeholder');
|
||||
expect(container.style.background).toBeTruthy();
|
||||
});
|
||||
|
||||
it('wraps and truncates long titles into multiple lines', () => {
|
||||
component.title = 'A Very Long Book Title That Keeps Going Beyond The Expected Width Of The Cover';
|
||||
component.author = 'Someone';
|
||||
it('applies the correct size class', () => {
|
||||
fixture.componentRef.setInput('title', 'Test');
|
||||
fixture.componentRef.setInput('size', 'lg');
|
||||
fixture.detectChanges();
|
||||
|
||||
const svg = decodeCover(component.generateCover());
|
||||
const container = fixture.nativeElement.querySelector('.placeholder');
|
||||
expect(container.classList.contains('size-lg')).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
expect((svg.match(/<text x="125"/g) ?? []).length).toBeGreaterThan(2);
|
||||
expect(svg).toContain('Going Beyond');
|
||||
expect(svg).not.toContain('Expected Width');
|
||||
describe('coverColorFor', () => {
|
||||
it('returns a deterministic color for the same inputs', () => {
|
||||
const first = coverColorFor('Dune', 'Frank Herbert');
|
||||
const second = coverColorFor('Dune', 'Frank Herbert');
|
||||
expect(first).toBe(second);
|
||||
});
|
||||
|
||||
it('produces deterministic palette selection for the same inputs', () => {
|
||||
component.title = 'Dune';
|
||||
component.author = 'Frank Herbert';
|
||||
it('returns different colors for different inputs', () => {
|
||||
const a = coverColorFor('Dune', 'Frank Herbert');
|
||||
const b = coverColorFor('Project Hail Mary', 'Andy Weir');
|
||||
expect(a).not.toBe(b);
|
||||
});
|
||||
|
||||
const first = component.generateCover();
|
||||
const second = component.generateCover();
|
||||
|
||||
expect(first).toBe(second);
|
||||
it('returns a valid hex color', () => {
|
||||
const color = coverColorFor('Test', 'Author');
|
||||
expect(color).toMatch(/^#[0-9A-Fa-f]{6}$/);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,235 +1,105 @@
|
||||
import {ChangeDetectionStrategy, Component, Input} from '@angular/core';
|
||||
import {ChangeDetectionStrategy, Component, computed, input} from '@angular/core';
|
||||
|
||||
const COVER_COLORS = [
|
||||
'#1a1a2e', '#2d3436', '#0c3547', '#1e3d59', '#2c2c54', '#1b262c',
|
||||
'#2B2D42', '#3D405B', '#463F3A', '#1B2838', '#2E4057', '#4A3728',
|
||||
];
|
||||
|
||||
function hashString(str: string): number {
|
||||
let hash = 0;
|
||||
for (let i = 0; i < str.length; i++) {
|
||||
hash = ((hash << 5) - hash) + str.charCodeAt(i);
|
||||
hash = hash & hash;
|
||||
}
|
||||
return Math.abs(hash);
|
||||
}
|
||||
|
||||
export function coverColorFor(title: string, author: string): string {
|
||||
return COVER_COLORS[hashString(title + author) % COVER_COLORS.length];
|
||||
}
|
||||
|
||||
export type CoverPlaceholderSize = 'sm' | 'md' | 'lg';
|
||||
|
||||
@Component({
|
||||
selector: 'app-cover-placeholder',
|
||||
standalone: true,
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
template: ''
|
||||
template: `
|
||||
<div
|
||||
class="placeholder"
|
||||
[class.size-sm]="size() === 'sm'"
|
||||
[class.size-md]="size() === 'md'"
|
||||
[class.size-lg]="size() === 'lg'"
|
||||
[style.background]="color()"
|
||||
>
|
||||
<div class="placeholder-title">{{ title() }}</div>
|
||||
<div class="placeholder-author">{{ author() }}</div>
|
||||
</div>
|
||||
`,
|
||||
styles: [`
|
||||
:host {
|
||||
display: block;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.placeholder {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.placeholder.size-sm { padding: 0.5rem; }
|
||||
.placeholder.size-md { padding: 1rem; }
|
||||
.placeholder.size-lg { padding: 1.5rem; }
|
||||
|
||||
.placeholder-title {
|
||||
color: rgba(255, 255, 255, 0.9);
|
||||
font-weight: 600;
|
||||
line-height: 1.375;
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 3;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.size-sm .placeholder-title {
|
||||
font-size: 11px;
|
||||
margin-bottom: 2px;
|
||||
}
|
||||
|
||||
.size-md .placeholder-title {
|
||||
font-size: 13px;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.size-lg .placeholder-title {
|
||||
font-size: 15px;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.placeholder-author {
|
||||
color: rgba(255, 255, 255, 0.5);
|
||||
letter-spacing: 0.025em;
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 1;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.size-sm .placeholder-author { font-size: 9px; }
|
||||
.size-md .placeholder-author { font-size: 11px; }
|
||||
.size-lg .placeholder-author { font-size: 12px; }
|
||||
`]
|
||||
})
|
||||
export class CoverGeneratorComponent {
|
||||
@Input() title: string = '';
|
||||
@Input() author: string = '';
|
||||
@Input() isSquare: boolean = false;
|
||||
export class CoverPlaceholderComponent {
|
||||
title = input('');
|
||||
author = input('');
|
||||
size = input<CoverPlaceholderSize>('md');
|
||||
|
||||
private wrapText(text: string, maxLineLength: number): string[] {
|
||||
const words = text.split(' ');
|
||||
const lines: string[] = [];
|
||||
let currentLine = '';
|
||||
|
||||
words.forEach(word => {
|
||||
if (word.length > maxLineLength) {
|
||||
if (currentLine.length > 0) {
|
||||
lines.push(currentLine);
|
||||
currentLine = '';
|
||||
}
|
||||
lines.push(word);
|
||||
} else if (currentLine.length + word.length + 1 > maxLineLength) {
|
||||
lines.push(currentLine);
|
||||
currentLine = word;
|
||||
} else {
|
||||
currentLine += (currentLine.length > 0 ? ' ' : '') + word;
|
||||
}
|
||||
});
|
||||
|
||||
if (currentLine.length > 0) {
|
||||
lines.push(currentLine);
|
||||
}
|
||||
|
||||
return lines;
|
||||
}
|
||||
|
||||
private truncateText(text: string, maxLength: number): string {
|
||||
if (text.length <= maxLength) return text;
|
||||
return text.substring(0, maxLength - 3) + '...';
|
||||
}
|
||||
|
||||
private escapeXml(text: string): string {
|
||||
return text
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/'/g, ''');
|
||||
}
|
||||
|
||||
private hashString(str: string): number {
|
||||
let hash = 0;
|
||||
for (let i = 0; i < str.length; i++) {
|
||||
const char = str.charCodeAt(i);
|
||||
hash = ((hash << 5) - hash) + char;
|
||||
hash = hash & hash;
|
||||
}
|
||||
return Math.abs(hash);
|
||||
}
|
||||
|
||||
generateCover(): string {
|
||||
const width = 250;
|
||||
const height = this.isSquare ? 250 : 350;
|
||||
const hash = this.hashString(this.title + this.author);
|
||||
|
||||
if (this.isSquare) {
|
||||
return this.generateAudiobookCover(width, height, hash);
|
||||
} else {
|
||||
return this.generateEbookCover(width, height, hash);
|
||||
}
|
||||
}
|
||||
|
||||
private generateEbookCover(width: number, height: number, hash: number): string {
|
||||
const palettes = [
|
||||
{bg1: '#1a1a2e', bg2: '#16213e', accent: '#e94560', text: '#eaeaea', textSecondary: '#b8b8b8'},
|
||||
{bg1: '#2d3436', bg2: '#636e72', accent: '#74b9ff', text: '#ffffff', textSecondary: '#dfe6e9'},
|
||||
{bg1: '#0c3547', bg2: '#1a5276', accent: '#f39c12', text: '#ecf0f1', textSecondary: '#bdc3c7'},
|
||||
{bg1: '#1e3d59', bg2: '#17263a', accent: '#ffc13b', text: '#f5f0e1', textSecondary: '#c7b198'},
|
||||
{bg1: '#2c2c54', bg2: '#474787', accent: '#ff793f', text: '#f8f8f8', textSecondary: '#d1ccc0'},
|
||||
{bg1: '#1b262c', bg2: '#0f4c75', accent: '#3282b8', text: '#bbe1fa', textSecondary: '#8fbdd3'},
|
||||
];
|
||||
|
||||
const palette = palettes[hash % palettes.length];
|
||||
const {titleLines, authorLines, titleFontSize, authorFontSize} = this.processText(false);
|
||||
|
||||
const titleLineHeight = titleFontSize * 1.3;
|
||||
const titleStartY = 80;
|
||||
|
||||
const titleElements = titleLines.map((line, index) => {
|
||||
const y = titleStartY + (index * titleLineHeight);
|
||||
return `<text x="125" y="${y}" text-anchor="middle" font-family="Georgia, serif" font-weight="600" font-size="${titleFontSize}" fill="${palette.text}">${this.escapeXml(line)}</text>`;
|
||||
}).join('\n');
|
||||
|
||||
const authorLineHeight = authorFontSize * 1.3;
|
||||
const authorStartY = height - 50 - ((authorLines.length - 1) * authorLineHeight);
|
||||
|
||||
const authorElements = authorLines.map((line, index) => {
|
||||
const y = authorStartY + (index * authorLineHeight);
|
||||
return `<text x="125" y="${y}" text-anchor="middle" font-family="Helvetica, Arial, sans-serif" font-size="${authorFontSize}" fill="${palette.textSecondary}">${this.escapeXml(line)}</text>`;
|
||||
}).join('\n');
|
||||
|
||||
const decorY = titleStartY + (titleLines.length * titleLineHeight) + 20;
|
||||
|
||||
const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}" viewBox="0 0 ${width} ${height}">
|
||||
<defs>
|
||||
<linearGradient id="bgGrad" x1="0%" y1="0%" x2="100%" y2="100%">
|
||||
<stop offset="0%" style="stop-color:${palette.bg1}"/>
|
||||
<stop offset="100%" style="stop-color:${palette.bg2}"/>
|
||||
</linearGradient>
|
||||
<linearGradient id="spineGrad" x1="0%" y1="0%" x2="100%" y2="0%">
|
||||
<stop offset="0%" style="stop-color:rgba(0,0,0,0.4)"/>
|
||||
<stop offset="100%" style="stop-color:rgba(0,0,0,0)"/>
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<rect width="100%" height="100%" fill="url(#bgGrad)"/>
|
||||
<rect x="0" y="0" width="12" height="100%" fill="url(#spineGrad)"/>
|
||||
<rect x="20" y="20" width="${width - 40}" height="${height - 40}" fill="none" stroke="${palette.accent}" stroke-width="1" opacity="0.4" rx="2"/>
|
||||
<rect x="25" y="25" width="${width - 50}" height="${height - 50}" fill="none" stroke="${palette.accent}" stroke-width="0.5" opacity="0.2" rx="1"/>
|
||||
${titleElements}
|
||||
<line x1="80" y1="${decorY}" x2="170" y2="${decorY}" stroke="${palette.accent}" stroke-width="2" stroke-linecap="round"/>
|
||||
<circle cx="125" cy="${decorY}" r="3" fill="${palette.accent}"/>
|
||||
${authorElements}
|
||||
<rect x="0" y="0" width="100%" height="100%" fill="none" stroke="rgba(255,255,255,0.1)" stroke-width="1"/>
|
||||
</svg>`;
|
||||
|
||||
return this.svgToDataUrl(svg);
|
||||
}
|
||||
|
||||
private generateAudiobookCover(width: number, height: number, hash: number): string {
|
||||
const palettes = [
|
||||
{bg1: '#667eea', bg2: '#764ba2', accent: '#ffffff', text: '#ffffff', textSecondary: '#e8e8e8'},
|
||||
{bg1: '#f093fb', bg2: '#f5576c', accent: '#ffffff', text: '#ffffff', textSecondary: '#ffeaea'},
|
||||
{bg1: '#4facfe', bg2: '#00f2fe', accent: '#ffffff', text: '#1a1a2e', textSecondary: '#2d3436'},
|
||||
{bg1: '#43e97b', bg2: '#38f9d7', accent: '#ffffff', text: '#1a1a2e', textSecondary: '#2d3436'},
|
||||
{bg1: '#fa709a', bg2: '#fee140', accent: '#ffffff', text: '#1a1a2e', textSecondary: '#2d3436'},
|
||||
{bg1: '#a18cd1', bg2: '#fbc2eb', accent: '#ffffff', text: '#2d3436', textSecondary: '#4a4a4a'},
|
||||
];
|
||||
|
||||
const palette = palettes[hash % palettes.length];
|
||||
const {titleLines, authorLines, titleFontSize, authorFontSize} = this.processText(true);
|
||||
|
||||
const titleLineHeight = titleFontSize * 1.3;
|
||||
const titleStartY = 70;
|
||||
|
||||
const titleElements = titleLines.map((line, index) => {
|
||||
const y = titleStartY + (index * titleLineHeight);
|
||||
return `<text x="125" y="${y}" text-anchor="middle" font-family="Helvetica, Arial, sans-serif" font-weight="700" font-size="${titleFontSize}" fill="${palette.text}">${this.escapeXml(line)}</text>`;
|
||||
}).join('\n');
|
||||
|
||||
const authorLineHeight = authorFontSize * 1.3;
|
||||
const authorStartY = height - 40 - ((authorLines.length - 1) * authorLineHeight);
|
||||
|
||||
const authorElements = authorLines.map((line, index) => {
|
||||
const y = authorStartY + (index * authorLineHeight);
|
||||
return `<text x="125" y="${y}" text-anchor="middle" font-family="Helvetica, Arial, sans-serif" font-size="${authorFontSize}" fill="${palette.textSecondary}">${this.escapeXml(line)}</text>`;
|
||||
}).join('\n');
|
||||
|
||||
const iconY = titleStartY + (titleLines.length * titleLineHeight) + 25;
|
||||
|
||||
const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}" viewBox="0 0 ${width} ${height}">
|
||||
<defs>
|
||||
<linearGradient id="bgGrad" x1="0%" y1="0%" x2="100%" y2="100%">
|
||||
<stop offset="0%" style="stop-color:${palette.bg1}"/>
|
||||
<stop offset="100%" style="stop-color:${palette.bg2}"/>
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<rect width="100%" height="100%" fill="url(#bgGrad)"/>
|
||||
<circle cx="125" cy="125" r="100" fill="none" stroke="${palette.accent}" stroke-width="1" opacity="0.15"/>
|
||||
<circle cx="125" cy="125" r="80" fill="none" stroke="${palette.accent}" stroke-width="1" opacity="0.1"/>
|
||||
${titleElements}
|
||||
<g transform="translate(125, ${iconY})" opacity="0.9">
|
||||
<circle cx="0" cy="0" r="18" fill="none" stroke="${palette.accent}" stroke-width="2" opacity="0.6"/>
|
||||
<path d="M-6,-8 L-6,8 L8,0 Z" fill="${palette.accent}" opacity="0.8"/>
|
||||
</g>
|
||||
${authorElements}
|
||||
</svg>`;
|
||||
|
||||
return this.svgToDataUrl(svg);
|
||||
}
|
||||
|
||||
private processText(isSquare: boolean): {
|
||||
titleLines: string[];
|
||||
authorLines: string[];
|
||||
titleFontSize: number;
|
||||
authorFontSize: number;
|
||||
} {
|
||||
const maxTitleLength = 60;
|
||||
const maxAuthorLength = 40;
|
||||
const truncatedTitle = this.truncateText(this.title, maxTitleLength);
|
||||
const truncatedAuthor = this.truncateText(this.author, maxAuthorLength);
|
||||
|
||||
const maxLineLength = 14;
|
||||
const maxTitleLines = isSquare ? 3 : 4;
|
||||
const maxAuthorLines = isSquare ? 2 : 3;
|
||||
|
||||
let titleLines = this.wrapText(truncatedTitle, maxLineLength);
|
||||
let authorLines = this.wrapText(truncatedAuthor, maxLineLength);
|
||||
|
||||
if (titleLines.length > maxTitleLines) {
|
||||
titleLines = titleLines.slice(0, maxTitleLines);
|
||||
titleLines[maxTitleLines - 1] = this.truncateText(titleLines[maxTitleLines - 1], maxLineLength);
|
||||
}
|
||||
|
||||
if (authorLines.length > maxAuthorLines) {
|
||||
authorLines = authorLines.slice(0, maxAuthorLines);
|
||||
authorLines[maxAuthorLines - 1] = this.truncateText(authorLines[maxAuthorLines - 1], maxLineLength);
|
||||
}
|
||||
|
||||
const titleFontSize = this.calculateTitleFontSize(titleLines.length);
|
||||
const authorFontSize = this.calculateAuthorFontSize(authorLines.length);
|
||||
|
||||
return {titleLines, authorLines, titleFontSize, authorFontSize};
|
||||
}
|
||||
|
||||
private calculateTitleFontSize(lineCount: number): number {
|
||||
if (lineCount <= 2) return 28;
|
||||
if (lineCount === 3) return 24;
|
||||
return 20;
|
||||
}
|
||||
|
||||
private calculateAuthorFontSize(lineCount: number): number {
|
||||
if (lineCount <= 2) return 18;
|
||||
return 16;
|
||||
}
|
||||
|
||||
private svgToDataUrl(svg: string): string {
|
||||
const base64 = btoa(encodeURIComponent(svg).replace(/%([0-9A-F]{2})/g, (_, p1) => {
|
||||
return String.fromCharCode(parseInt(p1, 16));
|
||||
}));
|
||||
return `data:image/svg+xml;base64,${base64}`;
|
||||
}
|
||||
protected color = computed(() => coverColorFor(this.title(), this.author()));
|
||||
}
|
||||
|
||||
@@ -4,8 +4,6 @@ import {afterEach, beforeEach, describe, expect, it, vi} from 'vitest';
|
||||
|
||||
import {API_CONFIG} from '../../core/config/api-config';
|
||||
import {Book, BookType} from '../../features/book/model/book.model';
|
||||
import {BookService} from '../../features/book/service/book.service';
|
||||
import {CoverGeneratorComponent} from '../components/cover-generator/cover-generator.component';
|
||||
import {AuthService} from './auth.service';
|
||||
import {UrlHelperService} from './url-helper.service';
|
||||
|
||||
@@ -14,24 +12,12 @@ describe('UrlHelperService', () => {
|
||||
getInternalAccessToken: vi.fn(),
|
||||
};
|
||||
|
||||
const bookServiceStub = {
|
||||
findBookById: vi.fn(),
|
||||
};
|
||||
|
||||
const routerStub = {
|
||||
createUrlTree: vi.fn((commands: unknown[], extras?: unknown) => ({commands, extras})),
|
||||
};
|
||||
|
||||
let service: UrlHelperService;
|
||||
|
||||
const bookWithMetadata = {
|
||||
id: 42,
|
||||
metadata: {
|
||||
title: 'The Testing Atlas',
|
||||
authors: ['Ada Lovelace', 'Grace Hopper'],
|
||||
},
|
||||
} as Book;
|
||||
|
||||
const supportedReadingRoutes: {bookType: BookType; readerSegment: string}[] = [
|
||||
{bookType: 'PDF', readerSegment: 'pdf-reader'},
|
||||
{bookType: 'EPUB', readerSegment: 'ebook-reader'},
|
||||
@@ -44,15 +30,12 @@ describe('UrlHelperService', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
authServiceStub.getInternalAccessToken.mockReturnValue('token-123');
|
||||
bookServiceStub.findBookById.mockReset();
|
||||
bookServiceStub.findBookById.mockReturnValue(undefined);
|
||||
routerStub.createUrlTree.mockClear();
|
||||
|
||||
TestBed.configureTestingModule({
|
||||
providers: [
|
||||
UrlHelperService,
|
||||
{provide: AuthService, useValue: authServiceStub},
|
||||
{provide: BookService, useValue: bookServiceStub},
|
||||
{provide: Router, useValue: routerStub},
|
||||
],
|
||||
});
|
||||
@@ -64,17 +47,8 @@ describe('UrlHelperService', () => {
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
it('generates a portrait cover when cached metadata exists and no updated marker is provided', () => {
|
||||
bookServiceStub.findBookById.mockReturnValue(bookWithMetadata);
|
||||
|
||||
const generateCoverSpy = vi.spyOn(CoverGeneratorComponent.prototype, 'generateCover').mockImplementation(function (this: CoverGeneratorComponent) {
|
||||
return `${this.title}|${this.author}|${this.isSquare ? 'square' : 'portrait'}`;
|
||||
});
|
||||
|
||||
const url = service.getThumbnailUrl(42);
|
||||
|
||||
expect(generateCoverSpy).toHaveBeenCalledTimes(1);
|
||||
expect(url).toBe('The Testing Atlas|Ada Lovelace, Grace Hopper|portrait');
|
||||
it('returns null for thumbnail when no coverUpdatedOn is provided', () => {
|
||||
expect(service.getThumbnailUrl(42)).toBeNull();
|
||||
});
|
||||
|
||||
it('appends the token to thumbnail urls that already have a cache key', () => {
|
||||
@@ -83,6 +57,22 @@ describe('UrlHelperService', () => {
|
||||
expect(url).toBe(`${API_CONFIG.BASE_URL}/api/v1/media/book/42/thumbnail?updated-2024&token=token-123`);
|
||||
});
|
||||
|
||||
it('returns null for cover url when no coverUpdatedOn is provided', () => {
|
||||
expect(service.getCoverUrl(42)).toBeNull();
|
||||
});
|
||||
|
||||
it('returns null for audiobook cover when no updated marker is provided', () => {
|
||||
expect(service.getAudiobookCoverUrl(42)).toBeNull();
|
||||
});
|
||||
|
||||
it('returns null for audiobook thumbnail when no updated marker is provided', () => {
|
||||
expect(service.getAudiobookThumbnailUrl(42)).toBeNull();
|
||||
});
|
||||
|
||||
it('uses the audiobook media url when an updated marker is present', () => {
|
||||
expect(service.getAudiobookThumbnailUrl(42, 'updated-2024')).toBe(`${API_CONFIG.BASE_URL}/api/v1/media/book/42/audiobook-thumbnail?updated-2024&token=token-123`);
|
||||
});
|
||||
|
||||
it('returns direct thumbnail and backup urls without a token when auth is unavailable', () => {
|
||||
authServiceStub.getInternalAccessToken.mockReturnValue(null);
|
||||
|
||||
@@ -90,23 +80,6 @@ describe('UrlHelperService', () => {
|
||||
expect(service.getBackupCoverUrl(42)).toBe(`${API_CONFIG.BASE_URL}/api/v1/media/book/42/backup-cover`);
|
||||
});
|
||||
|
||||
it('generates a square audiobook cover when cached metadata exists', () => {
|
||||
bookServiceStub.findBookById.mockReturnValue(bookWithMetadata);
|
||||
|
||||
const generateCoverSpy = vi.spyOn(CoverGeneratorComponent.prototype, 'generateCover').mockImplementation(function (this: CoverGeneratorComponent) {
|
||||
return `${this.title}|${this.author}|${this.isSquare ? 'square' : 'portrait'}`;
|
||||
});
|
||||
|
||||
const url = service.getAudiobookCoverUrl(42);
|
||||
|
||||
expect(generateCoverSpy).toHaveBeenCalledTimes(1);
|
||||
expect(url).toBe('The Testing Atlas|Ada Lovelace, Grace Hopper|square');
|
||||
});
|
||||
|
||||
it('uses the audiobook media url when an updated marker is present', () => {
|
||||
expect(service.getAudiobookThumbnailUrl(42, 'updated-2024')).toBe(`${API_CONFIG.BASE_URL}/api/v1/media/book/42/audiobook-thumbnail?updated-2024&token=token-123`);
|
||||
});
|
||||
|
||||
it.each(supportedReadingRoutes)('routes %s books to the correct reader path', ({bookType, readerSegment}: {bookType: BookType; readerSegment: string}) => {
|
||||
const book = {
|
||||
id: 77,
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import {inject, Injectable} from '@angular/core';
|
||||
import {API_CONFIG} from '../../core/config/api-config';
|
||||
import {AuthService} from './auth.service';
|
||||
import {BookService} from '../../features/book/service/book.service';
|
||||
import {CoverGeneratorComponent} from '../components/cover-generator/cover-generator.component';
|
||||
import {Router} from '@angular/router';
|
||||
import {Book,BookType} from '../../features/book/model/book.model';
|
||||
import {Book, BookType} from '../../features/book/model/book.model';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -13,7 +11,6 @@ export class UrlHelperService {
|
||||
private readonly baseUrl = API_CONFIG.BASE_URL;
|
||||
private readonly mediaBaseUrl = `${this.baseUrl}/api/v1/media`;
|
||||
private authService = inject(AuthService);
|
||||
private bookService = inject(BookService);
|
||||
private router = inject(Router);
|
||||
|
||||
private getToken(): string | null {
|
||||
@@ -25,21 +22,9 @@ export class UrlHelperService {
|
||||
return token ? `${url}${url.includes('?') ? '&' : '?'}token=${token}` : url;
|
||||
}
|
||||
|
||||
getThumbnailUrl(bookId: number, coverUpdatedOn?: string): string {
|
||||
if (!coverUpdatedOn) {
|
||||
const book = this.bookService.findBookById(bookId);
|
||||
if (book && book.metadata) {
|
||||
const coverGenerator = new CoverGeneratorComponent();
|
||||
coverGenerator.title = book.metadata.title || '';
|
||||
coverGenerator.author = (book.metadata.authors || []).join(', ');
|
||||
return coverGenerator.generateCover();
|
||||
}
|
||||
}
|
||||
let url = `${this.mediaBaseUrl}/book/${bookId}/thumbnail`;
|
||||
if (coverUpdatedOn) {
|
||||
url += `?${coverUpdatedOn}`;
|
||||
}
|
||||
return this.appendToken(url);
|
||||
getThumbnailUrl(bookId: number, coverUpdatedOn?: string): string | null {
|
||||
if (!coverUpdatedOn) return null;
|
||||
return this.appendToken(`${this.mediaBaseUrl}/book/${bookId}/thumbnail?${coverUpdatedOn}`);
|
||||
}
|
||||
|
||||
getDirectThumbnailUrl(bookId: number, coverUpdatedOn?: string): string {
|
||||
@@ -50,21 +35,9 @@ export class UrlHelperService {
|
||||
return this.appendToken(url);
|
||||
}
|
||||
|
||||
getCoverUrl(bookId: number, coverUpdatedOn?: string): string {
|
||||
if (!coverUpdatedOn) {
|
||||
const book = this.bookService.findBookById(bookId);
|
||||
if (book && book.metadata) {
|
||||
const coverGenerator = new CoverGeneratorComponent();
|
||||
coverGenerator.title = book.metadata.title || '';
|
||||
coverGenerator.author = (book.metadata.authors || []).join(', ');
|
||||
return coverGenerator.generateCover();
|
||||
}
|
||||
}
|
||||
let url = `${this.mediaBaseUrl}/book/${bookId}/cover`;
|
||||
if (coverUpdatedOn) {
|
||||
url += `?${coverUpdatedOn}`;
|
||||
}
|
||||
return this.appendToken(url);
|
||||
getCoverUrl(bookId: number, coverUpdatedOn?: string): string | null {
|
||||
if (!coverUpdatedOn) return null;
|
||||
return this.appendToken(`${this.mediaBaseUrl}/book/${bookId}/cover?${coverUpdatedOn}`);
|
||||
}
|
||||
|
||||
getBackupCoverUrl(bookId: number): string {
|
||||
@@ -72,35 +45,17 @@ export class UrlHelperService {
|
||||
return this.appendToken(url);
|
||||
}
|
||||
|
||||
getAudiobookCoverUrl(bookId: number, audiobookCoverUpdatedOn?: string): string {
|
||||
if (!audiobookCoverUpdatedOn) {
|
||||
const book = this.bookService.findBookById(bookId);
|
||||
if (book && book.metadata) {
|
||||
const coverGenerator = new CoverGeneratorComponent();
|
||||
coverGenerator.title = book.metadata.title || '';
|
||||
coverGenerator.author = (book.metadata.authors || []).join(', ');
|
||||
coverGenerator.isSquare = true;
|
||||
return coverGenerator.generateCover();
|
||||
}
|
||||
}
|
||||
let url = `${this.mediaBaseUrl}/book/${bookId}/audiobook-cover`;
|
||||
if (audiobookCoverUpdatedOn) {
|
||||
url += `?${audiobookCoverUpdatedOn}`;
|
||||
}
|
||||
return this.appendToken(url);
|
||||
getAudiobookCoverUrl(bookId: number, audiobookCoverUpdatedOn?: string): string | null {
|
||||
if (!audiobookCoverUpdatedOn) return null;
|
||||
return this.appendToken(`${this.mediaBaseUrl}/book/${bookId}/audiobook-cover?${audiobookCoverUpdatedOn}`);
|
||||
}
|
||||
|
||||
getAudiobookThumbnailUrl(bookId: number, audiobookCoverUpdatedOn?: string): string {
|
||||
if (!audiobookCoverUpdatedOn) {
|
||||
const book = this.bookService.findBookById(bookId);
|
||||
if (book && book.metadata) {
|
||||
const coverGenerator = new CoverGeneratorComponent();
|
||||
coverGenerator.title = book.metadata.title || '';
|
||||
coverGenerator.author = (book.metadata.authors || []).join(', ');
|
||||
coverGenerator.isSquare = true;
|
||||
return coverGenerator.generateCover();
|
||||
}
|
||||
}
|
||||
getAudiobookThumbnailUrl(bookId: number, audiobookCoverUpdatedOn?: string): string | null {
|
||||
if (!audiobookCoverUpdatedOn) return null;
|
||||
return this.appendToken(`${this.mediaBaseUrl}/book/${bookId}/audiobook-thumbnail?${audiobookCoverUpdatedOn}`);
|
||||
}
|
||||
|
||||
getDirectAudiobookThumbnailUrl(bookId: number, audiobookCoverUpdatedOn?: string): string {
|
||||
let url = `${this.mediaBaseUrl}/book/${bookId}/audiobook-thumbnail`;
|
||||
if (audiobookCoverUpdatedOn) {
|
||||
url += `?${audiobookCoverUpdatedOn}`;
|
||||
|
||||
Reference in New Issue
Block a user