feat(google-books): add optional API key configuration (#2629)
This commit is contained in:
+1
@@ -27,6 +27,7 @@ public class MetadataProviderSettings {
|
||||
public static class Google {
|
||||
private boolean enabled;
|
||||
private String language;
|
||||
private String apiKey;
|
||||
}
|
||||
|
||||
@Data
|
||||
|
||||
@@ -4,6 +4,7 @@ import org.booklore.model.dto.Book;
|
||||
import org.booklore.model.dto.BookMetadata;
|
||||
import org.booklore.model.dto.request.FetchMetadataRequest;
|
||||
import org.booklore.model.dto.response.GoogleBooksApiResponse;
|
||||
import org.booklore.model.dto.settings.MetadataProviderSettings;
|
||||
import org.booklore.model.enums.MetadataProvider;
|
||||
import org.booklore.service.appsettings.AppSettingService;
|
||||
import org.booklore.util.BookUtils;
|
||||
@@ -579,17 +580,23 @@ public class GoogleParser implements BookParser {
|
||||
}
|
||||
|
||||
private String getApiUrl() {
|
||||
String language = appSettingService.getAppSettings().getMetadataProviderSettings().getGoogle().getLanguage();
|
||||
MetadataProviderSettings.Google googleSettings = appSettingService.getAppSettings()
|
||||
.getMetadataProviderSettings().getGoogle();
|
||||
|
||||
if (language == null || language.isEmpty()) {
|
||||
return GOOGLE_BOOKS_API_URL;
|
||||
String language = googleSettings.getLanguage();
|
||||
String apiKey = googleSettings.getApiKey();
|
||||
|
||||
UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(GOOGLE_BOOKS_API_URL);
|
||||
|
||||
if (language != null && !language.isEmpty()) {
|
||||
builder.queryParam("langRestrict", language);
|
||||
}
|
||||
|
||||
return UriComponentsBuilder.fromUriString(GOOGLE_BOOKS_API_URL)
|
||||
.queryParam("langRestrict", language)
|
||||
.build()
|
||||
.toUri()
|
||||
.toString();
|
||||
if (apiKey != null && !apiKey.isBlank()) {
|
||||
builder.queryParam("key", apiKey);
|
||||
}
|
||||
|
||||
return builder.build().toUri().toString();
|
||||
}
|
||||
|
||||
private void waitForRateLimit() {
|
||||
|
||||
Reference in New Issue
Block a user