mirror of
https://github.com/maelgangloff/domain-watchdog.git
synced 2025-12-29 16:15:04 +00:00
feat: add rate limit : a user can update 25 domains per day
This commit is contained in:
@@ -8,12 +8,15 @@ use App\Service\RDAPService;
|
||||
use DateTimeImmutable;
|
||||
use Exception;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpKernel\Exception\TooManyRequestsHttpException;
|
||||
use Symfony\Component\RateLimiter\RateLimiterFactory;
|
||||
|
||||
class DomainRefreshController extends AbstractController
|
||||
{
|
||||
|
||||
public function __construct(private readonly DomainRepository $domainRepository,
|
||||
private readonly RDAPService $RDAPService)
|
||||
public function __construct(private readonly DomainRepository $domainRepository,
|
||||
private readonly RDAPService $RDAPService,
|
||||
private readonly RateLimiterFactory $authenticatedApiLimiter)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -27,7 +30,11 @@ class DomainRefreshController extends AbstractController
|
||||
if ($domain === null ||
|
||||
$domain->getUpdatedAt()->diff(new DateTimeImmutable('now'))->days >= 7) {
|
||||
|
||||
//TODO : Domain search rate limit here, before the RDAP request
|
||||
$limiter = $this->authenticatedApiLimiter->create($this->getUser()->getUserIdentifier());
|
||||
if (false === $limiter->consume()->isAccepted()) {
|
||||
throw new TooManyRequestsHttpException();
|
||||
}
|
||||
|
||||
$domain = $this->RDAPService->registerDomain($ldhName);
|
||||
}
|
||||
return $domain;
|
||||
|
||||
Reference in New Issue
Block a user