From 8253ca8cb96154f95854b1c1e5dd3ba53f41e5ec Mon Sep 17 00:00:00 2001 From: TheArcaneBrony Date: Mon, 14 Aug 2023 19:45:52 +0200 Subject: Code cleanup --- MxApiExtensions/Controllers/SyncController.cs | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) (limited to 'MxApiExtensions/Controllers/SyncController.cs') diff --git a/MxApiExtensions/Controllers/SyncController.cs b/MxApiExtensions/Controllers/SyncController.cs index e2b724f..d883377 100644 --- a/MxApiExtensions/Controllers/SyncController.cs +++ b/MxApiExtensions/Controllers/SyncController.cs @@ -38,7 +38,7 @@ public class SyncController : ControllerBase { // var resp = await hs._httpClient.GetAsync($"/_matrix/client/v3/sync?since={since}"); if (resp.Content is null) { - throw new MatrixException() { + throw new MatrixException { ErrorCode = "M_UNKNOWN", Error = "No content in response" }; @@ -49,7 +49,7 @@ public class SyncController : ControllerBase { await Response.StartAsync(); await using var stream = await resp.Content.ReadAsStreamAsync(); await using var target = System.IO.File.OpenWrite(cacheFile); - byte[] buffer = new byte[1]; + var buffer = new byte[1]; int bytesRead; while ((bytesRead = await stream.ReadAsync(buffer, 0, buffer.Length)) > 0) { @@ -78,17 +78,15 @@ public class SyncController : ControllerBase { } private async Task TrySendCached(string cacheFile) { - if (System.IO.File.Exists(cacheFile)) { - Response.StatusCode = 200; - Response.ContentType = "application/json"; - await Response.StartAsync(); - await using var stream = System.IO.File.OpenRead(cacheFile); - await stream.CopyToAsync(Response.Body); - await Response.CompleteAsync(); - return true; - } - - return false; + if (!System.IO.File.Exists(cacheFile)) return false; + + Response.StatusCode = 200; + Response.ContentType = "application/json"; + await Response.StartAsync(); + await using var stream = System.IO.File.OpenRead(cacheFile); + await stream.CopyToAsync(Response.Body); + await Response.CompleteAsync(); + return true; } #region Cache management @@ -98,7 +96,7 @@ public class SyncController : ControllerBase { Directory.CreateDirectory(cacheDir); var cacheFile = Path.Join(cacheDir, $"sync-{since}.json"); if (!Path.GetFullPath(cacheFile).StartsWith(Path.GetFullPath(cacheDir))) { - throw new MatrixException() { + throw new MatrixException { ErrorCode = "M_UNKNOWN", Error = "[Rory&::MxSyncCache] Cache file path is not in cache directory" }; -- cgit 1.5.1