-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #739 from Portkey-Wallet/release/1.23.1
Release/1.23.1
- Loading branch information
Showing
13 changed files
with
223 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/CAServer.Application.Contracts/Telegram/Dtos/RegisterTelegramBotDto.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System.ComponentModel.DataAnnotations; | ||
|
||
namespace CAServer.Telegram.Dtos; | ||
|
||
public class RegisterTelegramBotDto | ||
{ | ||
[Required] | ||
public string Secret { get; set; } | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
src/CAServer.Application.Contracts/Telegram/Dtos/TelegramAuthResponseDto.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace CAServer.Telegram.Dtos; | ||
|
||
public class TelegramAuthResponseDto<T> | ||
{ | ||
public bool Success { get; set; } | ||
public string Message { get; set; } | ||
public T Data { get; set; } | ||
} |
7 changes: 7 additions & 0 deletions
7
src/CAServer.Application.Contracts/Telegram/Dtos/TelegramBotInfoDto.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace CAServer.Telegram.Dtos; | ||
|
||
public class TelegramBotInfoDto | ||
{ | ||
public string BotId { get; set; } | ||
public string Secret { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
src/CAServer.Application.Contracts/Telegram/ITelegramRateLimiter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using System.Threading.Tasks; | ||
|
||
namespace CAServer.Telegram; | ||
|
||
public interface ITelegramRateLimiter | ||
{ | ||
Task RecordRequestAsync(); | ||
} |
15 changes: 15 additions & 0 deletions
15
src/CAServer.Application.Contracts/Telegram/Options/TelegramVerifierOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
namespace CAServer.Telegram.Options; | ||
|
||
public class TelegramVerifierOptions | ||
{ | ||
public string Url { get; set; } | ||
public int Timeout { get; set; } | ||
public int BotIdMinimumLength { get; set; } = 9; | ||
public int BotIdMaximumLength { get; set; } = 11; | ||
public int SecretMinimumLength { get; set; } = 34; | ||
public int SecretMaximumLength { get; set; } = 36; | ||
|
||
public int ReplenishmentPeriodSeconds { get; set; } = 60; | ||
public int TokenLimit { get; set; } = 5; | ||
public int TokensPerPeriod { get; set; } = 5; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System; | ||
using System.Threading.RateLimiting; | ||
using System.Threading.Tasks; | ||
using CAServer.Telegram.Options; | ||
using Microsoft.Extensions.Options; | ||
using Volo.Abp; | ||
using Volo.Abp.DependencyInjection; | ||
|
||
namespace CAServer.Telegram; | ||
|
||
public class TelegramRateLimiter : ITelegramRateLimiter, ISingletonDependency | ||
{ | ||
private readonly RateLimiter _rateLimiter; | ||
private readonly IOptionsMonitor<TelegramVerifierOptions> _optionsMonitor; | ||
|
||
public TelegramRateLimiter(IOptionsMonitor<TelegramVerifierOptions> optionsMonitor) | ||
{ | ||
_optionsMonitor = optionsMonitor; | ||
_rateLimiter = InitializeRateLimiter(); | ||
} | ||
|
||
private RateLimiter InitializeRateLimiter() | ||
{ | ||
return new TokenBucketRateLimiter(new TokenBucketRateLimiterOptions | ||
{ | ||
ReplenishmentPeriod = TimeSpan.FromSeconds(_optionsMonitor.CurrentValue.ReplenishmentPeriodSeconds), | ||
TokenLimit = _optionsMonitor.CurrentValue.TokenLimit, | ||
TokensPerPeriod = _optionsMonitor.CurrentValue.TokensPerPeriod | ||
}); | ||
} | ||
|
||
public Task RecordRequestAsync() | ||
{ | ||
var rateLimitLease = _rateLimiter.AttemptAcquire(1); | ||
if (!rateLimitLease.IsAcquired) | ||
{ | ||
throw new UserFriendlyException("The request exceeded the limit."); | ||
} | ||
return Task.CompletedTask; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters