From 42bfdb530bcfe69ea7e1425114ea2896e94a0cef Mon Sep 17 00:00:00 2001 From: Michel Roux Date: Fri, 14 Jun 2024 19:32:26 +0200 Subject: [PATCH] fix: :bug: fix crash if no cache is configured --- lib/Controller/PodcastController.php | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/lib/Controller/PodcastController.php b/lib/Controller/PodcastController.php index fb3a26e..4edbec7 100644 --- a/lib/Controller/PodcastController.php +++ b/lib/Controller/PodcastController.php @@ -10,12 +10,14 @@ use OCA\RePod\AppInfo\Application; use OCP\AppFramework\Controller; use OCP\AppFramework\Http\JSONResponse; use OCP\Http\Client\IClientService; +use OCP\ICacheFactory; use OCP\IRequest; class PodcastController extends Controller { public function __construct( IRequest $request, + private ICacheFactory $cacheFactory, private IClientService $clientService, private PodcastDataReader $podcastDataReader ) { @@ -27,10 +29,12 @@ class PodcastController extends Controller * @NoCSRFRequired */ public function index(string $url): JSONResponse { - try { - $podcast = $this->podcastDataReader->tryGetCachedPodcastData($url); - } catch (\Exception $e) { - $podcast = null; + if ($this->cacheFactory->isLocalCacheAvailable()) { + try { + $podcast = $this->podcastDataReader->tryGetCachedPodcastData($url); + } catch (\Exception $e) { + $podcast = null; + } } if ($podcast) { @@ -41,9 +45,11 @@ class PodcastController extends Controller $feed = $client->get($url); $podcast = PodcastData::parseRssXml((string) $feed->getBody()); - try { - $this->podcastDataReader->trySetCachedPodcastData($url, $podcast); - } catch (\Exception $e) { + if ($this->cacheFactory->isLocalCacheAvailable()) { + try { + $this->podcastDataReader->trySetCachedPodcastData($url, $podcast); + } catch (\Exception $e) { + } } return new JSONResponse($podcast, $feed->getStatusCode());