mirror of
https://code.castopod.org/adaures/castopod
synced 2025-04-23 01:01:20 +00:00

- update CI process to include quality stage (tests + code review) - add captainhook to install git pre-commit & pre-push hooks - remove .devcontainer Dockerfile to use project's docker-compose services: all services can now be started automatically using vscode - update docs/setup-development.md
63 lines
1.9 KiB
PHP
63 lines
1.9 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @copyright 2020 Podlibre
|
|
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
|
|
* @link https://castopod.org/
|
|
*/
|
|
|
|
namespace App\Controllers;
|
|
|
|
use CodeIgniter\HTTP\ResponseInterface;
|
|
use CodeIgniter\Exceptions\PageNotFoundException;
|
|
use Opawg\UserAgentsPhp\UserAgentsRSS;
|
|
use Exception;
|
|
use App\Models\EpisodeModel;
|
|
use App\Models\PodcastModel;
|
|
use CodeIgniter\Controller;
|
|
|
|
class Feed extends Controller
|
|
{
|
|
public function index($podcastName): ResponseInterface
|
|
{
|
|
helper('rss');
|
|
|
|
$podcast = (new PodcastModel())->where('name', $podcastName)->first();
|
|
if (!$podcast) {
|
|
throw PageNotFoundException::forPageNotFound();
|
|
}
|
|
|
|
$serviceSlug = '';
|
|
try {
|
|
$service = UserAgentsRSS::find($_SERVER['HTTP_USER_AGENT']);
|
|
if ($service) {
|
|
$serviceSlug = $service['slug'];
|
|
}
|
|
} catch (Exception $exception) {
|
|
// If things go wrong the show must go on and the user must be able to download the file
|
|
log_message('critical', $exception);
|
|
}
|
|
|
|
$cacheName =
|
|
"podcast#{$podcast->id}_feed" . ($service ? "_{$serviceSlug}" : '');
|
|
|
|
if (!($found = cache($cacheName))) {
|
|
$found = get_rss_feed($podcast, $serviceSlug);
|
|
|
|
// The page cache is set to expire after next episode publication or a decade by default so it is deleted manually upon podcast update
|
|
$secondsToNextUnpublishedEpisode = (new EpisodeModel())->getSecondsToNextUnpublishedEpisode(
|
|
$podcast->id,
|
|
);
|
|
|
|
cache()->save(
|
|
$cacheName,
|
|
$found,
|
|
$secondsToNextUnpublishedEpisode
|
|
? $secondsToNextUnpublishedEpisode
|
|
: DECADE,
|
|
);
|
|
}
|
|
return $this->response->setXML($found);
|
|
}
|
|
}
|