fix(soundcloud): bug in prior cache refactor (#3516)

This commit is contained in:
Dag 2023-07-08 22:53:23 +02:00 committed by GitHub
parent adc38e65d9
commit 1a529fac46
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 18 deletions

View File

@ -36,13 +36,17 @@ class SoundCloudBridge extends BridgeAbstract
private $feedTitle = null;
private $feedIcon = null;
private $clientIDCache = null;
private $cache = null;
private $clientIdRegex = '/client_id.*?"(.+?)"/';
private $widgetRegex = '/widget-.+?\.js/';
public function collectData()
{
$this->cache = RssBridge::getCache();
$this->cache->setScope('SoundCloudBridge');
$this->cache->setKey(['client_id']);
$res = $this->getUser($this->getInput('u'));
$this->feedTitle = $res->username;
@ -116,22 +120,11 @@ HTML;
return parent::getName();
}
private function initClientIDCache()
{
if ($this->clientIDCache !== null) {
return;
}
$this->clientIDCache = RssBridge::getCache();
$this->clientIDCache->setScope('SoundCloudBridge');
$this->clientIDCache->setKey(['client_id']);
}
private function getClientID()
{
$this->initClientIDCache();
$clientID = $this->clientIDCache->loadData();
$this->cache->setScope('SoundCloudBridge');
$this->cache->setKey(['client_id']);
$clientID = $this->cache->loadData();
if ($clientID == null) {
return $this->refreshClientID();
@ -142,8 +135,6 @@ HTML;
private function refreshClientID()
{
$this->initClientIDCache();
$playerHTML = getContents($this->playerUrl);
// Extract widget JS filenames from player page
@ -161,7 +152,9 @@ HTML;
if (preg_match($this->clientIdRegex, $widgetJS, $matches)) {
$clientID = $matches[1];
$this->clientIDCache->saveData($clientID);
$this->cache->setScope('SoundCloudBridge');
$this->cache->setKey(['client_id']);
$this->cache->saveData($clientID);
return $clientID;
}