fix(metadata): refactor book metadata fetching to use fetch API and signals for state management (#495)
* fix(metadata): refactor book metadata fetching to use fetch API and signals for state management * fix(metadata): update tests to mock fetch API for book metadata streaming * fix(metadata): improve metadata fetching with error handling and retry logic * fix(metadata): update author photo search to use SSE with auth headers and improve error handling * fix(metadata): require bookId for cover fetching and improve error handling * fix(metadata): simplify error handling in DuckDuckGo cover image fetching * fix(metadata): refactor SSE data handling for cover image and book metadata fetching
This commit is contained in:
@@ -116,10 +116,25 @@ export class AuthorService {
|
||||
return this.http.delete<void>(this.baseUrl, {body: authorIds});
|
||||
}
|
||||
|
||||
searchAuthorPhotos(authorId: number, query: string): Observable<AuthorPhotoResult[]> {
|
||||
return this.http.get<AuthorPhotoResult[]>(`${this.baseUrl}/${authorId}/search-photos`, {
|
||||
params: {q: query}
|
||||
});
|
||||
searchAuthorPhotos(authorId: number, query: string): Observable<AuthorPhotoResult> {
|
||||
const token = this.authService.getInternalAccessToken();
|
||||
const headers = new HttpHeaders()
|
||||
.set('Content-Type', 'application/json')
|
||||
.set('Authorization', `Bearer ${token}`);
|
||||
|
||||
return this.sseClient.stream(
|
||||
`${this.baseUrl}/${authorId}/search-photos`,
|
||||
{keepAlive: false, reconnectionDelay: 1000, responseType: 'event'},
|
||||
{headers, params: {q: query}, withCredentials: true},
|
||||
'GET'
|
||||
).pipe(
|
||||
map(event => {
|
||||
if (event.type === 'error') {
|
||||
throw new Error((event as ErrorEvent).message);
|
||||
}
|
||||
return JSON.parse((event as MessageEvent).data) as AuthorPhotoResult;
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
uploadAuthorPhotoFromUrl(authorId: number, imageUrl: string): Observable<void> {
|
||||
|
||||
Reference in New Issue
Block a user