documentation and env changes
This commit is contained in:
@@ -24,8 +24,8 @@ class SpotifyClient
|
||||
public function __construct(
|
||||
HttpClientInterface $httpClient,
|
||||
CacheInterface $cache,
|
||||
string $clientId,
|
||||
string $clientSecret,
|
||||
?string $clientId,
|
||||
?string $clientSecret,
|
||||
SettingRepository $settings
|
||||
) {
|
||||
$this->httpClient = $httpClient;
|
||||
@@ -129,6 +129,8 @@ class SpotifyClient
|
||||
$offset += $limit;
|
||||
$total = isset($page['total']) ? (int) $page['total'] : null;
|
||||
$hasNext = isset($page['next']) && $page['next'] !== null;
|
||||
// Guard against Spotify omitting total by relying on the "next" cursor.
|
||||
// Ensures album requests stop when Spotify has no more pages.
|
||||
} while ($hasNext && ($total === null || $offset < $total));
|
||||
|
||||
return $items;
|
||||
@@ -197,6 +199,7 @@ class SpotifyClient
|
||||
|
||||
$shouldCache = $cacheTtlSeconds > 0 && strtoupper($method) === 'GET';
|
||||
if ($shouldCache) {
|
||||
// Cache fingerprint mixes URL and query only; headers are static (Bearer token).
|
||||
$cacheKey = 'spotify_resp_' . sha1($url . '|' . json_encode($options['query'] ?? []));
|
||||
return $this->cache->get($cacheKey, function (ItemInterface $item) use ($cacheTtlSeconds, $request) {
|
||||
$item->expiresAfter($cacheTtlSeconds);
|
||||
@@ -268,12 +271,22 @@ class SpotifyClient
|
||||
});
|
||||
|
||||
if ($token === null) {
|
||||
// Remove failed entries so the next request retries instead of serving cached nulls.
|
||||
// Nuke cached nulls so the next request retries instead of reusing the failure sentinel.
|
||||
$this->cache->delete($cacheKey);
|
||||
}
|
||||
|
||||
return $token;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true when credentials are available from DB or environment.
|
||||
*/
|
||||
public function isConfigured(): bool
|
||||
{
|
||||
$clientId = trim((string) $this->settings->getValue('SPOTIFY_CLIENT_ID', $this->clientId ?? ''));
|
||||
$clientSecret = trim((string) $this->settings->getValue('SPOTIFY_CLIENT_SECRET', $this->clientSecret ?? ''));
|
||||
return $clientId !== '' && $clientSecret !== '';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user