Skip to content

Commit

Permalink
Inject all dependnencies and increase cache timeout
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Härtl <[email protected]>
  • Loading branch information
juliusknorr committed Aug 31, 2022
1 parent 80f6a58 commit 1ab6698
Showing 4 changed files with 14 additions and 7 deletions.
3 changes: 2 additions & 1 deletion core/Controller/ReferenceController.php
Original file line number Diff line number Diff line change
@@ -24,6 +24,7 @@

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 @@ public function __construct(string $appName, IRequest $request, IReferenceManage
* @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);
Original file line number Diff line number Diff line change
@@ -103,7 +103,7 @@ public function resolveReference(string $referenceText): ?IReference {
/**
* @throws NotFoundException
*/
private function fetchReference(Reference $reference) {
private function fetchReference(Reference $reference): void {
if ($this->userId === null) {
throw new NotFoundException();
}
14 changes: 10 additions & 4 deletions lib/private/Collaboration/Reference/LinkReferenceProvider.php
Original file line number Diff line number Diff line change
@@ -35,7 +35,9 @@
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 @@ public function resolveReference(string $referenceText): ?IReference {
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;
2 changes: 1 addition & 1 deletion lib/private/Collaboration/Reference/ReferenceManager.php
Original file line number Diff line number Diff line change
@@ -37,7 +37,7 @@
use Throwable;

class ReferenceManager implements IReferenceManager {
public const CACHE_TTL = 60;
public const CACHE_TTL = 3600;

/** @var IReferenceProvider[]|null */
private ?array $providers = null;

0 comments on commit 1ab6698

Please sign in to comment.