parsed based64 encoded daily sinexcel data
This commit is contained in:
parent
812962ace0
commit
015cd5e5e6
|
|
@ -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).
|
||||
/// </summary>
|
||||
public static async Task<String?> 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
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
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
|
||||
|
|
|
|||
Loading…
Reference in New Issue