summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--appinfo/routes.php5
-rw-r--r--lib/Controller/LocalController.php31
-rw-r--r--lib/Controller/NavigationController.php44
3 files changed, 65 insertions, 15 deletions
diff --git a/appinfo/routes.php b/appinfo/routes.php
index 293d4bb7..6f86395e 100644
--- a/appinfo/routes.php
+++ b/appinfo/routes.php
@@ -21,8 +21,8 @@ return [
'requirements' => ['path' => '.+'], 'defaults' => ['path' => '']
],
['name' => 'Navigation#public', 'url' => '/{username}', 'verb' => 'GET'],
- ['name' => 'Navigation#documentsGet', 'url' => '/documents/get', 'verb' => 'GET'],
- ['name' => 'Navigation#documentsGetPublic', 'url' => '/documents/public', 'verb' => 'GET'],
+ ['name' => 'Navigation#documentGet', 'url' => '/document/get', 'verb' => 'GET'],
+ ['name' => 'Navigation#documentGetPublic', 'url' => '/document/public', 'verb' => 'GET'],
// ['name' => 'Account#create', 'url' => '/local/account/{username}', 'verb' => 'POST'],
['name' => 'Account#info', 'url' => '/local/account/{username}', 'verb' => 'GET'],
@@ -50,6 +50,7 @@ return [
['name' => 'Local#accountUnfollow', 'url' => '/api/v1/account/follow', 'verb' => 'DELETE'],
['name' => 'Local#accountInfo', 'url' => '/api/v1/account/info', 'verb' => 'GET'],
['name' => 'Local#actorInfo', 'url' => '/api/v1/actor/info', 'verb' => 'GET'],
+ ['name' => 'Local#documentsCache', 'url' => '/api/v1/documents/cache', 'verb' => 'POST'],
[
'name' => 'Config#setCloudAddress', 'url' => '/api/v1/config/cloudAddress',
diff --git a/lib/Controller/LocalController.php b/lib/Controller/LocalController.php
index cd6bb0f3..1217d523 100644
--- a/lib/Controller/LocalController.php
+++ b/lib/Controller/LocalController.php
@@ -398,4 +398,35 @@ class LocalController extends Controller {
}
}
+
+ /**
+ * // TODO: Delete the NoCSRF check
+ *
+ * @NoCSRFRequired
+ * @NoAdminRequired
+ * @NoSubAdminRequired
+ *
+ * @param array $documents
+ *
+ * @return DataResponse
+ */
+ public function documentsCache(array $documents): DataResponse {
+ try {
+ $cached = [];
+ foreach ($documents as $id) {
+ try {
+
+ $document = $this->documentService->cacheRemoteDocument($id);
+ $cached[] = $document;
+ } catch (Exception $e) {
+ }
+ }
+
+ return $this->success($cached);
+ } catch (Exception $e) {
+ return $this->fail($e);
+ }
+ }
+
}
+
diff --git a/lib/Controller/NavigationController.php b/lib/Controller/NavigationController.php
index 2801bcb3..864b9eb8 100644
--- a/lib/Controller/NavigationController.php
+++ b/lib/Controller/NavigationController.php
@@ -33,16 +33,21 @@ namespace OCA\Social\Controller;
use daita\MySmallPhpTools\Traits\TArrayTools;
use daita\MySmallPhpTools\Traits\Nextcloud\TNCDataResponse;
use Exception;
+use OC\Files\Node\File;
+use OC\Files\SimpleFS\SimpleFile;
use OC\User\NoUserException;
use OCA\Social\AppInfo\Application;
use OCA\Social\Exceptions\AccountAlreadyExistsException;
use OCA\Social\Exceptions\SocialAppConfigException;
+use OCA\Social\Service\ActivityPub\DocumentService;
use OCA\Social\Service\ActorService;
use OCA\Social\Service\ConfigService;
use OCA\Social\Service\MiscService;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\DataResponse;
+use OCP\AppFramework\Http\FileDisplayResponse;
use OCP\AppFramework\Http\RedirectResponse;
+use OCP\AppFramework\Http\Response;
use OCP\AppFramework\Http\Template\PublicTemplateResponse;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\IConfig;
@@ -69,6 +74,8 @@ class NavigationController extends Controller {
/** @var ActorService */
private $actorService;
+ private $documentService;
+
/** @var ConfigService */
private $configService;
@@ -86,14 +93,15 @@ class NavigationController extends Controller {
* @param IConfig $config
* @param IURLGenerator $urlGenerator
* @param ActorService $actorService
+ * @param DocumentService $documentService
* @param ConfigService $configService
* @param MiscService $miscService
* @param IL10N $l10n
*/
public function __construct(
IRequest $request, $userId, IConfig $config, IURLGenerator $urlGenerator,
- ActorService $actorService, ConfigService $configService, MiscService $miscService,
- IL10N $l10n
+ ActorService $actorService, DocumentService $documentService, ConfigService $configService,
+ MiscService $miscService, IL10N $l10n
) {
parent::__construct(Application::APP_NAME, $request);
@@ -102,6 +110,7 @@ class NavigationController extends Controller {
$this->urlGenerator = $urlGenerator;
$this->actorService = $actorService;
+ $this->documentService = $documentService;
$this->configService = $configService;
$this->miscService = $miscService;
$this->l10n = $l10n;
@@ -131,13 +140,18 @@ class NavigationController extends Controller {
$data['serverData']['cloudAddress'] = $this->configService->getCloudAddress();
} catch (SocialAppConfigException $e) {
$data['serverData']['setup'] = true;
- $data['serverData']['isAdmin'] = \OC::$server->getGroupManager()->isAdmin($this->userId);
+ $data['serverData']['isAdmin'] = \OC::$server->getGroupManager()
+ ->isAdmin($this->userId);
if ($data['serverData']['isAdmin']) {
$cloudAddress = $this->request->getParam('cloudAddress');
if ($cloudAddress !== null) {
$this->configService->setCloudAddress($cloudAddress);
} else {
- $data['serverData']['cliUrl'] = $this->config->getSystemValue('overwrite.cli.url', \OC::$server->getURLGenerator()->getBaseUrl());
+ $data['serverData']['cliUrl'] = $this->config->getSystemValue(
+ 'overwrite.cli.url', \OC::$server->getURLGenerator()
+ ->getBaseUrl()
+ );
+
return new TemplateResponse(Application::APP_NAME, 'main', $data);
}
}
@@ -154,8 +168,6 @@ class NavigationController extends Controller {
}
-
-
/**
* Display the navigation page of the Social app.
*
@@ -239,7 +251,6 @@ class NavigationController extends Controller {
}
-
/**
*
* // TODO: Delete the NoCSRF check
@@ -250,11 +261,14 @@ class NavigationController extends Controller {
*
* @param string $id
*
- * @return DataResponse
+ * @return Response
*/
- public function documentsGet(string $id): DataResponse {
+ public function documentGet(string $id): Response {
+
try {
- return $this->success([$id]);
+ $file = $this->documentService->getFromCache($id);
+
+ return new FileDisplayResponse($file);
} catch (Exception $e) {
return $this->fail($e);
}
@@ -272,14 +286,18 @@ class NavigationController extends Controller {
*
* @param string $id
*
- * @return DataResponse
+ * @return Response
*/
- public function documentsGetPublic(string $id): DataResponse {
+ public function documentGetPublic(string $id): Response {
+
try {
- return $this->success([$id]);
+ $file = $this->documentService->getFromCache($id, true);
+
+ return new FileDisplayResponse($file);
} catch (Exception $e) {
return $this->fail($e);
}
}
}
+