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:
brios
2026-04-22 17:27:15 -04:00
committed by Zach Yale
parent 27db18ae80
commit fcee609b15
19 changed files with 702 additions and 397 deletions
@@ -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> {