From 8d30d783fe8fe1aa7eaaff36f484a9660fd9c59d Mon Sep 17 00:00:00 2001 From: Noe Date: Wed, 12 Jun 2024 12:43:25 +0200 Subject: [PATCH] Updated History view in front-end --- csharp/App/SaliMax/src/Program.cs | 61 ++++++++++--------- csharp/App/SaliMax/src/S3Config.cs | 13 +--- .../content/dashboards/History/History.tsx | 20 +++--- 3 files changed, 44 insertions(+), 50 deletions(-) diff --git a/csharp/App/SaliMax/src/Program.cs b/csharp/App/SaliMax/src/Program.cs index e54ddb987..98af9657c 100644 --- a/csharp/App/SaliMax/src/Program.cs +++ b/csharp/App/SaliMax/src/Program.cs @@ -319,7 +319,7 @@ internal static class Program if (s3Bucket != null) RabbitMqManager.InformMiddleware(currentSalimaxState); } - else if (_subscribedToQueue && _heartBitInterval >= 15) + else if (_subscribedToQueue && _heartBitInterval >= 30) { //Send a heartbit to the backend Console.WriteLine("----------------------------------------Sending Heartbit----------------------------------------"); @@ -676,38 +676,39 @@ internal static class Program var s3Path = timeStamp.ToUnixTime() + ".csv"; var request = s3Config.CreatePutRequest(s3Path); - // This is temporary for Wittman, but now it's for all Instalattion + // This is temporary for Wittman, but now it's for all Installation await File.WriteAllTextAsync("/var/www/html/status.csv", csv.SplitLines().Where(l => !l.Contains("Secret")).JoinLines()); - var response = await request.PutAsync(new StringContent(csv)); + //Use this for no compression + //var response = await request.PutAsync(new StringContent(csv)); + + //Compress CSV data to a byte array + byte[] compressedBytes; + using (var memoryStream = new MemoryStream()) + { + //Create a zip directory and put the compressed file inside + using (var archive = new ZipArchive(memoryStream, ZipArchiveMode.Create, true)) + { + var entry = archive.CreateEntry("data.csv", CompressionLevel.SmallestSize); // Add CSV data to the ZIP archive + using (var entryStream = entry.Open()) + using (var writer = new StreamWriter(entryStream)) + { + writer.Write(csv); + } + } + + compressedBytes = memoryStream.ToArray(); + } + + // Encode the compressed byte array as a Base64 string + string base64String = Convert.ToBase64String(compressedBytes); + + // Create StringContent from Base64 string + var stringContent = new StringContent(base64String, Encoding.UTF8, "application/base64"); + + // Upload the compressed data (ZIP archive) to S3 + var response = await request.PutAsync(stringContent); - // Compress CSV data to a byte array - // byte[] compressedBytes; - // using (var memoryStream = new MemoryStream()) - // { - // //Create a zip directory and put the compressed file inside - // using (var archive = new ZipArchive(memoryStream, ZipArchiveMode.Create, true)) - // { - // var entry = archive.CreateEntry("data.csv", CompressionLevel.SmallestSize); // Add CSV data to the ZIP archive - // using (var entryStream = entry.Open()) - // using (var writer = new StreamWriter(entryStream)) - // { - // writer.Write(csv); - // } - // } - // - // compressedBytes = memoryStream.ToArray(); - // } - // - // // Encode the compressed byte array as a Base64 string - // string base64String = Convert.ToBase64String(compressedBytes); - // - // // Create StringContent from Base64 string - // var stringContent = new StringContent(base64String, Encoding.UTF8, "application/base64"); - // - // // Upload the compressed data (ZIP archive) to S3 - // var response = await request.PutAsync(stringContent); - // if (response.StatusCode != 200) { Console.WriteLine("ERROR: PUT"); diff --git a/csharp/App/SaliMax/src/S3Config.cs b/csharp/App/SaliMax/src/S3Config.cs index cbf2a92f9..48ff5c218 100644 --- a/csharp/App/SaliMax/src/S3Config.cs +++ b/csharp/App/SaliMax/src/S3Config.cs @@ -62,16 +62,9 @@ public record S3Config String contentType = "application/base64", String md5Hash = "") { - // StringToSign = HTTP-Verb + "\n" + - // Content-MD5 + "\n" + - // Content-Type + "\n" + - // Date + "\n" + - // CanonicalizedAmzHeaders + - // CanonicalizedResource; - - - //contentType = "application/base64; charset=utf-8"; - contentType = "text/plain; charset=utf-8"; + + contentType = "application/base64; charset=utf-8"; + //contentType = "text/plain; charset=utf-8"; var payload = $"{method}\n{md5Hash}\n{contentType}\n{date}\n/{bucket.Trim('/')}/{s3Path.Trim('/')}"; using var hmacSha1 = new HMACSHA1(UTF8.GetBytes(s3Secret)); diff --git a/typescript/frontend-marios2/src/content/dashboards/History/History.tsx b/typescript/frontend-marios2/src/content/dashboards/History/History.tsx index 86923395e..25de1adce 100644 --- a/typescript/frontend-marios2/src/content/dashboards/History/History.tsx +++ b/typescript/frontend-marios2/src/content/dashboards/History/History.tsx @@ -124,7 +124,7 @@ function HistoryOfActions(props: HistoryProps) {
+
{action.userName} @@ -203,7 +202,6 @@ function HistoryOfActions(props: HistoryProps) { fontWeight="bold" color="text.primary" gutterBottom - noWrap > {datePart} @@ -222,7 +220,6 @@ function HistoryOfActions(props: HistoryProps) { fontWeight="bold" color="text.primary" gutterBottom - noWrap > {timePart} @@ -230,7 +227,7 @@ function HistoryOfActions(props: HistoryProps) {
{action.description}
- +
); })}