From e05c36051bd43dccb591b692251e649fe999dc19 Mon Sep 17 00:00:00 2001 From: Noe Date: Mon, 1 Jul 2024 13:25:24 +0200 Subject: [PATCH] Updated pv view in frontend Updated CORS settings in createBucket function --- csharp/Lib/S3Utils/S3.cs | 69 ++++++++++++++++--- .../src/content/dashboards/PvView/PvView.tsx | 2 +- .../SalidomoInstallations/index.tsx | 8 +-- 3 files changed, 64 insertions(+), 15 deletions(-) diff --git a/csharp/Lib/S3Utils/S3.cs b/csharp/Lib/S3Utils/S3.cs index b8d2db382..0bd7eb99f 100644 --- a/csharp/Lib/S3Utils/S3.cs +++ b/csharp/Lib/S3Utils/S3.cs @@ -135,22 +135,71 @@ public static class S3 yield break; } } - - public static async Task PutBucket(this S3Region region, String name) + + public static async Task PutBucket(this S3Region region, string name) { var request = new PutBucketRequest { BucketName = name }; + var response = await region.GetS3Client().PutBucketAsync(request); - var response = await region - .GetS3Client() - .PutBucketAsync(request); - - return response.HttpStatusCode switch + if (response.HttpStatusCode == HttpStatusCode.OK) { - HttpStatusCode.OK => region.Bucket(name), - _ => null - }; + // Define CORS configuration rules + var corsConfiguration = new CORSConfiguration + { + Rules = new List + { + new CORSRule + { + AllowedHeaders = new List { "*" }, + AllowedMethods = new List { "GET", "HEAD" }, + AllowedOrigins = new List { "*" }, + ExposeHeaders = new List() // Empty list as per your settings + } + } + }; + + // Create a PutCORSConfigurationRequest + var putCorsRequest = new PutCORSConfigurationRequest + { + BucketName = name, + Configuration = corsConfiguration + }; + + // Set the CORS configuration for the bucket + var corsResponse = await region.GetS3Client().PutCORSConfigurationAsync(putCorsRequest); + + if (corsResponse.HttpStatusCode == HttpStatusCode.OK) + { + return region.Bucket(name); + } + else + { + Console.WriteLine("Failed to set CORS configuration."); + return null; + } + } + else + { + Console.WriteLine("Failed to create bucket."); + return null; + } } + // public static async Task PutBucket(this S3Region region, String name) + // { + // var request = new PutBucketRequest { BucketName = name }; + // + // var response = await region + // .GetS3Client() + // .PutBucketAsync(request); + // + // return response.HttpStatusCode switch + // { + // HttpStatusCode.OK => region.Bucket(name), + // _ => null + // }; + // } + public static async Task PutCors(this S3Bucket bucket, CORSConfiguration corsConfiguration) { diff --git a/typescript/frontend-marios2/src/content/dashboards/PvView/PvView.tsx b/typescript/frontend-marios2/src/content/dashboards/PvView/PvView.tsx index 548fb36fc..9f89d2003 100644 --- a/typescript/frontend-marios2/src/content/dashboards/PvView/PvView.tsx +++ b/typescript/frontend-marios2/src/content/dashboards/PvView/PvView.tsx @@ -96,7 +96,7 @@ function PvView(props: PvViewProps) { style={{ color: 'black', fontWeight: 'bold' }} mt={2} > - Battery service is not available at the moment + Pv view is not available at the moment Please wait or refresh the page diff --git a/typescript/frontend-marios2/src/content/dashboards/SalidomoInstallations/index.tsx b/typescript/frontend-marios2/src/content/dashboards/SalidomoInstallations/index.tsx index 8b15fc5bd..a35b1a2c4 100644 --- a/typescript/frontend-marios2/src/content/dashboards/SalidomoInstallations/index.tsx +++ b/typescript/frontend-marios2/src/content/dashboards/SalidomoInstallations/index.tsx @@ -92,10 +92,10 @@ function SalidomoInstallationTabs() { /> ) }, - // { - // value: 'overview', - // label: - // }, + { + value: 'overview', + label: + }, { value: 'log', label: