fix: 🐛 fix crash if no cache is configured
This commit is contained in:
parent
bc8db22fce
commit
42bfdb530b
@ -10,12 +10,14 @@ use OCA\RePod\AppInfo\Application;
|
|||||||
use OCP\AppFramework\Controller;
|
use OCP\AppFramework\Controller;
|
||||||
use OCP\AppFramework\Http\JSONResponse;
|
use OCP\AppFramework\Http\JSONResponse;
|
||||||
use OCP\Http\Client\IClientService;
|
use OCP\Http\Client\IClientService;
|
||||||
|
use OCP\ICacheFactory;
|
||||||
use OCP\IRequest;
|
use OCP\IRequest;
|
||||||
|
|
||||||
class PodcastController extends Controller
|
class PodcastController extends Controller
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
IRequest $request,
|
IRequest $request,
|
||||||
|
private ICacheFactory $cacheFactory,
|
||||||
private IClientService $clientService,
|
private IClientService $clientService,
|
||||||
private PodcastDataReader $podcastDataReader
|
private PodcastDataReader $podcastDataReader
|
||||||
) {
|
) {
|
||||||
@ -27,11 +29,13 @@ class PodcastController extends Controller
|
|||||||
* @NoCSRFRequired
|
* @NoCSRFRequired
|
||||||
*/
|
*/
|
||||||
public function index(string $url): JSONResponse {
|
public function index(string $url): JSONResponse {
|
||||||
|
if ($this->cacheFactory->isLocalCacheAvailable()) {
|
||||||
try {
|
try {
|
||||||
$podcast = $this->podcastDataReader->tryGetCachedPodcastData($url);
|
$podcast = $this->podcastDataReader->tryGetCachedPodcastData($url);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$podcast = null;
|
$podcast = null;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($podcast) {
|
if ($podcast) {
|
||||||
return new JSONResponse($podcast);
|
return new JSONResponse($podcast);
|
||||||
@ -41,10 +45,12 @@ class PodcastController extends Controller
|
|||||||
$feed = $client->get($url);
|
$feed = $client->get($url);
|
||||||
$podcast = PodcastData::parseRssXml((string) $feed->getBody());
|
$podcast = PodcastData::parseRssXml((string) $feed->getBody());
|
||||||
|
|
||||||
|
if ($this->cacheFactory->isLocalCacheAvailable()) {
|
||||||
try {
|
try {
|
||||||
$this->podcastDataReader->trySetCachedPodcastData($url, $podcast);
|
$this->podcastDataReader->trySetCachedPodcastData($url, $podcast);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return new JSONResponse($podcast, $feed->getStatusCode());
|
return new JSONResponse($podcast, $feed->getStatusCode());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user