feat(rss): add option for 301 redirect to new feed url

This commit is contained in:
Yassine Doghri 2024-10-24 12:23:59 +00:00
commit 3a7d26fdf9
4 changed files with 27 additions and 2 deletions

View file

@ -33,14 +33,25 @@ class FeedController extends Controller
public function index(string $podcastHandle): ResponseInterface
{
helper(['rss', 'premium_podcasts', 'misc']);
$podcast = (new PodcastModel())->where('handle', $podcastHandle)
->first();
if (! $podcast instanceof Podcast) {
throw PageNotFoundException::forPageNotFound();
}
// 301 redirect to new feed?
$redirectToNewFeed = service('settings')
->get('Podcast.redirect_to_new_feed', 'podcast:' . $podcast->id);
if ($redirectToNewFeed && $podcast->new_feed_url !== null && filter_var(
$podcast->new_feed_url,
FILTER_VALIDATE_URL
) && $podcast->new_feed_url !== current_url()) {
return redirect()->to($podcast->new_feed_url, 301);
}
helper(['rss', 'premium_podcasts', 'misc']);
$service = null;
try {
$service = UserAgentsRSS::find(service('superglobals')->server('HTTP_USER_AGENT'));