diff options
author | Julius Härtl <jus@bitgrid.net> | 2022-08-31 15:13:37 +0300 |
---|---|---|
committer | Julius Härtl <jus@bitgrid.net> | 2022-08-31 19:02:57 +0300 |
commit | 1ab66988bc6e5dca0b0b18ad9366880124fb28e1 (patch) | |
tree | ebf692156207f422bef27761a5f36c7a8d4b3cda | |
parent | 80f6a5834ab9e679c1a0df6a1aee82107ca5cfe3 (diff) |
Inject all dependnencies and increase cache timeout
Signed-off-by: Julius Härtl <jus@bitgrid.net>
4 files changed, 14 insertions, 7 deletions
diff --git a/core/Controller/ReferenceController.php b/core/Controller/ReferenceController.php index 93510a35f4a..2f6ef152d01 100644 --- a/core/Controller/ReferenceController.php +++ b/core/Controller/ReferenceController.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace OC\Core\Controller; +use OCP\AppFramework\Http\Response; use OCP\Collaboration\Reference\IReferenceManager; use OCP\AppFramework\Controller; use OCP\AppFramework\Http; @@ -48,7 +49,7 @@ class ReferenceController extends Controller { * @PublicPage * @NoCSRFRequired */ - public function preview(string $referenceId) { + public function preview(string $referenceId): Response { $reference = $this->referenceManager->getReferenceByCacheKey($referenceId); if ($reference === null) { return new DataResponse('', Http::STATUS_NOT_FOUND); diff --git a/lib/private/Collaboration/Reference/File/FileReferenceProvider.php b/lib/private/Collaboration/Reference/File/FileReferenceProvider.php index ecb7229e21e..39cdb62b09a 100644 --- a/lib/private/Collaboration/Reference/File/FileReferenceProvider.php +++ b/lib/private/Collaboration/Reference/File/FileReferenceProvider.php @@ -103,7 +103,7 @@ class FileReferenceProvider implements IReferenceProvider { /** * @throws NotFoundException */ - private function fetchReference(Reference $reference) { + private function fetchReference(Reference $reference): void { if ($this->userId === null) { throw new NotFoundException(); } diff --git a/lib/private/Collaboration/Reference/LinkReferenceProvider.php b/lib/private/Collaboration/Reference/LinkReferenceProvider.php index 0c2052b6d7d..36fbdd0b168 100644 --- a/lib/private/Collaboration/Reference/LinkReferenceProvider.php +++ b/lib/private/Collaboration/Reference/LinkReferenceProvider.php @@ -35,7 +35,9 @@ use OCP\Collaboration\Reference\IReferenceProvider; use OCP\Files\AppData\IAppDataFactory; use OCP\Files\NotFoundException; use OCP\Http\Client\IClientService; +use OCP\IRequest; use OCP\IURLGenerator; +use OCP\IUserSession; use Psr\Log\LoggerInterface; class LinkReferenceProvider implements IReferenceProvider { @@ -56,14 +58,18 @@ class LinkReferenceProvider implements IReferenceProvider { private IAppDataFactory $appDataFactory; private IURLGenerator $urlGenerator; private Limiter $limiter; + private IUserSession $userSession; + private IRequest $request; - public function __construct(IClientService $clientService, LoggerInterface $logger, SystemConfig $systemConfig, IAppDataFactory $appDataFactory, IURLGenerator $urlGenerator, Limiter $limiter) { + public function __construct(IClientService $clientService, LoggerInterface $logger, SystemConfig $systemConfig, IAppDataFactory $appDataFactory, IURLGenerator $urlGenerator, Limiter $limiter, IUserSession $userSession, IRequest $request) { $this->clientService = $clientService; $this->logger = $logger; $this->systemConfig = $systemConfig; $this->appDataFactory = $appDataFactory; $this->urlGenerator = $urlGenerator; $this->limiter = $limiter; + $this->userSession = $userSession; + $this->request = $request; } public function matchReference(string $referenceText): bool { @@ -84,13 +90,13 @@ class LinkReferenceProvider implements IReferenceProvider { return null; } - private function fetchReference(Reference $reference) { + private function fetchReference(Reference $reference): void { try { - $user = \OC::$server->getUserSession()->getUser(); + $user = $this->userSession->getUser(); if ($user) { $this->limiter->registerUserRequest('opengraph', 10, 120, $user); } else { - $this->limiter->registerAnonRequest('opengraph', 10, 120, \OC::$server->getRequest()->getRemoteAddress()); + $this->limiter->registerAnonRequest('opengraph', 10, 120, $this->request->getRemoteAddress()); } } catch (RateLimitExceededException $e) { return; diff --git a/lib/private/Collaboration/Reference/ReferenceManager.php b/lib/private/Collaboration/Reference/ReferenceManager.php index 562c9944651..304d693804f 100644 --- a/lib/private/Collaboration/Reference/ReferenceManager.php +++ b/lib/private/Collaboration/Reference/ReferenceManager.php @@ -37,7 +37,7 @@ use Psr\Log\LoggerInterface; use Throwable; class ReferenceManager implements IReferenceManager { - public const CACHE_TTL = 60; + public const CACHE_TTL = 3600; /** @var IReferenceProvider[]|null */ private ?array $providers = null; |