mirror of
https://git.crystalyx.net/Xefir/repod.git
synced 2024-12-28 01:32:49 +01:00
52 lines
1.2 KiB
PHP
52 lines
1.2 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);
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
*/
|
|
public function index(string $url): JSONResponse {
|
|
try {
|
|
$podcast = $this->podcastDataReader->tryGetCachedPodcastData($url);
|
|
} catch (\Exception $e) {
|
|
$podcast = null;
|
|
}
|
|
|
|
if ($podcast) {
|
|
return new JSONResponse($podcast);
|
|
}
|
|
|
|
$client = $this->clientService->newClient();
|
|
$feed = $client->get($url);
|
|
$podcast = PodcastData::parseRssXml((string) $feed->getBody());
|
|
|
|
try {
|
|
$this->podcastDataReader->trySetCachedPodcastData($url, $podcast);
|
|
} catch (\Exception $e) {
|
|
}
|
|
|
|
return new JSONResponse($podcast, $feed->getStatusCode());
|
|
}
|
|
}
|