mirror of
https://github.com/friendica/friendica
synced 2024-11-14 03:42:53 +00:00
Enable POST route for /filerm module
- This prevents a costly page empty page render when calling the module asynchronously
This commit is contained in:
parent
bdd80eeaaf
commit
cacfc6ec92
2 changed files with 57 additions and 20 deletions
|
@ -21,30 +21,68 @@
|
||||||
|
|
||||||
namespace Friendica\Module\Filer;
|
namespace Friendica\Module\Filer;
|
||||||
|
|
||||||
|
use Friendica\App;
|
||||||
use Friendica\BaseModule;
|
use Friendica\BaseModule;
|
||||||
|
use Friendica\Core\L10n;
|
||||||
|
use Friendica\Core\System;
|
||||||
use Friendica\Database\DBA;
|
use Friendica\Database\DBA;
|
||||||
use Friendica\DI;
|
|
||||||
use Friendica\Model\Post;
|
use Friendica\Model\Post;
|
||||||
|
use Friendica\Module\Response;
|
||||||
|
use Friendica\Navigation\SystemMessages;
|
||||||
use Friendica\Network\HTTPException;
|
use Friendica\Network\HTTPException;
|
||||||
use Friendica\Util\XML;
|
use Friendica\Util\Profiler;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove a tag from a file
|
* Remove a tag from a file
|
||||||
*/
|
*/
|
||||||
class RemoveTag extends BaseModule
|
class RemoveTag extends BaseModule
|
||||||
{
|
{
|
||||||
|
/** @var SystemMessages */
|
||||||
|
private $systemMessages;
|
||||||
|
|
||||||
|
public function __construct(SystemMessages $systemMessages, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
|
||||||
|
{
|
||||||
|
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||||
|
|
||||||
|
$this->systemMessages = $systemMessages;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function post(array $request = [])
|
||||||
|
{
|
||||||
|
System::httpError($this->removeTag($request));
|
||||||
|
}
|
||||||
|
|
||||||
protected function content(array $request = []): string
|
protected function content(array $request = []): string
|
||||||
{
|
{
|
||||||
if (!local_user()) {
|
if (!local_user()) {
|
||||||
throw new HTTPException\ForbiddenException();
|
throw new HTTPException\ForbiddenException();
|
||||||
}
|
}
|
||||||
|
|
||||||
$logger = DI::logger();
|
$this->removeTag($request, $type, $term);
|
||||||
|
|
||||||
|
if ($type == Post\Category::FILE) {
|
||||||
|
$this->baseUrl->redirect('filed?file=' . rawurlencode($term));
|
||||||
|
}
|
||||||
|
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $request The $_REQUEST array
|
||||||
|
* @param string|null $type Output parameter with the computed type
|
||||||
|
* @param string|null $term Output parameter with the computed term
|
||||||
|
*
|
||||||
|
* @return int The relevant HTTP code
|
||||||
|
*
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
private function removeTag(array $request, string &$type = null, string &$term = null): int
|
||||||
|
{
|
||||||
$item_id = $this->parameters['id'] ?? 0;
|
$item_id = $this->parameters['id'] ?? 0;
|
||||||
|
|
||||||
$term = XML::unescape(trim($_GET['term'] ?? ''));
|
$term = trim($request['term'] ?? '');
|
||||||
$cat = XML::unescape(trim($_GET['cat'] ?? ''));
|
$cat = trim($request['cat'] ?? '');
|
||||||
|
|
||||||
if (!empty($cat)) {
|
if (!empty($cat)) {
|
||||||
$type = Post\Category::CATEGORY;
|
$type = Post\Category::CATEGORY;
|
||||||
|
@ -53,28 +91,27 @@ class RemoveTag extends BaseModule
|
||||||
$type = Post\Category::FILE;
|
$type = Post\Category::FILE;
|
||||||
}
|
}
|
||||||
|
|
||||||
$logger->info('Filer - Remove Tag', [
|
$this->logger->info('Filer - Remove Tag', [
|
||||||
'term' => $term,
|
'term' => $term,
|
||||||
'item' => $item_id,
|
'item' => $item_id,
|
||||||
'type' => $type
|
'type' => $type
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if ($item_id && strlen($term)) {
|
if (!$item_id || !strlen($term)) {
|
||||||
|
$this->systemMessages->addNotice($this->l10n->t('Item was not deleted'));
|
||||||
|
return 401;
|
||||||
|
}
|
||||||
|
|
||||||
$item = Post::selectFirst(['uri-id'], ['id' => $item_id]);
|
$item = Post::selectFirst(['uri-id'], ['id' => $item_id]);
|
||||||
if (!DBA::isResult($item)) {
|
if (!DBA::isResult($item)) {
|
||||||
return '';
|
return 404;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Post\Category::deleteFileByURIId($item['uri-id'], local_user(), $type, $term)) {
|
if (!Post\Category::deleteFileByURIId($item['uri-id'], local_user(), $type, $term)) {
|
||||||
notice(DI::l10n()->t('Item was not removed'));
|
$this->systemMessages->addNotice($this->l10n->t('Item was not removed'));
|
||||||
}
|
return 500;
|
||||||
} else {
|
|
||||||
notice(DI::l10n()->t('Item was not deleted'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($type == Post\Category::FILE) {
|
return 200;
|
||||||
DI::baseUrl()->redirect('filed?file=' . rawurlencode($term));
|
|
||||||
}
|
|
||||||
|
|
||||||
return '';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -410,7 +410,7 @@ return [
|
||||||
],
|
],
|
||||||
'/filed' => [Module\Search\Filed::class, [R::GET]],
|
'/filed' => [Module\Search\Filed::class, [R::GET]],
|
||||||
'/filer[/{id:\d+}]' => [Module\Filer\SaveTag::class, [R::GET]],
|
'/filer[/{id:\d+}]' => [Module\Filer\SaveTag::class, [R::GET]],
|
||||||
'/filerm/{id:\d+}' => [Module\Filer\RemoveTag::class, [R::GET]],
|
'/filerm/{id:\d+}' => [Module\Filer\RemoveTag::class, [R::GET, R::POST]],
|
||||||
'/follow_confirm' => [Module\FollowConfirm::class, [R::GET, R::POST]],
|
'/follow_confirm' => [Module\FollowConfirm::class, [R::GET, R::POST]],
|
||||||
'/followers/{nickname}' => [Module\ActivityPub\Followers::class, [R::GET]],
|
'/followers/{nickname}' => [Module\ActivityPub\Followers::class, [R::GET]],
|
||||||
'/following/{nickname}' => [Module\ActivityPub\Following::class, [R::GET]],
|
'/following/{nickname}' => [Module\ActivityPub\Following::class, [R::GET]],
|
||||||
|
|
Loading…
Reference in a new issue