Added configuration for search for frontend.
This commit is contained in:
@ -1,5 +1,21 @@
|
||||
{
|
||||
"features": {
|
||||
"registration": false
|
||||
}
|
||||
"features": {
|
||||
"registration": false
|
||||
},
|
||||
"providers": {
|
||||
"default": "google",
|
||||
"google": {
|
||||
"name": "Google",
|
||||
"filters": {},
|
||||
"languages": {
|
||||
"zh": "Chinese",
|
||||
"nl": "Dutch",
|
||||
"en": "English",
|
||||
"fr": "Francais",
|
||||
"ko": "Korean",
|
||||
"ja": "Japanese",
|
||||
"es": "Spanish"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -7,7 +7,7 @@ export class GoogleSearchContext extends SearchContext {
|
||||
|
||||
|
||||
generateQueryParams(): string {
|
||||
const filterParams = ['maxResults', 'startIndex', 'orderBy'];
|
||||
const filterParams = ['maxResults', 'startIndex', 'orderBy', 'langRestrict'];
|
||||
const searchParams = ['intitle', 'inauthor', 'inpublisher', 'subject', 'isbn'];
|
||||
|
||||
const queryParams = filterParams
|
||||
|
@ -1,14 +1,16 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { BadRequestException, HttpException, Injectable } from '@nestjs/common';
|
||||
import { BookSearchResultDto } from '../dto/book-search-result.dto';
|
||||
import { HttpService } from '@nestjs/axios';
|
||||
import { firstValueFrom, map, timeout } from 'rxjs';
|
||||
import { AxiosResponse } from 'axios';
|
||||
import { catchError, EMPTY, firstValueFrom, map, timeout } from 'rxjs';
|
||||
import { AxiosError, AxiosResponse } from 'axios';
|
||||
import { GoogleSearchContext } from '../contexts/google.search.context';
|
||||
import { PinoLogger } from 'nestjs-pino';
|
||||
|
||||
@Injectable()
|
||||
export class GoogleService {
|
||||
constructor(
|
||||
private readonly http: HttpService,
|
||||
private readonly logger: PinoLogger,
|
||||
) { }
|
||||
|
||||
async searchRaw(searchQuery: string): Promise<BookSearchResultDto[]> {
|
||||
@ -28,7 +30,7 @@ export class GoogleService {
|
||||
return null;
|
||||
}
|
||||
|
||||
const defaultQueryParams = 'langRestrict=en&printType=books&fields=items(kind,id,volumeInfo(title,description,authors,publisher,publishedDate,industryIdentifiers,language,categories,maturityRating,imageLinks,canonicalVolumeLink,seriesInfo))';
|
||||
const defaultQueryParams = 'printType=books&fields=items(kind,id,volumeInfo(title,description,authors,publisher,publishedDate,industryIdentifiers,language,categories,maturityRating,imageLinks,canonicalVolumeLink,seriesInfo))';
|
||||
const customQueryParams = context.generateQueryParams();
|
||||
|
||||
return await firstValueFrom(
|
||||
@ -36,6 +38,23 @@ export class GoogleService {
|
||||
.pipe(
|
||||
timeout({ first: 5000 }),
|
||||
map(value => this.transform(value)),
|
||||
catchError((err: any) => {
|
||||
if (err instanceof AxiosError) {
|
||||
if (err.status == 400) {
|
||||
throw new BadRequestException(err.response.data);
|
||||
} else if (err.status == 429) {
|
||||
throw new HttpException(err.response?.data, 429);
|
||||
}
|
||||
}
|
||||
|
||||
this.logger.error({
|
||||
class: GoogleService.name,
|
||||
method: this.search.name,
|
||||
msg: 'Unknown Google search error.',
|
||||
error: err,
|
||||
});
|
||||
return EMPTY;
|
||||
})
|
||||
)
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user