mirror of
https://github.com/ad-aures/castopod.git
synced 2026-04-11 18:56:42 +02:00
feat(activitypub): add Podcast actor and PodcastEpisode object with comments
This commit is contained in:
parent
b814cfaf7c
commit
9e1e5d2e86
13 changed files with 316 additions and 17 deletions
|
|
@ -10,12 +10,18 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Controllers;
|
||||
|
||||
use ActivityPub\Objects\OrderedCollectionObject;
|
||||
use ActivityPub\Objects\OrderedCollectionPage;
|
||||
use Analytics\AnalyticsTrait;
|
||||
use App\Entities\Podcast;
|
||||
use App\Libraries\PodcastActor;
|
||||
use App\Libraries\PodcastEpisode;
|
||||
use App\Models\EpisodeModel;
|
||||
use App\Models\PodcastModel;
|
||||
use App\Models\StatusModel;
|
||||
use CodeIgniter\Exceptions\PageNotFoundException;
|
||||
use CodeIgniter\HTTP\RedirectResponse;
|
||||
use CodeIgniter\HTTP\Response;
|
||||
|
||||
class PodcastController extends BaseController
|
||||
{
|
||||
|
|
@ -42,6 +48,15 @@ class PodcastController extends BaseController
|
|||
return $this->{$method}(...$params);
|
||||
}
|
||||
|
||||
public function podcastActor(): RedirectResponse
|
||||
{
|
||||
$podcastActor = new PodcastActor($this->podcast);
|
||||
|
||||
return $this->response
|
||||
->setContentType('application/activity+json')
|
||||
->setBody($podcastActor->toJSON());
|
||||
}
|
||||
|
||||
public function activity(): string
|
||||
{
|
||||
// Prevent analytics hit when authenticated
|
||||
|
|
@ -209,4 +224,46 @@ class PodcastController extends BaseController
|
|||
|
||||
return $cachedView;
|
||||
}
|
||||
|
||||
/**
|
||||
* @noRector ReturnTypeDeclarationRector
|
||||
*/
|
||||
public function episodeCollection(): Response
|
||||
{
|
||||
if ($this->podcast->type === 'serial') {
|
||||
// podcast is serial
|
||||
$episodes = model('EpisodeModel')
|
||||
->where('`published_at` <= NOW()', null, false)
|
||||
->orderBy('season_number DESC, number ASC');
|
||||
} else {
|
||||
$episodes = model('EpisodeModel')
|
||||
->where('`published_at` <= NOW()', null, false)
|
||||
->orderBy('published_at', 'DESC');
|
||||
}
|
||||
|
||||
$pageNumber = (int) $this->request->getGet('page');
|
||||
|
||||
if ($pageNumber < 1) {
|
||||
$episodes->paginate(12);
|
||||
$pager = $episodes->pager;
|
||||
$collection = new OrderedCollectionObject(null, $pager);
|
||||
} else {
|
||||
$paginatedEpisodes = $episodes->paginate(12, 'default', $pageNumber);
|
||||
$pager = $episodes->pager;
|
||||
|
||||
$orderedItems = [];
|
||||
if ($paginatedEpisodes !== null) {
|
||||
foreach ($paginatedEpisodes as $episode) {
|
||||
$orderedItems[] = (new PodcastEpisode($episode))->toArray();
|
||||
}
|
||||
}
|
||||
|
||||
// @phpstan-ignore-next-line
|
||||
$collection = new OrderedCollectionPage($pager, $orderedItems);
|
||||
}
|
||||
|
||||
return $this->response
|
||||
->setContentType('application/activity+json')
|
||||
->setBody($collection->toJSON());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue