fix route on non-token

Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
pull/912/head
Maxence Lange 2020-06-18 20:55:54 -01:00
rodzic 1ebb155fcf
commit 0888efd78a
2 zmienionych plików z 72 dodań i 0 usunięć

Wyświetl plik

@ -37,6 +37,7 @@ use Exception;
use OC\AppFramework\Http;
use OCA\Social\AppInfo\Application;
use OCA\Social\Exceptions\ItemUnknownException;
use OCA\Social\Exceptions\RealTokenException;
use OCA\Social\Exceptions\SignatureIsGoneException;
use OCA\Social\Exceptions\SocialAppConfigException;
use OCA\Social\Exceptions\StreamNotFoundException;
@ -351,8 +352,14 @@ class ActivityPubController extends Controller {
* @return Response
* @throws SocialAppConfigException
* @throws StreamNotFoundException
* @throws UrlCloudException
*/
public function displayPost(string $username, string $token): Response {
try {
return $this->fixToken($username, $token);
} catch (RealTokenException $e) {
}
if (!$this->checkSourceActivityStreams()) {
return $this->socialPubController->displayPost($username, $token);
}
@ -367,6 +374,32 @@ class ActivityPubController extends Controller {
}
/**
* @param string $username
* @param string $token
*
* @return Response
* @throws RealTokenException
* @throws SocialAppConfigException
* @throws UrlCloudException
*/
private function fixToken(string $username, string $token): Response {
$t = strtolower($token);
if ($t === 'outbox') {
return $this->outbox($username);
}
if ($t === 'followers') {
return $this->followers($username);
}
if ($t === 'following') {
return $this->following($username);
}
throw new RealTokenException();
}
/**
* Check that the request comes from an ActivityPub server, based on the header.
*

Wyświetl plik

@ -0,0 +1,39 @@
<?php
/**
* Nextcloud - Social Support
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2018, Maxence Lange <maxence@artificial-owl.com>
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Social\Exceptions;
use Exception;
class RealTokenException extends Exception {
}