fix: update DomainRefreshController

This commit is contained in:
Maël Gangloff 2024-07-21 19:47:25 +02:00
parent 8a5f69c333
commit c48f37696c
No known key found for this signature in database
GPG Key ID: 11FDC81C24A7F629
3 changed files with 6 additions and 4 deletions

View File

@ -11,6 +11,7 @@ use DateTimeImmutable;
use Exception; use Exception;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpKernel\Exception\TooManyRequestsHttpException; use Symfony\Component\HttpKernel\Exception\TooManyRequestsHttpException;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Messenger\Exception\ExceptionInterface; use Symfony\Component\Messenger\Exception\ExceptionInterface;
use Symfony\Component\Messenger\MessageBusInterface; use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Component\RateLimiter\RateLimiterFactory; use Symfony\Component\RateLimiter\RateLimiterFactory;
@ -29,20 +30,21 @@ class DomainRefreshController extends AbstractController
* @throws Exception * @throws Exception
* @throws ExceptionInterface * @throws ExceptionInterface
*/ */
public function __invoke(string $ldhName,): ?Domain public function __invoke(string $ldhName, KernelInterface $kernel): ?Domain
{ {
/** @var Domain $domain */ /** @var Domain $domain */
$domain = $this->domainRepository->findOneBy(["ldhName" => $ldhName]); $domain = $this->domainRepository->findOneBy(["ldhName" => $ldhName]);
if ($domain !== null && $domain->getUpdatedAt()->diff(new DateTimeImmutable('now'))->days < 7) return $domain; if ($domain !== null && $domain->getUpdatedAt()->diff(new DateTimeImmutable('now'))->days < 7) return $domain;
if ($this->container->getParameter('kernel.environment') !== 'dev') { if (false === $kernel->isDebug()) {
$limiter = $this->authenticatedApiLimiter->create($this->getUser()->getUserIdentifier()); $limiter = $this->authenticatedApiLimiter->create($this->getUser()->getUserIdentifier());
if (false === $limiter->consume()->isAccepted()) throw new TooManyRequestsHttpException(); if (false === $limiter->consume()->isAccepted()) throw new TooManyRequestsHttpException();
} }
if ($domain === null) return $this->RDAPService->registerDomain($ldhName);
$updatedAt = $domain->getUpdatedAt(); $updatedAt = $domain->getUpdatedAt();
$domain = $this->RDAPService->registerDomain($ldhName); $domain = $this->RDAPService->registerDomain($ldhName);
/** @var WatchList $watchList */ /** @var WatchList $watchList */
foreach ($domain->getWatchLists()->getIterator() as $watchList) { foreach ($domain->getWatchLists()->getIterator() as $watchList) {
$this->bus->dispatch(new ProcessDomainTrigger($watchList->getToken(), $domain->getLdhName(), $updatedAt)); $this->bus->dispatch(new ProcessDomainTrigger($watchList->getToken(), $domain->getLdhName(), $updatedAt));

View File

@ -12,7 +12,7 @@ class HomeController extends AbstractController
#[Route(path: "/", name: "index")] #[Route(path: "/", name: "index")]
public function index(): Response public function index(): Response
{ {
return $this->render('base.html.twig'); return $this->render('index.html.twig');
} }