diff --git a/app/Controllers/HomeController.php b/app/Controllers/HomeController.php index 1daacbd6f37fe460aebde5193f806c6f72032e2c..7031b741ae3492b68da17e59370ca0b195021cd9 100644 --- a/app/Controllers/HomeController.php +++ b/app/Controllers/HomeController.php @@ -11,25 +11,25 @@ declare(strict_types=1); namespace App\Controllers; use App\Models\PodcastModel; -use CodeIgniter\Database\Exceptions\DatabaseException; use CodeIgniter\HTTP\RedirectResponse; use Config\Services; -use mysqli_sql_exception; class HomeController extends BaseController { public function index(): RedirectResponse | string { - try { - $allPodcasts = (new PodcastModel())->findAll(); - } catch (mysqli_sql_exception | DatabaseException) { - // An error was caught when retrieving the podcasts from the database. + $connections = \CodeIgniter\Database\Config::getConnections(); + $db = db_connect(); + if ($connections === [] || ! $db->tableExists('podcasts')) { + // Cannot connect to the database or cannot find the podcasts table // Redirecting to install page because it is likely that Castopod Host has not been installed yet. // NB: as base_url wouldn't have been defined here, redirect to install wizard manually $route = Services::routes()->reverseRoute('install'); return redirect()->to(rtrim(host_url(), '/') . $route); } + $allPodcasts = (new PodcastModel())->findAll(); + // check if there's only one podcast to redirect user to it if (count($allPodcasts) === 1) { return redirect()->route('podcast-activity', [$allPodcasts[0]->name]); diff --git a/app/Controllers/NoteController.php b/app/Controllers/NoteController.php index 0182fd29f688b4d0183dc0a9fa15207ab865de1a..39831e1cf62dddfc2e3a461b2953a5e7c37f8aea 100644 --- a/app/Controllers/NoteController.php +++ b/app/Controllers/NoteController.php @@ -39,28 +39,24 @@ class NoteController extends ActivityPubNoteController public function _remap(string $method, string ...$params): mixed { - if (count($params) < 2) { - throw PageNotFoundException::forPageNotFound(); - } - if ( - ($this->podcast = (new PodcastModel())->getPodcastByName($params[0])) === null + ($podcast = (new PodcastModel())->getPodcastByName($params[0],)) === null ) { throw PageNotFoundException::forPageNotFound(); } + $this->podcast = $podcast; $this->actor = $this->podcast->actor; if ( - ($note = (new NoteModel())->getNoteById($params[1])) === null + count($params) > 1 && + ($note = (new NoteModel())->getNoteById($params[1])) !== null ) { - throw PageNotFoundException::forPageNotFound(); - } - - $this->note = $note; + $this->note = $note; - unset($params[0]); - unset($params[1]); + unset($params[0]); + unset($params[1]); + } return $this->{$method}(...$params); } diff --git a/app/Controllers/PodcastController.php b/app/Controllers/PodcastController.php index 793352512a910999f4893f3abdefbdea8adf7486..b3dd5351da66fcbd3ec138e713bb5c01aa3e9c58 100644 --- a/app/Controllers/PodcastController.php +++ b/app/Controllers/PodcastController.php @@ -38,6 +38,7 @@ class PodcastController extends BaseController $this->podcast = $podcast; unset($params[0]); + return $this->{$method}(...$params); } diff --git a/app/Libraries/ActivityPub/Controllers/ActorController.php b/app/Libraries/ActivityPub/Controllers/ActorController.php index 8b8705b4a1877fabba50d02bdd9393512f5df16a..41ab1e1f35dfa059e0424afb0f375d8fd65f1771 100644 --- a/app/Libraries/ActivityPub/Controllers/ActorController.php +++ b/app/Libraries/ActivityPub/Controllers/ActorController.php @@ -272,9 +272,9 @@ class ActorController extends Controller ->where('`created_at` <= NOW()', null, false) ->orderBy('created_at', 'DESC'); - $pageNumber = $this->request->getGet('page'); + $pageNumber = (int) $this->request->getGet('page'); - if (! isset($pageNumber)) { + if ($pageNumber < 1) { $actorActivity->paginate(12); $pager = $actorActivity->pager; $collection = new OrderedCollectionObject(null, $pager); @@ -304,9 +304,9 @@ class ActorController extends Controller ->where('activitypub_follows.target_actor_id', $this->actor->id) ->orderBy('activitypub_follows.created_at', 'DESC'); - $pageNumber = $this->request->getGet('page'); + $pageNumber = (int) $this->request->getGet('page'); - if (! isset($pageNumber)) { + if ($pageNumber < 1) { $followers->paginate(12); $pager = $followers->pager; $followersCollection = new OrderedCollectionObject(null, $pager); diff --git a/app/Libraries/ActivityPub/Controllers/NoteController.php b/app/Libraries/ActivityPub/Controllers/NoteController.php index 10cac4a5f7fbdaa75db911d557f2201dae2a5bca..05b748d69519df9b562d023e2969234457151289 100644 --- a/app/Libraries/ActivityPub/Controllers/NoteController.php +++ b/app/Libraries/ActivityPub/Controllers/NoteController.php @@ -39,10 +39,6 @@ class NoteController extends Controller public function _remap(string $method, string ...$params): mixed { - if (count($params) < 1) { - throw PageNotFoundException::forPageNotFound(); - } - if (($note = model('NoteModel')->getNoteById($params[0])) === null) { throw PageNotFoundException::forPageNotFound(); } @@ -80,9 +76,9 @@ class NoteController extends Controller ->where('`published_at` <= NOW()', null, false) ->orderBy('published_at', 'ASC'); - $pageNumber = $this->request->getGet('page'); + $pageNumber = (int) $this->request->getGet('page'); - if (! isset($pageNumber)) { + if ($pageNumber < 1) { $noteReplies->paginate(12); $pager = $noteReplies->pager; $collection = new OrderedCollectionObject(null, $pager); diff --git a/app/Libraries/ActivityPub/HttpSignature.php b/app/Libraries/ActivityPub/HttpSignature.php index a630613c714a5bb812597d8b9f2ccb8a5b08587d..046a1cf62d1bc710b4d0f944694896110ff09e71 100644 --- a/app/Libraries/ActivityPub/HttpSignature.php +++ b/app/Libraries/ActivityPub/HttpSignature.php @@ -35,7 +35,7 @@ class HttpSignature ([\w\-\.#\/@]+) )", algorithm="(?P<algorithm>[\w\-]+)", - (headers="\(request-target\) (?P<headers>[\w\\-\s]+)")? + (headers="\(request-target\) (?P<headers>[\w\\-\s]+)",)? signature="(?P<signature>[\w+\/]+={0,2})" /x';