feat(google-books): add optional API key configuration (#2629)

This commit is contained in:
ACX
2026-02-05 22:37:12 -07:00
committed by GitHub
parent e0c3d8b50d
commit 37ea0b156f
5 changed files with 30 additions and 8 deletions

View File

@@ -27,6 +27,7 @@ public class MetadataProviderSettings {
public static class Google {
private boolean enabled;
private String language;
private String apiKey;
}
@Data

View File

@@ -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() {

View File

@@ -65,6 +65,16 @@
class="config-select">
</p-select>
</div>
<div class="config-field">
<label class="config-label">API Key (Optional)</label>
<p class="config-description">Providing a Google Books API key increases rate limits and improves reliability.</p>
<input
type="text"
pInputText
placeholder="Enter Google Books API key"
[(ngModel)]="googleApiKey"
class="config-input"/>
</div>
</div>
}
</div>

View File

@@ -95,6 +95,7 @@ export class MetadataProviderSettingsComponent implements OnInit {
doubanEnabled: boolean = false;
lubimyCzytacEnabled: boolean = false;
ranobedbEnabled: boolean = false;
googleApiKey: string = '';
private appSettingsService = inject(AppSettingsService);
private messageService = inject(MessageService);
@@ -116,6 +117,7 @@ export class MetadataProviderSettingsComponent implements OnInit {
this.goodreadsEnabled = metadataProviderSettings?.goodReads?.enabled ?? false;
this.googleEnabled = metadataProviderSettings?.google?.enabled ?? false;
this.selectedGoogleLanguage = metadataProviderSettings?.google?.language ?? '';
this.googleApiKey = metadataProviderSettings?.google?.apiKey ?? '';
this.hardcoverToken = metadataProviderSettings?.hardcover?.apiKey ?? '';
this.hardcoverEnabled = metadataProviderSettings?.hardcover?.enabled ?? false;
this.comicvineEnabled = metadataProviderSettings?.comicvine?.enabled ?? false;
@@ -157,6 +159,7 @@ export class MetadataProviderSettingsComponent implements OnInit {
google: {
enabled: this.googleEnabled,
language: this.selectedGoogleLanguage,
apiKey: this.googleApiKey.trim()
},
hardcover: {
enabled: this.hardcoverEnabled,

View File

@@ -66,6 +66,7 @@ export interface Amazon {
export interface Google {
enabled: boolean;
language: string;
apiKey: string;
}
export interface Goodreads {