Feature/999 add high resolution cover support upload storage and search (#1006)
* Add high-resolution cover support: upload, storage, and search * Disable tests until fixed
This commit is contained in:
@@ -1,24 +1,43 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import {inject, Injectable} from '@angular/core';
|
||||
import {API_CONFIG} from '../../config/api-config';
|
||||
import {AuthService} from '../../core/service/auth.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class UrlHelperService {
|
||||
private readonly baseUrl = API_CONFIG.BASE_URL;
|
||||
private readonly mediaBaseUrl = `${this.baseUrl}/api/v1/media`;
|
||||
private authService = inject(AuthService);
|
||||
|
||||
private getToken(): string | null {
|
||||
return this.authService.getOidcAccessToken() || this.authService.getInternalAccessToken();
|
||||
}
|
||||
|
||||
private appendToken(url: string): string {
|
||||
const token = this.getToken();
|
||||
return token ? `${url}${url.includes('?') ? '&' : '?'}token=${token}` : url;
|
||||
}
|
||||
|
||||
getThumbnailUrl(bookId: number, coverUpdatedOn?: string): string {
|
||||
if (!coverUpdatedOn) return 'assets/images/missing-cover.jpg';
|
||||
const url = `${this.mediaBaseUrl}/book/${bookId}/thumbnail?${coverUpdatedOn}`;
|
||||
return this.appendToken(url);
|
||||
}
|
||||
|
||||
getCoverUrl(bookId: number, coverUpdatedOn?: string): string {
|
||||
if (!coverUpdatedOn) {
|
||||
return 'assets/images/missing-cover.jpg';
|
||||
}
|
||||
return `${this.baseUrl}/api/v1/books/${bookId}/cover?${coverUpdatedOn}`;
|
||||
if (!coverUpdatedOn) return 'assets/images/missing-cover.jpg';
|
||||
const url = `${this.mediaBaseUrl}/book/${bookId}/cover?${coverUpdatedOn}`;
|
||||
return this.appendToken(url);
|
||||
}
|
||||
|
||||
getBackupCoverUrl(bookId: number): string {
|
||||
return `${this.baseUrl}/api/v1/books/${bookId}/backup-cover`;
|
||||
const url = `${this.mediaBaseUrl}/book/${bookId}/backup-cover`;
|
||||
return this.appendToken(url);
|
||||
}
|
||||
|
||||
getBookdropCoverUrl(bookdropId: number): string {
|
||||
return `${this.baseUrl}/api/bookdrop/${bookdropId}/cover`;
|
||||
const url = `${this.mediaBaseUrl}/bookdrop/${bookdropId}/cover`;
|
||||
return this.appendToken(url);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user