diff --git a/src/GZCTF/Controllers/GameController.cs b/src/GZCTF/Controllers/GameController.cs index f2f019d58..5493c3073 100644 --- a/src/GZCTF/Controllers/GameController.cs +++ b/src/GZCTF/Controllers/GameController.cs @@ -921,7 +921,8 @@ public async Task CreateContainer([FromRoute] int id, [FromRoute] if (DateTimeOffset.UtcNow - instance.LastContainerOperation < TimeSpan.FromSeconds(10)) return new JsonResult(new RequestResponse(localizer[nameof(Resources.Program.Game_OperationTooFrequent)], - StatusCodes.Status429TooManyRequests)) { StatusCode = StatusCodes.Status429TooManyRequests }; + StatusCodes.Status429TooManyRequests)) + { StatusCode = StatusCodes.Status429TooManyRequests }; if (instance.Container is not null) { @@ -934,15 +935,15 @@ public async Task CreateContainer([FromRoute] int id, [FromRoute] return await gameInstanceRepository.CreateContainer(instance, context.Participation!.Team, context.User!, context.Game!.ContainerCountLimit, token) switch - { - null or (TaskStatus.Failed, null) => BadRequest( - new RequestResponse(localizer[nameof(Resources.Program.Game_ContainerCreationFailed)])), - (TaskStatus.Denied, null) => BadRequest( - new RequestResponse(localizer[nameof(Resources.Program.Game_ContainerNumberLimitExceeded), - context.Game.ContainerCountLimit])), - (TaskStatus.Success, var x) => Ok(ContainerInfoModel.FromContainer(x!)), - _ => throw new UnreachableException() - }; + { + null or (TaskStatus.Failed, null) => BadRequest( + new RequestResponse(localizer[nameof(Resources.Program.Game_ContainerCreationFailed)])), + (TaskStatus.Denied, null) => BadRequest( + new RequestResponse(localizer[nameof(Resources.Program.Game_ContainerNumberLimitExceeded), + context.Game.ContainerCountLimit])), + (TaskStatus.Success, var x) => Ok(ContainerInfoModel.FromContainer(x!)), + _ => throw new UnreachableException() + }; } /// @@ -1035,7 +1036,8 @@ public async Task DeleteContainer([FromRoute] int id, [FromRoute] if (DateTimeOffset.UtcNow - instance.LastContainerOperation < TimeSpan.FromSeconds(10)) return new JsonResult(new RequestResponse(localizer[nameof(Resources.Program.Game_OperationTooFrequent)], - StatusCodes.Status429TooManyRequests)) { StatusCode = StatusCodes.Status429TooManyRequests }; + StatusCodes.Status429TooManyRequests)) + { StatusCode = StatusCodes.Status429TooManyRequests }; var destroyId = instance.Container.ContainerId; @@ -1068,7 +1070,8 @@ async Task GetContextInfo(int id, int challengeId = 0, bool withFla { ContextInfo res = new() { - User = await userManager.GetUserAsync(User), Game = await gameRepository.GetGameById(id, token) + User = await userManager.GetUserAsync(User), + Game = await gameRepository.GetGameById(id, token) }; if (res.Game is null) diff --git a/src/GZCTF/Controllers/ProxyController.cs b/src/GZCTF/Controllers/ProxyController.cs index 75aea665c..344d00d53 100644 --- a/src/GZCTF/Controllers/ProxyController.cs +++ b/src/GZCTF/Controllers/ProxyController.cs @@ -173,7 +173,8 @@ async Task DoContainerProxy(Guid id, IPEndPoint client, IPEndPoin TaskStatus.Failed, LogLevel.Debug); return new JsonResult(new RequestResponse( localizer[nameof(Resources.Program.Proxy_ContainerConnectionFailed), e.SocketErrorCode], - StatusCodes.Status418ImATeapot)) { StatusCode = StatusCodes.Status418ImATeapot }; + StatusCodes.Status418ImATeapot)) + { StatusCode = StatusCodes.Status418ImATeapot }; } using WebSocket ws = await HttpContext.WebSockets.AcceptWebSocketAsync(); diff --git a/src/GZCTF/Controllers/TeamController.cs b/src/GZCTF/Controllers/TeamController.cs index 011fe15c8..790a67d80 100644 --- a/src/GZCTF/Controllers/TeamController.cs +++ b/src/GZCTF/Controllers/TeamController.cs @@ -144,7 +144,8 @@ public async Task UpdateTeam([FromRoute] int id, [FromBody] TeamU if (team.CaptainId != user!.Id) return new JsonResult(new RequestResponse(localizer[nameof(Resources.Program.Auth_AccessForbidden)], - StatusCodes.Status403Forbidden)) { StatusCode = StatusCodes.Status403Forbidden }; + StatusCodes.Status403Forbidden)) + { StatusCode = StatusCodes.Status403Forbidden }; team.UpdateInfo(model); @@ -183,7 +184,8 @@ public async Task Transfer([FromRoute] int id, [FromBody] TeamTra if (team.CaptainId != user!.Id) return new JsonResult(new RequestResponse(localizer[nameof(Resources.Program.Auth_AccessForbidden)], - StatusCodes.Status403Forbidden)) { StatusCode = StatusCodes.Status403Forbidden }; + StatusCodes.Status403Forbidden)) + { StatusCode = StatusCodes.Status403Forbidden }; if (team.Locked && await teamRepository.AnyActiveGame(team, token)) return BadRequest(new RequestResponse(localizer[nameof(Resources.Program.Team_Locked)])); @@ -231,7 +233,8 @@ public async Task InviteCode([FromRoute] int id, CancellationToke if (team.CaptainId != user!.Id) return new JsonResult(new RequestResponse(localizer[nameof(Resources.Program.Auth_AccessForbidden)], - StatusCodes.Status403Forbidden)) { StatusCode = StatusCodes.Status403Forbidden }; + StatusCodes.Status403Forbidden)) + { StatusCode = StatusCodes.Status403Forbidden }; return Ok(team.InviteCode); } @@ -264,7 +267,8 @@ public async Task UpdateInviteToken([FromRoute] int id, Cancellat if (team.CaptainId != user!.Id) return new JsonResult(new RequestResponse(localizer[nameof(Resources.Program.Auth_AccessForbidden)], - StatusCodes.Status403Forbidden)) { StatusCode = StatusCodes.Status403Forbidden }; + StatusCodes.Status403Forbidden)) + { StatusCode = StatusCodes.Status403Forbidden }; team.UpdateInviteToken(); @@ -302,7 +306,8 @@ public async Task KickUser([FromRoute] int id, [FromRoute] Guid u if (team.CaptainId != user!.Id) return new JsonResult(new RequestResponse(localizer[nameof(Resources.Program.Auth_AccessForbidden)], - StatusCodes.Status403Forbidden)) { StatusCode = StatusCodes.Status403Forbidden }; + StatusCodes.Status403Forbidden)) + { StatusCode = StatusCodes.Status403Forbidden }; IDbContextTransaction trans = await teamRepository.BeginTransactionAsync(token); @@ -488,7 +493,8 @@ public async Task Avatar([FromRoute] int id, IFormFile file, Canc if (team.CaptainId != user!.Id) return new JsonResult(new RequestResponse(localizer[nameof(Resources.Program.Auth_AccessForbidden)], - StatusCodes.Status403Forbidden)) { StatusCode = StatusCodes.Status403Forbidden }; + StatusCodes.Status403Forbidden)) + { StatusCode = StatusCodes.Status403Forbidden }; if (file.Length == 0) return BadRequest(new RequestResponse(localizer[nameof(Resources.Program.File_SizeZero)])); @@ -540,7 +546,8 @@ public async Task DeleteTeam(int id, CancellationToken token) if (team.CaptainId != user!.Id) return new JsonResult(new RequestResponse(localizer[nameof(Resources.Program.Auth_AccessForbidden)], - StatusCodes.Status403Forbidden)) { StatusCode = StatusCodes.Status403Forbidden }; + StatusCodes.Status403Forbidden)) + { StatusCode = StatusCodes.Status403Forbidden }; if (team.Locked && await teamRepository.AnyActiveGame(team, token)) return BadRequest(new RequestResponse(localizer[nameof(Resources.Program.Team_Locked)])); diff --git a/src/GZCTF/Extensions/CaptchaExtension.cs b/src/GZCTF/Extensions/CaptchaExtension.cs index 32085c8ec..d8d9b09d2 100644 --- a/src/GZCTF/Extensions/CaptchaExtension.cs +++ b/src/GZCTF/Extensions/CaptchaExtension.cs @@ -84,7 +84,9 @@ public override async Task VerifyAsync(ModelWithCaptcha model, HttpContext TurnstileRequestModel req = new() { - Secret = Config.SecretKey, Response = model.Challenge, RemoteIp = ip.ToString() + Secret = Config.SecretKey, + Response = model.Challenge, + RemoteIp = ip.ToString() }; const string api = "https://challenges.cloudflare.com/turnstile/v0/siteverify"; diff --git a/src/GZCTF/Models/AppDbContext.cs b/src/GZCTF/Models/AppDbContext.cs index 562779bb1..fd9957732 100644 --- a/src/GZCTF/Models/AppDbContext.cs +++ b/src/GZCTF/Models/AppDbContext.cs @@ -317,7 +317,7 @@ protected override void OnModelCreating(ModelBuilder builder) entity.Navigation(e => e.LocalFile).AutoInclude(); }); - + builder.Entity(entity => { entity.Property(e => e.Values) @@ -332,7 +332,7 @@ protected override void OnModelCreating(ModelBuilder builder) .HasConversion(listConverter) .Metadata .SetValueComparer(listComparer); - + entity.HasOne(e => e.Team) .WithMany() .HasForeignKey(e => e.TeamId); diff --git a/src/GZCTF/Models/Data/Challenge.cs b/src/GZCTF/Models/Data/Challenge.cs index 235dfe148..0ca44c175 100644 --- a/src/GZCTF/Models/Data/Challenge.cs +++ b/src/GZCTF/Models/Data/Challenge.cs @@ -128,7 +128,7 @@ public class Challenge /// /// 题目对应的 Flag 列表 /// - public List Flags { get; set; } = new(); + public List Flags { get; set; } = []; /// /// 为参赛对象生成动态 Flag @@ -191,10 +191,7 @@ internal string GenerateTestFlag() if (FlagTemplate.Contains("[GUID]")) return FlagTemplate.Replace("[GUID]", Guid.NewGuid().ToString("D")); - if (FlagTemplate.StartsWith("[LEET]")) - return Codec.Leet.LeetFlag(FlagTemplate[6..]); - - return Codec.Leet.LeetFlag(FlagTemplate); + return Codec.Leet.LeetFlag(FlagTemplate.StartsWith("[LEET]") ? FlagTemplate[6..] : FlagTemplate); } #endregion diff --git a/src/GZCTF/Models/Data/ExerciseChallenge.cs b/src/GZCTF/Models/Data/ExerciseChallenge.cs index 8986e6564..f7a24bfbc 100644 --- a/src/GZCTF/Models/Data/ExerciseChallenge.cs +++ b/src/GZCTF/Models/Data/ExerciseChallenge.cs @@ -15,14 +15,14 @@ public class ExerciseChallenge : Challenge /// /// 练习题目附加标签 /// - public List? Tags { get; set; } = new(); + public List? Tags { get; set; } = []; #region Db Relationship /// /// 依赖的练习题目 /// - public List Dependencies { get; set; } = new(); + public List Dependencies { get; set; } = []; #endregion } \ No newline at end of file diff --git a/src/GZCTF/Models/Data/Game.cs b/src/GZCTF/Models/Data/Game.cs index 144c4504f..06d79c976 100644 --- a/src/GZCTF/Models/Data/Game.cs +++ b/src/GZCTF/Models/Data/Game.cs @@ -195,31 +195,31 @@ internal Game Update(GameInfoModel model) /// 比赛事件 /// [JsonIgnore] - public List GameEvents { get; set; } = new(); + public List GameEvents { get; set; } = []; /// /// 比赛通知 /// [JsonIgnore] - public List GameNotices { get; set; } = new(); + public List GameNotices { get; set; } = []; /// /// 比赛题目 /// [JsonIgnore] - public List Challenges { get; set; } = new(); + public List Challenges { get; set; } = []; /// /// 比赛提交 /// [JsonIgnore] - public List Submissions { get; set; } = new(); + public List Submissions { get; set; } = []; /// /// 比赛队伍参赛对象 /// [JsonIgnore] - public HashSet Participations { get; set; } = new(); + public HashSet Participations { get; set; } = []; /// /// 比赛队伍 diff --git a/src/GZCTF/Models/Data/GameChallenge.cs b/src/GZCTF/Models/Data/GameChallenge.cs index fe3c791da..dc578ba1e 100644 --- a/src/GZCTF/Models/Data/GameChallenge.cs +++ b/src/GZCTF/Models/Data/GameChallenge.cs @@ -72,17 +72,17 @@ internal void Update(ChallengeUpdateModel model) /// /// 提交 /// - public List Submissions { get; set; } = new(); + public List Submissions { get; set; } = []; /// /// 赛题实例 /// - public List Instances { get; set; } = new(); + public List Instances { get; set; } = []; /// /// 激活赛题的队伍 /// - public HashSet Teams { get; set; } = new(); + public HashSet Teams { get; set; } = []; /// /// 比赛 Id diff --git a/src/GZCTF/Models/Data/LocalFile.cs b/src/GZCTF/Models/Data/LocalFile.cs index 306bbc0ab..730381519 100644 --- a/src/GZCTF/Models/Data/LocalFile.cs +++ b/src/GZCTF/Models/Data/LocalFile.cs @@ -28,7 +28,7 @@ public class LocalFile /// 文件大小 /// [JsonIgnore] - public long FileSize { get; set; } = 0; + public long FileSize { get; set; } /// /// 文件名 diff --git a/src/GZCTF/Models/Data/Participation.cs b/src/GZCTF/Models/Data/Participation.cs index c76168a61..d60718db7 100644 --- a/src/GZCTF/Models/Data/Participation.cs +++ b/src/GZCTF/Models/Data/Participation.cs @@ -43,22 +43,22 @@ public class Participation /// /// 队伍参与的队员 /// - public HashSet Members { get; set; } = new(); + public HashSet Members { get; set; } = []; /// /// 队伍激活的题目 /// - public HashSet Challenges { get; set; } = new(); + public HashSet Challenges { get; set; } = []; /// /// 赛题实例 /// - public List Instances { get; set; } = new(); + public List Instances { get; set; } = []; /// /// 提交 /// - public List Submissions { get; set; } = new(); + public List Submissions { get; set; } = []; [Required] public int GameId { get; set; } diff --git a/src/GZCTF/Models/Data/Post.cs b/src/GZCTF/Models/Data/Post.cs index 7a6f67562..c1be4958a 100644 --- a/src/GZCTF/Models/Data/Post.cs +++ b/src/GZCTF/Models/Data/Post.cs @@ -38,7 +38,7 @@ public partial class Post /// /// 文章标签 /// - public List? Tags { get; set; } = new(); + public List? Tags { get; set; } = []; /// /// 作者信息 diff --git a/src/GZCTF/Models/Data/Team.cs b/src/GZCTF/Models/Data/Team.cs index 3dc7a91cd..77ecddf29 100644 --- a/src/GZCTF/Models/Data/Team.cs +++ b/src/GZCTF/Models/Data/Team.cs @@ -79,7 +79,7 @@ internal void UpdateInfo(AdminTeamModel model) /// /// 比赛参与对象 /// - public List Participations { get; set; } = new(); + public List Participations { get; set; } = []; /// /// 比赛对象 @@ -89,7 +89,7 @@ internal void UpdateInfo(AdminTeamModel model) /// /// 队员 /// - public HashSet Members { get; set; } = new(); + public HashSet Members { get; set; } = []; #endregion Db Relationship } \ No newline at end of file diff --git a/src/GZCTF/Models/Data/UserInfo.cs b/src/GZCTF/Models/Data/UserInfo.cs index 2b725cdae..2396d0ddf 100644 --- a/src/GZCTF/Models/Data/UserInfo.cs +++ b/src/GZCTF/Models/Data/UserInfo.cs @@ -125,13 +125,13 @@ internal void UpdateUserInfo(ProfileUpdateModel model) /// 个人提交记录 /// [MemoryPackIgnore] - public List Submissions { get; set; } = new(); + public List Submissions { get; set; } = []; /// /// 参与的队伍 /// [MemoryPackIgnore] - public List Teams { get; set; } = new(); + public List Teams { get; set; } = []; #endregion } \ No newline at end of file diff --git a/src/GZCTF/Models/Internal/CaptchaModel.cs b/src/GZCTF/Models/Internal/CaptchaModel.cs index b6fc00274..e5c83a5fd 100644 --- a/src/GZCTF/Models/Internal/CaptchaModel.cs +++ b/src/GZCTF/Models/Internal/CaptchaModel.cs @@ -1,5 +1,6 @@ using System.Text.Json.Serialization; +// ReSharper disable UnusedMember.Global // ReSharper disable ClassNeverInstantiated.Global namespace GZCTF.Models.Internal; @@ -19,7 +20,7 @@ public class RecaptchaResponseModel public string Action { get; set; } = string.Empty; [JsonPropertyName("error-codes")] - public List ErrorCodes { get; set; } = new(); + public List ErrorCodes { get; set; } = []; } /// @@ -59,5 +60,5 @@ public class TurnstileResponseModel public string Action { get; set; } = string.Empty; [JsonPropertyName("error-codes")] - public List ErrorCodes { get; set; } = new(); + public List ErrorCodes { get; set; } = []; } \ No newline at end of file diff --git a/src/GZCTF/Models/Internal/FormattableData.cs b/src/GZCTF/Models/Internal/FormattableData.cs index 32ec5572d..d05661db7 100644 --- a/src/GZCTF/Models/Internal/FormattableData.cs +++ b/src/GZCTF/Models/Internal/FormattableData.cs @@ -13,7 +13,7 @@ public abstract class FormattableData where T : Enum /// [Required] public T Type { get; set; } = default!; - + /// /// 格式化值列表 /// diff --git a/src/GZCTF/Models/Request/Account/AccountVerifyModel.cs b/src/GZCTF/Models/Request/Account/AccountVerifyModel.cs index 7bb3e2513..219e2cafd 100644 --- a/src/GZCTF/Models/Request/Account/AccountVerifyModel.cs +++ b/src/GZCTF/Models/Request/Account/AccountVerifyModel.cs @@ -10,12 +10,14 @@ public class AccountVerifyModel /// /// 邮箱接收到的Base64格式Token /// - [Required(ErrorMessage = "Token是必需的")] + [Required(ErrorMessageResourceName = nameof(Resources.Program.Model_TokenRequired), + ErrorMessageResourceType = typeof(Resources.Program))] public string? Token { get; set; } /// /// 用户邮箱的Base64格式 /// - [Required(ErrorMessage = "邮箱是必需的")] + [Required(ErrorMessageResourceName = nameof(Resources.Program.Model_EmailRequired), + ErrorMessageResourceType = typeof(Resources.Program))] public string? Email { get; set; } } \ No newline at end of file diff --git a/src/GZCTF/Models/Request/Edit/GameInfoModel.cs b/src/GZCTF/Models/Request/Edit/GameInfoModel.cs index 2b5be20c1..62f5c97db 100644 --- a/src/GZCTF/Models/Request/Edit/GameInfoModel.cs +++ b/src/GZCTF/Models/Request/Edit/GameInfoModel.cs @@ -43,7 +43,7 @@ public class GameInfoModel /// 是否需要提交 Writeup /// public bool WriteupRequired { get; set; } - + /// /// 比赛邀请码 /// diff --git a/src/GZCTF/Models/Request/Game/DetailedGameInfoModel.cs b/src/GZCTF/Models/Request/Game/DetailedGameInfoModel.cs index 684599f6d..8c6e6aed7 100644 --- a/src/GZCTF/Models/Request/Game/DetailedGameInfoModel.cs +++ b/src/GZCTF/Models/Request/Game/DetailedGameInfoModel.cs @@ -45,7 +45,7 @@ public class DetailedGameInfoModel /// 是否需要提交 Writeup /// public bool WriteupRequired { get; set; } - + /// /// 比赛头图 /// diff --git a/src/GZCTF/Models/Request/Game/GameDetailModel.cs b/src/GZCTF/Models/Request/Game/GameDetailModel.cs index 05ac1fc13..99c603246 100644 --- a/src/GZCTF/Models/Request/Game/GameDetailModel.cs +++ b/src/GZCTF/Models/Request/Game/GameDetailModel.cs @@ -27,7 +27,7 @@ public class GameDetailModel /// [Required] public bool WriteupRequired { get; set; } = false; - + /// /// Writeup 提交截止时间 /// diff --git a/src/GZCTF/Program.cs b/src/GZCTF/Program.cs index b43bacb83..3c9e89d9f 100644 --- a/src/GZCTF/Program.cs +++ b/src/GZCTF/Program.cs @@ -84,7 +84,8 @@ options.UseNpgsql(builder.Configuration.GetConnectionString("Database"), o => o.UseQuerySplittingBehavior(QuerySplittingBehavior.SplitQuery)); - if (!builder.Environment.IsDevelopment()) return; + if (!builder.Environment.IsDevelopment()) + return; options.EnableSensitiveDataLogging(); options.EnableDetailedErrors(); @@ -389,15 +390,17 @@ public static IActionResult InvalidModelStateHandler(ActionContext context) return new JsonResult( new RequestResponse(errors is [_, ..] ? errors - : StaticLocalizer[nameof(Resources.Program.Model_ValidationFailed)])) { StatusCode = 400 }; + : StaticLocalizer[nameof(Resources.Program.Model_ValidationFailed)])) + { StatusCode = 400 }; errors = (from val in context.ModelState.Values - where val.Errors.Count > 0 - select val.Errors.FirstOrDefault()?.ErrorMessage).FirstOrDefault(); + where val.Errors.Count > 0 + select val.Errors.FirstOrDefault()?.ErrorMessage).FirstOrDefault(); return new JsonResult(new RequestResponse(errors is [_, ..] ? errors - : StaticLocalizer[nameof(Resources.Program.Model_ValidationFailed)])) { StatusCode = 400 }; + : StaticLocalizer[nameof(Resources.Program.Model_ValidationFailed)])) + { StatusCode = 400 }; } } -} \ No newline at end of file +} diff --git a/src/GZCTF/Providers/EntityConfigurationProvider.cs b/src/GZCTF/Providers/EntityConfigurationProvider.cs index 35e51d7d5..046906260 100644 --- a/src/GZCTF/Providers/EntityConfigurationProvider.cs +++ b/src/GZCTF/Providers/EntityConfigurationProvider.cs @@ -92,7 +92,8 @@ public override void Load() AppDbContext context = CreateAppDbContext(); - if (!context.Database.IsInMemory() && context.Database.GetMigrations().Any()) context.Database.Migrate(); + if (!context.Database.IsInMemory() && context.Database.GetMigrations().Any()) + context.Database.Migrate(); context.Database.EnsureCreated(); diff --git a/src/GZCTF/Repositories/GameRepository.cs b/src/GZCTF/Repositories/GameRepository.cs index 675933dd6..cf0e4546a 100644 --- a/src/GZCTF/Repositories/GameRepository.cs +++ b/src/GZCTF/Repositories/GameRepository.cs @@ -342,7 +342,8 @@ static IEnumerable GenTimeLine(IEnumerable items) score += i.Score; return new TimeLine { - Score = score, Time = i.SubmitTimeUtc!.Value // 此处不为 null + Score = score, + Time = i.SubmitTimeUtc!.Value // 此处不为 null }; }); } diff --git a/src/GZCTF/Services/Container/Manager/DockerManager.cs b/src/GZCTF/Services/Container/Manager/DockerManager.cs index cb7e2e159..58a07e83e 100644 --- a/src/GZCTF/Services/Container/Manager/DockerManager.cs +++ b/src/GZCTF/Services/Container/Manager/DockerManager.cs @@ -159,7 +159,8 @@ await _client.Images.CreateImageAsync(new() { FromImage = config.Image }, _meta. container.Port = config.ExposedPort; container.IsProxy = !_meta.ExposePort; - if (!_meta.ExposePort) return container; + if (!_meta.ExposePort) + return container; var port = info.NetworkSettings.Ports .FirstOrDefault(p => diff --git a/src/GZCTF/Services/Container/Manager/KubernetesManager.cs b/src/GZCTF/Services/Container/Manager/KubernetesManager.cs index 353e40eae..cb8a40242 100644 --- a/src/GZCTF/Services/Container/Manager/KubernetesManager.cs +++ b/src/GZCTF/Services/Container/Manager/KubernetesManager.cs @@ -86,7 +86,8 @@ config.Flag is null }, Requests = new Dictionary { - ["cpu"] = new("10m"), ["memory"] = new("32Mi") + ["cpu"] = new("10m"), + ["memory"] = new("32Mi") } } } @@ -195,7 +196,8 @@ config.Flag is null container.Port = config.ExposedPort; container.IsProxy = !_meta.ExposePort; - if (!_meta.ExposePort) return container; + if (!_meta.ExposePort) + return container; container.PublicIP = _meta.PublicEntry; container.PublicPort = service.Spec.Ports[0].NodePort; diff --git a/src/GZCTF/Services/Container/Manager/SwarmManager.cs b/src/GZCTF/Services/Container/Manager/SwarmManager.cs index a4e5db538..e5b0ed7b8 100644 --- a/src/GZCTF/Services/Container/Manager/SwarmManager.cs +++ b/src/GZCTF/Services/Container/Manager/SwarmManager.cs @@ -73,7 +73,7 @@ public async Task DestroyContainerAsync(Models.Data.Container container, Cancell ServiceCreateParameters parameters = GetServiceCreateParameters(config); var retry = 0; ServiceCreateResponse? serviceRes; - CreateContainer: + CreateContainer: try { serviceRes = await _client.Swarm.CreateServiceAsync(parameters, token); @@ -159,7 +159,8 @@ ServiceCreateParameters GetServiceCreateParameters(ContainerConfig config) => Labels = new Dictionary { - ["TeamId"] = config.TeamId, ["UserId"] = config.UserId.ToString() + ["TeamId"] = config.TeamId, + ["UserId"] = config.UserId.ToString() }, Mode = new() { Replicated = new() { Replicas = 1 } }, TaskTemplate = new() @@ -189,7 +190,8 @@ config.Flag is null [ new() { - PublishMode = _meta.ExposePort ? "global" : "vip", TargetPort = (uint)config.ExposedPort + PublishMode = _meta.ExposePort ? "global" : "vip", + TargetPort = (uint)config.ExposedPort } ] } diff --git a/src/GZCTF/Services/Container/Provider/KubernetesProvider.cs b/src/GZCTF/Services/Container/Provider/KubernetesProvider.cs index aec6412e6..77f092131 100644 --- a/src/GZCTF/Services/Container/Provider/KubernetesProvider.cs +++ b/src/GZCTF/Services/Container/Provider/KubernetesProvider.cs @@ -3,7 +3,6 @@ using GZCTF.Services.Interface; using k8s; using k8s.Models; -using Microsoft.Extensions.Localization; using Microsoft.Extensions.Options; using static GZCTF.Program; @@ -33,10 +32,9 @@ public class KubernetesProvider : IContainerProvider _localizer; public KubernetesProvider(IOptions registry, IOptions options, - ILogger logger, IStringLocalizer localizer) + ILogger logger) { _kubernetesMetadata = new() { @@ -44,7 +42,6 @@ public KubernetesProvider(IOptions registry, IOptions registry, IOptions localizer) { readonly string[] _commonScoreboardHeader = [ - localizer[nameof(Resources.Program.Header_Ranking)], localizer[nameof(Resources.Program.Header_Team)], - localizer[nameof(Resources.Program.Header_Captain)], localizer[nameof(Resources.Program.Header_Member)], + localizer[nameof(Resources.Program.Header_Ranking)], + localizer[nameof(Resources.Program.Header_Team)], + localizer[nameof(Resources.Program.Header_Captain)], + localizer[nameof(Resources.Program.Header_Member)], localizer[nameof(Resources.Program.Header_StdNumber)], localizer[nameof(Resources.Program.Header_PhoneNumber)], localizer[nameof(Resources.Program.Header_SolvedNumber)], @@ -21,9 +23,12 @@ public class ExcelHelper(IStringLocalizer localizer) readonly string[] _commonSubmissionHeader = [ localizer[nameof(Resources.Program.Header_SubmitStatus)], - localizer[nameof(Resources.Program.Header_SubmitTime)], localizer[nameof(Resources.Program.Header_Team)], - localizer[nameof(Resources.Program.Header_User)], localizer[nameof(Resources.Program.Header_Challenge)], - localizer[nameof(Resources.Program.Header_SubmitContent)], localizer[nameof(Resources.Program.Header_Email)] + localizer[nameof(Resources.Program.Header_SubmitTime)], + localizer[nameof(Resources.Program.Header_Team)], + localizer[nameof(Resources.Program.Header_User)], + localizer[nameof(Resources.Program.Header_Challenge)], + localizer[nameof(Resources.Program.Header_SubmitContent)], + localizer[nameof(Resources.Program.Header_Email)] ]; public MemoryStream GetScoreboardExcel(ScoreboardModel scoreboard, Game game) @@ -123,13 +128,13 @@ int[] WriteBoardHeader(ISheet sheet, ICellStyle style, ScoreboardModel scoreboar } foreach (KeyValuePair> type in scoreboard.Challenges) - foreach (ChallengeInfo chall in type.Value) - { - ICell? cell = row.CreateCell(colIndex++); - cell.SetCellValue(chall.Title); - cell.CellStyle = style; - challIds.Add(chall.Id); - } + foreach (ChallengeInfo chall in type.Value) + { + ICell? cell = row.CreateCell(colIndex++); + cell.SetCellValue(chall.Title); + cell.CellStyle = style; + challIds.Add(chall.Id); + } return challIds.ToArray(); } diff --git a/src/GZCTF/Utils/Shared.cs b/src/GZCTF/Utils/Shared.cs index d11d89640..8ace2a32b 100644 --- a/src/GZCTF/Utils/Shared.cs +++ b/src/GZCTF/Utils/Shared.cs @@ -126,7 +126,9 @@ public class FileRecord internal static FileRecord FromFileInfo(FileInfo info) => new() { - FileName = info.Name, UpdateTime = info.LastWriteTimeUtc, Size = info.Length + FileName = info.Name, + UpdateTime = info.LastWriteTimeUtc, + Size = info.Length }; }