repod/lib/Controller/PodcastController.php
Michel Roux 540c5df7e5
All checks were successful
repod / xml (push) Successful in 22s
repod / php (push) Successful in 56s
repod / nodejs (push) Successful in 2m5s
repod / release (push) Has been skipped
refacto: remove atomlink that leads to weird bugs
2024-01-16 14:21:35 +01:00

40 lines
1.0 KiB
PHP

<?php
declare(strict_types=1);
namespace OCA\RePod\Controller;
use OCA\GPodderSync\Core\PodcastData\PodcastData;
use OCA\GPodderSync\Core\PodcastData\PodcastDataReader;
use OCA\RePod\AppInfo\Application;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\JSONResponse;
use OCP\Http\Client\IClientService;
use OCP\IRequest;
class PodcastController extends Controller
{
public function __construct(
IRequest $request,
private IClientService $clientService,
private PodcastDataReader $podcastDataReader
) {
parent::__construct(Application::APP_ID, $request);
}
public function index(string $url): JSONResponse {
$podcast = $this->podcastDataReader->tryGetCachedPodcastData($url);
if ($podcast) {
return new JSONResponse($podcast);
}
$client = $this->clientService->newClient();
$feed = $client->get($url);
$podcast = PodcastData::parseRssXml((string) $feed->getBody());
$this->podcastDataReader->trySetCachedPodcastData($url, $podcast);
return new JSONResponse($podcast, $feed->getStatusCode());
}
}