From 015cd5e5e61db2ed3c7c3da00b2357e5d4ab6dad Mon Sep 17 00:00:00 2001 From: Yinyin Liu Date: Sat, 28 Mar 2026 09:37:40 +0100 Subject: [PATCH] parsed based64 encoded daily sinexcel data --- .../Backend/Services/AggregatedJsonParser.cs | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/csharp/App/Backend/Services/AggregatedJsonParser.cs b/csharp/App/Backend/Services/AggregatedJsonParser.cs index bcc613c8d..d3f3573ad 100644 --- a/csharp/App/Backend/Services/AggregatedJsonParser.cs +++ b/csharp/App/Backend/Services/AggregatedJsonParser.cs @@ -1,3 +1,4 @@ +using System.Text; using System.Text.Json; using System.Text.Json.Serialization; using InnovEnergy.App.Backend.DataTypes; @@ -115,6 +116,7 @@ public static class AggregatedJsonParser /// Tries to read an aggregated JSON file from the installation's S3 bucket. /// S3 key: DDMMYYYY.json (directly in bucket root). /// Returns file content or null if not found / error. + /// Handles base64-encoded files (SinexcelCommunication uploads base64). /// public static async Task TryReadFromS3(Installation installation, String isoDate) { @@ -125,7 +127,8 @@ public static class AggregatedJsonParser var bucket = region.Bucket(installation.BucketName()); var s3Url = bucket.Path(fileName); - return await s3Url.GetObjectAsString(); + var raw = await s3Url.GetObjectAsString(); + return DecodeContent(raw); } catch (Exception ex) { @@ -134,6 +137,29 @@ public static class AggregatedJsonParser } } + /// + /// Decodes S3 file content. SinexcelCommunication devices upload DDMMYYYY.json + /// as base64-encoded NDJSON. If the content doesn't start with '{' it is + /// assumed to be base64 and decoded accordingly. + /// + private static String DecodeContent(String raw) + { + var trimmed = raw.Trim(); + if (trimmed.StartsWith('{')) + return raw; + + try + { + var decoded = Encoding.UTF8.GetString(Convert.FromBase64String(trimmed)); + Console.WriteLine("[AggregatedJsonParser] Decoded base64-encoded S3 content"); + return decoded; + } + catch + { + return raw; + } + } + // --- JSON DTOs --- private sealed class HourlyJsonDto