From 2cc2379e10f1f38e2b8b29930d34d40d97c5c284 Mon Sep 17 00:00:00 2001 From: whoswhip Date: Wed, 28 Jan 2026 08:53:32 -0500 Subject: [PATCH] refactor: make unnecessary asynchronous methods synchronous --- .../Controllers/PasteController.cs | 16 +++++++-------- SharpbinV3.Server/Services/PasteService.cs | 20 +++++++++++-------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/SharpbinV3.Server/Controllers/PasteController.cs b/SharpbinV3.Server/Controllers/PasteController.cs index 511bf5b..20bcd20 100644 --- a/SharpbinV3.Server/Controllers/PasteController.cs +++ b/SharpbinV3.Server/Controllers/PasteController.cs @@ -31,13 +31,13 @@ namespace SharpbinV3.Server.Controllers [EnableRateLimiting("Strict")] public async Task CreatePaste(string title = "", string syntax = "plaintext", int visibility = 0, long expiresAt = 0, string? token = null) { - if (!await _pasteService.ValidateExpiresAt(expiresAt)) + if (!_pasteService.ValidateExpiresAt(expiresAt)) return BadRequest(new { success = false, message = "Invalid expiration time." }); - if (!await _pasteService.ValidateVisibility(visibility)) + if (!_pasteService.ValidateVisibility(visibility)) return BadRequest(new { success = false, message = "Invalid visibility level. Must be between 0 and 2." }); - if (!await _pasteService.ValidateSyntax(syntax)) + if (!_pasteService.ValidateSyntax(syntax)) return BadRequest(new { success = false, message = "Invalid syntax." }); - if (!await _pasteService.ValidateTitle(title)) + if (!_pasteService.ValidateTitle(title)) return BadRequest(new { success = false, message = $"Invalid title. Must be less than {_pasteSettings.MaxTitleLength} characters." }); string content = await new StreamReader(Request.Body).ReadToEndAsync(); @@ -185,13 +185,13 @@ namespace SharpbinV3.Server.Controllers if (request.ExpiresAt.HasValue) paste.ExpiresAt = request.ExpiresAt.Value; - if (!await _pasteService.ValidateExpiresAt(paste.ExpiresAt)) + if (!_pasteService.ValidateExpiresAt(paste.ExpiresAt)) return BadRequest(new { success = false, message = "Invalid expiration time." }); - if (!await _pasteService.ValidateVisibility(paste.Visibility)) + if (!_pasteService.ValidateVisibility(paste.Visibility)) return BadRequest(new { success = false, message = "Invalid visibility level. Must be between 0 and 2." }); - if (!await _pasteService.ValidateSyntax(paste.Syntax ?? "plaintext")) + if (!_pasteService.ValidateSyntax(paste.Syntax ?? "plaintext")) return BadRequest(new { success = false, message = "Invalid syntax." }); - if (!await _pasteService.ValidateTitle(paste.Title ?? "")) + if (!_pasteService.ValidateTitle(paste.Title ?? "")) return BadRequest(new { success = false, message = $"Invalid title. Must be less than {_pasteSettings.MaxTitleLength} characters." }); var newPaste = await _pasteService.Edit(paste); diff --git a/SharpbinV3.Server/Services/PasteService.cs b/SharpbinV3.Server/Services/PasteService.cs index eb6929e..8e746b6 100644 --- a/SharpbinV3.Server/Services/PasteService.cs +++ b/SharpbinV3.Server/Services/PasteService.cs @@ -130,23 +130,27 @@ namespace SharpbinV3.Server.Services .ToListAsync(); } - public async Task ValidateSyntax(string syntax) + public bool ValidateSyntax(string syntax) { - return await Task.FromResult(_pasteSettings.ValidSyntaxLanguages.Contains(syntax)); + return _pasteSettings.ValidSyntaxLanguages.Contains(syntax); } - public async Task ValidateTitle(string title) + + public bool ValidateTitle(string title) { - return await Task.FromResult(title.Length <= _pasteSettings.MaxTitleLength); + return title.Length <= _pasteSettings.MaxTitleLength; } - public async Task ValidateVisibility(int visibility) + + public bool ValidateVisibility(int visibility) { - return await Task.FromResult(visibility >= 0 && visibility <= 2); + return visibility >= 0 && visibility <= 2; } - public async Task ValidateExpiresAt(long expiresAt) + + public bool ValidateExpiresAt(long expiresAt) { if (expiresAt == 0) return true; var currentTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(); - return await Task.FromResult(expiresAt > currentTime - 1000); + return expiresAt > currentTime - 1000; } } } +