mirror of
https://code.castopod.org/adaures/castopod
synced 2025-06-06 18:31:05 +00:00
fix: check for database connection and podcasts table existence before redirecting to install
fix signature regex
This commit is contained in:
parent
cacd228098
commit
eb74e81c3d
@ -11,25 +11,25 @@ declare(strict_types=1);
|
|||||||
namespace App\Controllers;
|
namespace App\Controllers;
|
||||||
|
|
||||||
use App\Models\PodcastModel;
|
use App\Models\PodcastModel;
|
||||||
use CodeIgniter\Database\Exceptions\DatabaseException;
|
|
||||||
use CodeIgniter\HTTP\RedirectResponse;
|
use CodeIgniter\HTTP\RedirectResponse;
|
||||||
use Config\Services;
|
use Config\Services;
|
||||||
use mysqli_sql_exception;
|
|
||||||
|
|
||||||
class HomeController extends BaseController
|
class HomeController extends BaseController
|
||||||
{
|
{
|
||||||
public function index(): RedirectResponse | string
|
public function index(): RedirectResponse | string
|
||||||
{
|
{
|
||||||
try {
|
$connections = \CodeIgniter\Database\Config::getConnections();
|
||||||
$allPodcasts = (new PodcastModel())->findAll();
|
$db = db_connect();
|
||||||
} catch (mysqli_sql_exception | DatabaseException) {
|
if ($connections === [] || ! $db->tableExists('podcasts')) {
|
||||||
// An error was caught when retrieving the podcasts from the database.
|
// 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.
|
// 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
|
// NB: as base_url wouldn't have been defined here, redirect to install wizard manually
|
||||||
$route = Services::routes()->reverseRoute('install');
|
$route = Services::routes()->reverseRoute('install');
|
||||||
return redirect()->to(rtrim(host_url(), '/') . $route);
|
return redirect()->to(rtrim(host_url(), '/') . $route);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$allPodcasts = (new PodcastModel())->findAll();
|
||||||
|
|
||||||
// check if there's only one podcast to redirect user to it
|
// check if there's only one podcast to redirect user to it
|
||||||
if (count($allPodcasts) === 1) {
|
if (count($allPodcasts) === 1) {
|
||||||
return redirect()->route('podcast-activity', [$allPodcasts[0]->name]);
|
return redirect()->route('podcast-activity', [$allPodcasts[0]->name]);
|
||||||
|
@ -39,28 +39,24 @@ class NoteController extends ActivityPubNoteController
|
|||||||
|
|
||||||
public function _remap(string $method, string ...$params): mixed
|
public function _remap(string $method, string ...$params): mixed
|
||||||
{
|
{
|
||||||
if (count($params) < 2) {
|
|
||||||
throw PageNotFoundException::forPageNotFound();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
($this->podcast = (new PodcastModel())->getPodcastByName($params[0])) === null
|
($podcast = (new PodcastModel())->getPodcastByName($params[0],)) === null
|
||||||
) {
|
) {
|
||||||
throw PageNotFoundException::forPageNotFound();
|
throw PageNotFoundException::forPageNotFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->podcast = $podcast;
|
||||||
$this->actor = $this->podcast->actor;
|
$this->actor = $this->podcast->actor;
|
||||||
|
|
||||||
if (
|
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[0]);
|
||||||
unset($params[1]);
|
unset($params[1]);
|
||||||
|
}
|
||||||
|
|
||||||
return $this->{$method}(...$params);
|
return $this->{$method}(...$params);
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,7 @@ class PodcastController extends BaseController
|
|||||||
$this->podcast = $podcast;
|
$this->podcast = $podcast;
|
||||||
|
|
||||||
unset($params[0]);
|
unset($params[0]);
|
||||||
|
|
||||||
return $this->{$method}(...$params);
|
return $this->{$method}(...$params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -272,9 +272,9 @@ class ActorController extends Controller
|
|||||||
->where('`created_at` <= NOW()', null, false)
|
->where('`created_at` <= NOW()', null, false)
|
||||||
->orderBy('created_at', 'DESC');
|
->orderBy('created_at', 'DESC');
|
||||||
|
|
||||||
$pageNumber = $this->request->getGet('page');
|
$pageNumber = (int) $this->request->getGet('page');
|
||||||
|
|
||||||
if (! isset($pageNumber)) {
|
if ($pageNumber < 1) {
|
||||||
$actorActivity->paginate(12);
|
$actorActivity->paginate(12);
|
||||||
$pager = $actorActivity->pager;
|
$pager = $actorActivity->pager;
|
||||||
$collection = new OrderedCollectionObject(null, $pager);
|
$collection = new OrderedCollectionObject(null, $pager);
|
||||||
@ -304,9 +304,9 @@ class ActorController extends Controller
|
|||||||
->where('activitypub_follows.target_actor_id', $this->actor->id)
|
->where('activitypub_follows.target_actor_id', $this->actor->id)
|
||||||
->orderBy('activitypub_follows.created_at', 'DESC');
|
->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);
|
$followers->paginate(12);
|
||||||
$pager = $followers->pager;
|
$pager = $followers->pager;
|
||||||
$followersCollection = new OrderedCollectionObject(null, $pager);
|
$followersCollection = new OrderedCollectionObject(null, $pager);
|
||||||
|
@ -39,10 +39,6 @@ class NoteController extends Controller
|
|||||||
|
|
||||||
public function _remap(string $method, string ...$params): mixed
|
public function _remap(string $method, string ...$params): mixed
|
||||||
{
|
{
|
||||||
if (count($params) < 1) {
|
|
||||||
throw PageNotFoundException::forPageNotFound();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (($note = model('NoteModel')->getNoteById($params[0])) === null) {
|
if (($note = model('NoteModel')->getNoteById($params[0])) === null) {
|
||||||
throw PageNotFoundException::forPageNotFound();
|
throw PageNotFoundException::forPageNotFound();
|
||||||
}
|
}
|
||||||
@ -80,9 +76,9 @@ class NoteController extends Controller
|
|||||||
->where('`published_at` <= NOW()', null, false)
|
->where('`published_at` <= NOW()', null, false)
|
||||||
->orderBy('published_at', 'ASC');
|
->orderBy('published_at', 'ASC');
|
||||||
|
|
||||||
$pageNumber = $this->request->getGet('page');
|
$pageNumber = (int) $this->request->getGet('page');
|
||||||
|
|
||||||
if (! isset($pageNumber)) {
|
if ($pageNumber < 1) {
|
||||||
$noteReplies->paginate(12);
|
$noteReplies->paginate(12);
|
||||||
$pager = $noteReplies->pager;
|
$pager = $noteReplies->pager;
|
||||||
$collection = new OrderedCollectionObject(null, $pager);
|
$collection = new OrderedCollectionObject(null, $pager);
|
||||||
|
@ -35,7 +35,7 @@ class HttpSignature
|
|||||||
([\w\-\.#\/@]+)
|
([\w\-\.#\/@]+)
|
||||||
)",
|
)",
|
||||||
algorithm="(?P<algorithm>[\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})"
|
signature="(?P<signature>[\w+\/]+={0,2})"
|
||||||
/x';
|
/x';
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user