isRateLimited method

Future<bool> isRateLimited(
  1. String clientIp
)

Check if IP is rate limited

Implementation

Future<bool> isRateLimited(String clientIp) async {
  // First, it gonna check if the IP is blocked
  if (ipBlocker.isIpBlocked(clientIp)) {
    return true;
  }

  await File("$storagePath.country").writeAsString(countryBlocker.asJson());

  final now = DateTime.now();
  _requests[clientIp] ??= [];
  _requests[clientIp]!
      .removeWhere((time) => now.difference(time) > resetDuration);

  if (_requests[clientIp]!.length < maxRequests) {
    _requests[clientIp]!.add(now);
    _saveRequests();
    return false;
  }
  return true;
}