From 133c3d37f77c93b181301c1e1748badce7b2101b Mon Sep 17 00:00:00 2001 From: GZTime Date: Mon, 1 Apr 2024 10:08:55 +0800 Subject: [PATCH] fix: response message & try get value --- src/GZCTF/Controllers/GameController.cs | 5 +---- src/GZCTF/Middlewares/RateLimiter.cs | 4 ++-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/GZCTF/Controllers/GameController.cs b/src/GZCTF/Controllers/GameController.cs index 5b88d3e6b..d581f1123 100644 --- a/src/GZCTF/Controllers/GameController.cs +++ b/src/GZCTF/Controllers/GameController.cs @@ -533,10 +533,7 @@ public async Task ChallengesWithTeamInfo([FromRoute] int id, Canc ScoreboardModel scoreboard = await gameRepository.GetScoreboard(context.Game!, token); - ScoreboardItem? boardItem = scoreboard.Items[context.Participation!.TeamId]; - - // make sure team info is not null - boardItem ??= new ScoreboardItem + ScoreboardItem boardItem = scoreboard.Items.TryGetValue(context.Participation!.TeamId, out var item) ? item : new() { Avatar = context.Participation!.Team.AvatarUrl, SolvedCount = 0, diff --git a/src/GZCTF/Middlewares/RateLimiter.cs b/src/GZCTF/Middlewares/RateLimiter.cs index 886a185a8..8cc72d255 100644 --- a/src/GZCTF/Middlewares/RateLimiter.cs +++ b/src/GZCTF/Middlewares/RateLimiter.cs @@ -82,7 +82,7 @@ public static void ConfigureRateLimiter(RateLimiterOptions options) context.HttpContext.Response.Headers.RetryAfter = afterSec.ToString(NumberFormatInfo.InvariantInfo); await context.HttpContext.Response.WriteAsJsonAsync( - new RequestResponse(localizer[nameof(Resources.Program.RateLimit_TooManyRequests)], + new RequestResponse(localizer[nameof(Resources.Program.RateLimit_TooManyRequests), afterSec], StatusCodes.Status429TooManyRequests ), cancellationToken); }; @@ -109,4 +109,4 @@ await context.HttpContext.Response.WriteAsJsonAsync( o.ReplenishmentPeriod = TimeSpan.FromSeconds(5); }); } -} \ No newline at end of file +}