Commit 3234500e authored by Yassine Doghri's avatar Yassine Doghri
Browse files

feat: add premium podcasts to manage subscriptions for premium episodes

closes #193
parent b6114d3d
Loading
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -51,6 +51,7 @@ class Autoload extends AutoloadConfig
        'Modules\Fediverse' => ROOTPATH . 'modules/Fediverse/',
        'Modules\WebSub' => ROOTPATH . 'modules/WebSub/',
        'Modules\Api\Rest\V1' => ROOTPATH . 'modules/Api/Rest/V1',
        'Modules\PremiumPodcasts' => ROOTPATH . 'modules/PremiumPodcasts/',
        'Config' => APPPATH . 'Config/',
        'ViewComponents' => APPPATH . 'Libraries/ViewComponents/',
        'ViewThemes' => APPPATH . 'Libraries/ViewThemes/',
+5 −0
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@ use Modules\Api\Rest\V1\Filters\ApiFilter;
use Modules\Auth\Filters\PermissionFilter;
use Modules\Fediverse\Filters\AllowCorsFilter;
use Modules\Fediverse\Filters\FediverseFilter;
use Modules\PremiumPodcasts\Filters\PodcastUnlockFilter;
use Myth\Auth\Filters\LoginFilter;
use Myth\Auth\Filters\RoleFilter;

@@ -36,6 +37,7 @@ class Filters extends BaseConfig
        'fediverse' => FediverseFilter::class,
        'allow-cors' => AllowCorsFilter::class,
        'rest-api' => ApiFilter::class,
        'podcast-unlock' => PodcastUnlockFilter::class,
    ];

    /**
@@ -87,6 +89,9 @@ class Filters extends BaseConfig
            'login' => [
                'before' => [config('Admin')->gateway . '*', config('Analytics')->gateway . '*'],
            ],
            'podcast-unlock' => [
                'before' => ['*@*/episodes/*'],
            ],
        ];
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -28,7 +28,7 @@ abstract class BaseController extends Controller
        ResponseInterface $response,
        LoggerInterface $logger
    ): void {
        $this->helpers = array_merge($this->helpers, ['auth', 'svg', 'components', 'misc', 'seo']);
        $this->helpers = array_merge($this->helpers, ['auth', 'svg', 'components', 'misc', 'seo', 'premium_podcasts']);

        // Do Not Edit This Line
        parent::initController($request, $response, $logger);
+19 −4
Original line number Diff line number Diff line
@@ -10,19 +10,21 @@ declare(strict_types=1);

namespace App\Controllers;

use App\Entities\Podcast;
use App\Models\EpisodeModel;
use App\Models\PodcastModel;
use CodeIgniter\Controller;
use CodeIgniter\Exceptions\PageNotFoundException;
use CodeIgniter\HTTP\ResponseInterface;
use Exception;
use Modules\PremiumPodcasts\Models\SubscriptionModel;
use Opawg\UserAgentsPhp\UserAgentsRSS;

class FeedController extends Controller
{
    public function index(string $podcastHandle): ResponseInterface
    {
        helper('rss');
        helper(['rss', 'premium_podcasts']);

        $podcast = (new PodcastModel())->where('handle', $podcastHandle)
            ->first();
@@ -43,11 +45,24 @@ class FeedController extends Controller
            $serviceSlug = $service['slug'];
        }

        $cacheName =
            "podcast#{$podcast->id}_feed" . ($service ? "_{$serviceSlug}" : '');
        $subscription = null;
        $token = $this->request->getGet('token');
        if ($token) {
            $subscription = (new SubscriptionModel())->validateSubscription($podcastHandle, $token);
        }

        $cacheName = implode(
            '_',
            array_filter([
                "podcast#{$podcast->id}",
                'feed',
                $service ? $serviceSlug : null,
                $subscription !== null ? 'unlocked' : null,
            ]),
        );

        if (! ($found = cache($cacheName))) {
            $found = get_rss_feed($podcast, $serviceSlug);
            $found = get_rss_feed($podcast, $serviceSlug, $subscription, $token);

            // 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(
+1 −1
Original line number Diff line number Diff line
@@ -40,7 +40,7 @@ class PostController extends FediversePostController
    /**
     * @var string[]
     */
    protected $helpers = ['auth', 'fediverse', 'svg', 'components', 'misc', 'seo'];
    protected $helpers = ['auth', 'fediverse', 'svg', 'components', 'misc', 'seo', 'premium_podcasts'];

    public function _remap(string $method, string ...$params): mixed
    {
Loading