fix(fediverse): do not cache remote action form + fix typo on post routes for passing post uuid

+ remove unnecessary session->start() directive
This commit is contained in:
Yassine Doghri 2023-09-17 10:07:59 +00:00
parent 3189f12206
commit 4ecb42f7c8
8 changed files with 20 additions and 39 deletions

View File

@ -55,11 +55,11 @@ class Cache extends BaseConfig
* Whether to take the URL query string into consideration when generating * Whether to take the URL query string into consideration when generating
* output cache files. Valid options are: * output cache files. Valid options are:
* *
* false = Disabled * false = Disabled
* true = Enabled, take all query parameters into account. * true = Enabled, take all query parameters into account.
* Please be aware that this may result in numerous cache * Please be aware that this may result in numerous cache
* files generated for the same page over and over again. * files generated for the same page over and over again.
* array('q') = Enabled, but only take into account the specified list * ['q'] = Enabled, but only take into account the specified list
* of query parameters. * of query parameters.
* *
* @var boolean|string[] * @var boolean|string[]
@ -97,6 +97,7 @@ class Cache extends BaseConfig
* A string of reserved characters that will not be allowed in keys or tags. * A string of reserved characters that will not be allowed in keys or tags.
* Strings that violate this restriction will cause handlers to throw. * Strings that violate this restriction will cause handlers to throw.
* Default: {}()/\@: * Default: {}()/\@:
*
* Note: The default set is required for PSR-6 compliance. * Note: The default set is required for PSR-6 compliance.
*/ */
public string $reservedCharacters = '{}()/\@:'; public string $reservedCharacters = '{}()/\@:';

View File

@ -6,7 +6,7 @@ use CodeIgniter\Router\RouteCollection;
/** /**
* @var RouteCollection $routes * @var RouteCollection $routes
/** *
* -------------------------------------------------------------------- * --------------------------------------------------------------------
* Placeholder definitions * Placeholder definitions
* -------------------------------------------------------------------- * --------------------------------------------------------------------
@ -232,7 +232,7 @@ $routes->group('@(:podcastHandle)', static function ($routes): void {
], ],
'application/ld+json; profile="https://www.w3.org/ns/activitystreams' => [ 'application/ld+json; profile="https://www.w3.org/ns/activitystreams' => [
'namespace' => 'Modules\Fediverse\Controllers', 'namespace' => 'Modules\Fediverse\Controllers',
'controller-method' => 'PostController::index\$2', 'controller-method' => 'PostController::index/$2',
], ],
], ],
'filter' => 'allow-cors', 'filter' => 'allow-cors',

View File

@ -133,7 +133,6 @@ class EpisodeAudioController extends Controller
} }
$session = Services::session(); $session = Services::session();
$session->start();
$serviceName = ''; $serviceName = '';
if ($this->request->getGet('_from')) { if ($this->request->getGet('_from')) {

View File

@ -176,7 +176,7 @@ class EpisodeController extends BaseController
} }
$session = Services::session(); $session = Services::session();
$session->start();
if (service('superglobals')->server('HTTP_REFERER') !== null) { if (service('superglobals')->server('HTTP_REFERER') !== null) {
$session->set('embed_domain', parse_url(service('superglobals')->server('HTTP_REFERER'), PHP_URL_HOST)); $session->set('embed_domain', parse_url(service('superglobals')->server('HTTP_REFERER'), PHP_URL_HOST));
} }

View File

@ -249,28 +249,17 @@ class PostController extends FediversePostController
$this->registerPodcastWebpageHit($this->podcast->id); $this->registerPodcastWebpageHit($this->podcast->id);
} }
$cacheName = implode( $data = [
'_', 'metatags' => get_remote_actions_metatags($this->post, $action),
array_filter(['page', "post#{$this->post->id}", "remote_{$action}", service('request') ->getLocale()]), 'podcast' => $this->podcast,
); 'actor' => $this->actor,
'post' => $this->post,
'action' => $action,
];
if (! ($cachedView = cache($cacheName))) { helper('form');
$data = [
'metatags' => get_remote_actions_metatags($this->post, $action),
'podcast' => $this->podcast,
'actor' => $this->actor,
'post' => $this->post,
'action' => $action,
];
helper('form'); // NO VIEW CACHING: form has a CSRF token which should change on each request
return view('post/remote_action', $data);
return view('post/remote_action', $data, [
'cache' => DECADE,
'cache_name' => $cacheName,
]);
}
return (string) $cachedView;
} }
} }

View File

@ -24,7 +24,6 @@ trait AnalyticsTrait
set_user_session_entry_page(); set_user_session_entry_page();
$session = Services::session(); $session = Services::session();
$session->start();
if (! $session->get('denyListIp')) { if (! $session->get('denyListIp')) {
$db = db_connect(); $db = db_connect();

View File

@ -56,7 +56,6 @@ if (! function_exists('set_user_session_deny_list_ip')) {
function set_user_session_deny_list_ip(): void function set_user_session_deny_list_ip(): void
{ {
$session = Services::session(); $session = Services::session();
$session->start();
if (! $session->has('denyListIp')) { if (! $session->has('denyListIp')) {
$session->set('denyListIp', IpDb::find(client_ip()) !== null); $session->set('denyListIp', IpDb::find(client_ip()) !== null);
@ -71,7 +70,6 @@ if (! function_exists('set_user_session_location')) {
function set_user_session_location(): void function set_user_session_location(): void
{ {
$session = Services::session(); $session = Services::session();
$session->start();
$location = [ $location = [
'countryCode' => 'N/A', 'countryCode' => 'N/A',
@ -112,7 +110,6 @@ if (! function_exists('set_user_session_player')) {
function set_user_session_player(): void function set_user_session_player(): void
{ {
$session = Services::session(); $session = Services::session();
$session->start();
if (! $session->has('player')) { if (! $session->has('player')) {
$playerFound = null; $playerFound = null;
@ -155,7 +152,6 @@ if (! function_exists('set_user_session_browser')) {
function set_user_session_browser(): void function set_user_session_browser(): void
{ {
$session = Services::session(); $session = Services::session();
$session->start();
if (! $session->has('browser')) { if (! $session->has('browser')) {
$browserName = '- Other -'; $browserName = '- Other -';
@ -182,7 +178,6 @@ if (! function_exists('set_user_session_referer')) {
function set_user_session_referer(): void function set_user_session_referer(): void
{ {
$session = Services::session(); $session = Services::session();
$session->start();
$newreferer = isset($_SERVER['HTTP_REFERER']) $newreferer = isset($_SERVER['HTTP_REFERER'])
? $_SERVER['HTTP_REFERER'] ? $_SERVER['HTTP_REFERER']
@ -205,7 +200,6 @@ if (! function_exists('set_user_session_entry_page')) {
function set_user_session_entry_page(): void function set_user_session_entry_page(): void
{ {
$session = Services::session(); $session = Services::session();
$session->start();
$entryPage = $_SERVER['REQUEST_URI']; $entryPage = $_SERVER['REQUEST_URI'];
if (! $session->has('entryPage')) { if (! $session->has('entryPage')) {
@ -245,7 +239,6 @@ if (! function_exists('podcast_hit')) {
?int $subscriptionId, ?int $subscriptionId,
): void { ): void {
$session = Services::session(); $session = Services::session();
$session->start();
$clientIp = client_ip(); $clientIp = client_ip();

View File

@ -50,7 +50,7 @@ class PostController extends Controller
public function _remap(string $method, string ...$params): mixed public function _remap(string $method, string ...$params): mixed
{ {
if (count($params) === 0) { if ($params === []) {
throw PageNotFoundException::forPageNotFound(); throw PageNotFoundException::forPageNotFound();
} }