summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMaxence Lange <maxence@artificial-owl.com>2020-06-18 20:55:54 -0100
committerMaxence Lange <maxence@artificial-owl.com>2020-06-18 20:55:54 -0100
commit0888efd78a56432b7ec0bc11d79c4dbc553c2214 (patch)
tree803b11f682fb22f09c31e3158d1b4ab0576fd842 /lib
parent1ebb155fcfef6086653c8f90c21d04a60b912b8a (diff)
fix route on non-token
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/Controller/ActivityPubController.php33
-rw-r--r--lib/Exceptions/RealTokenException.php39
2 files changed, 72 insertions, 0 deletions
diff --git a/lib/Controller/ActivityPubController.php b/lib/Controller/ActivityPubController.php
index 8037193f..23713aee 100644
--- a/lib/Controller/ActivityPubController.php
+++ b/lib/Controller/ActivityPubController.php
@@ -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);
}
@@ -368,6 +375,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.
*
* If not, should forward to a readable webpage that displays content for navigation.
diff --git a/lib/Exceptions/RealTokenException.php b/lib/Exceptions/RealTokenException.php
new file mode 100644
index 00000000..29b73f76
--- /dev/null
+++ b/lib/Exceptions/RealTokenException.php
@@ -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 {
+
+}
+