diff --git a/config/services.yaml b/config/services.yaml index f75d8efc..ba8e1745 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -8,10 +8,12 @@ parameters: BOOK_FILE_NAMING_FORMAT: '%env(BOOK_FILE_NAMING_FORMAT)%' KOBO_PROXY_ENABLED: '%env(bool:KOBO_PROXY_ENABLED)%' env(KOBO_PROXY_ENABLED): true - KOBO_PROXY_USE_DEV: '%env(bool:KOBO_PROXY_USE_DEV)%' - env(KOBO_PROXY_USE_DEV): false KOBO_PROXY_USE_EVERYWHERE: '%env(bool:KOBO_PROXY_USE_EVERYWHERE)%' env(KOBO_PROXY_USE_EVERYWHERE): false + env(KOBO_API_URL): "https://storeapi.kobo.com" + KOBO_API_URL: '%env(KOBO_API_URL)%' + env(KOBO_IMAGE_API_URL): "https://cdn.kobo.com/book-images" + KOBO_IMAGE_API_URL: '%env(KOBO_IMAGE_API_URL)%' services: # default configuration for services in *this* file _defaults: @@ -92,7 +94,8 @@ services: App\Kobo\Proxy\KoboProxyConfiguration: calls: - - [ setUseDevProxy, ['%KOBO_PROXY_USE_DEV%'] ] + - [ setStoreApiUrl, ['%KOBO_API_URL%'] ] + - [ setImageApiUrl, ['%KOBO_IMAGE_API_URL%'] ] - [ setEnabled, ['%KOBO_PROXY_ENABLED%'] ] - [ setUseProxyEverywhere, ['%KOBO_PROXY_USE_EVERYWHERE%'] ] diff --git a/src/Kobo/Proxy/KoboProxyConfiguration.php b/src/Kobo/Proxy/KoboProxyConfiguration.php index 877c358e..5c5c9aa2 100644 --- a/src/Kobo/Proxy/KoboProxyConfiguration.php +++ b/src/Kobo/Proxy/KoboProxyConfiguration.php @@ -7,15 +7,11 @@ class KoboProxyConfiguration { - public const KOBO_STOREAPI_URL_PROD = 'https://storeapi.kobo.com'; - public const KOBO_IMAGEHOST_URL_PROD = 'https://cdn.kobo.com/book-images'; - public const KOBO_STOREAPI_URL_SAFE = 'https://books-proxy.example.com'; - public const KOBO_IMAGEHOST_URL_SAFE = 'https://books-proxy.example.com'; - private bool $useDevProxy = true; private bool $useProxy = true; - private bool $useProxyEverywhere = true; + private bool $useProxyEverywhere = false; - private bool $useRedirect = false; + private string $imageApiUrl = ''; + private string $storeApiUrl = ''; public function useProxy(): bool { @@ -27,19 +23,29 @@ public function useProxyEverywhere(): bool return $this->useProxyEverywhere; } - protected function useDevProxy(): bool + public function getStoreApiUrl(): string { - return $this->useDevProxy; + if ($this->storeApiUrl === '') { + throw new \InvalidArgumentException('Store API URL is not set'); + } + + return $this->storeApiUrl; } - public function getStoreApiUrl(): string + public function setStoreApiUrl(string $storeApiUrl): self { - return $this->useDevProxy() ? self::KOBO_STOREAPI_URL_SAFE : self::KOBO_STOREAPI_URL_PROD; + $this->storeApiUrl = $storeApiUrl; + + return $this; } public function getImageApiUrl(): string { - return $this->useDevProxy() ? self::KOBO_IMAGEHOST_URL_SAFE : self::KOBO_IMAGEHOST_URL_PROD; + if ($this->storeApiUrl === '') { + throw new \InvalidArgumentException('Image API URL is not set'); + } + + return $this->imageApiUrl; } public function isImageHostUrl(Request|RequestInterface $request): bool @@ -51,9 +57,9 @@ public function isImageHostUrl(Request|RequestInterface $request): bool || str_ends_with($uri, '.jpeg'); } - public function setUseDevProxy(bool $useDevProxy): KoboProxyConfiguration + public function setImageApiUrl(string $imageApiUrl): KoboProxyConfiguration { - $this->useDevProxy = $useDevProxy; + $this->imageApiUrl = $imageApiUrl; return $this; } @@ -65,30 +71,6 @@ public function setEnabled(bool $useProxy): KoboProxyConfiguration return $this; } - public function setUseProxyEverywhere(bool $useProxyEverywhere): KoboProxyConfiguration - { - $this->useProxyEverywhere = $useProxyEverywhere; - - return $this; - } - - public function isBlacklistedForEveryWhere(Request $request): bool - { - return false; - } - - public function setUseRedirect(bool $useRedirect): KoboProxyConfiguration - { - $this->useRedirect = $useRedirect; - - return $this; - } - - public function isUseRedirect(): bool - { - return $this->useRedirect; - } - public function getNativeInitializationJson(): array { return [ @@ -242,4 +224,11 @@ public function getNativeInitializationJson(): array 'wishlist_page' => 'https://store.kobobooks.com/{region}/{language}/account/wishlist', ]; } + + public function setUseProxyEverywhere(bool $useProxyEverywhere): self + { + $this->useProxyEverywhere = $useProxyEverywhere; + + return $this; + } }