diff --git a/Helpers/SimApiStorage.cs b/Helpers/SimApiStorage.cs index fa6ffdf..8719704 100644 --- a/Helpers/SimApiStorage.cs +++ b/Helpers/SimApiStorage.cs @@ -14,7 +14,9 @@ namespace SimApi.Helpers public MinioClient Client => Mc; private string ServeUrl { get; } + private string Bucket { get; } + private IHttpContextAccessor HttpContextAccessor { get; } public SimApiStorage(SimApiOptions apiOptions, IHttpContextAccessor httpContextAccessor) @@ -22,7 +24,7 @@ namespace SimApi.Helpers var options = apiOptions.SimApiStorageOptions; HttpContextAccessor = httpContextAccessor; var useSsl = false; - var endpoint = string.Empty; + string endpoint; if (options.Endpoint.StartsWith("http://")) { endpoint = options.Endpoint.Replace("http://", string.Empty); @@ -39,19 +41,19 @@ namespace SimApi.Helpers ServeUrl = options.ServeUrl; Bucket = options.Bucket; + Console.WriteLine($"{endpoint} == {options.AccessKey} == {options.SecretKey}"); + var mcb = new MinioClient().WithEndpoint(endpoint) + .WithCredentials(options.AccessKey, options.SecretKey); if (useSsl) { - Mc = new MinioClient(endpoint, options.AccessKey, options.SecretKey).WithSSL(); - } - else - { - Mc = new MinioClient(endpoint, options.AccessKey, options.SecretKey); + mcb = mcb.WithSSL(); } + Mc = mcb.Build(); - bool found = Mc.BucketExistsAsync(Bucket).Result; + bool found = Mc.BucketExistsAsync(new BucketExistsArgs().WithBucket(Bucket)).Result; if (!found) { - Mc.MakeBucketAsync(Bucket).Wait(); + Mc.MakeBucketAsync(new MakeBucketArgs().WithBucket(Bucket)).Wait(); } } @@ -59,7 +61,8 @@ namespace SimApi.Helpers { try { - return Mc.PresignedPutObjectAsync(Bucket, path, expire).Result; + return Mc.PresignedPutObjectAsync(new PresignedPutObjectArgs().WithBucket(Bucket) + .WithObject(path).WithExpiry(expire)).Result; } catch (MinioException e) { @@ -72,7 +75,8 @@ namespace SimApi.Helpers { try { - Mc.PutObjectAsync(Bucket, path, stream, stream.Length).Wait(); + Mc.PutObjectAsync(new PutObjectArgs().WithBucket(Bucket).WithObject(path).WithStreamData(stream)) + .Wait(); return null; } catch (MinioException e) @@ -84,8 +88,8 @@ namespace SimApi.Helpers public string FullUrl(string path) { - var httpRequest = HttpContextAccessor.HttpContext.Request; - var url = $"{httpRequest.Scheme}://{httpRequest.Host}"; + var httpRequest = HttpContextAccessor.HttpContext?.Request; + var url = $"{httpRequest?.Scheme}://{httpRequest?.Host}"; if (string.IsNullOrEmpty(path)) { return path; diff --git a/Logger/SimApiLoggerConfiguration.cs b/Logger/SimApiLoggerConfiguration.cs new file mode 100644 index 0000000..3fb6bb4 --- /dev/null +++ b/Logger/SimApiLoggerConfiguration.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using Microsoft.Extensions.Logging; + +namespace SimApi.Logger; + +public class SimApiLoggerConfiguration +{ + public int EventId { get; set; } + + public Dictionary LogLevels { get; set; } = new() + { + [LogLevel.Information] = ConsoleColor.Green + }; +} \ No newline at end of file diff --git a/Properties/launchSettings.json b/Properties/launchSettings.json index 5987041..9306811 100644 --- a/Properties/launchSettings.json +++ b/Properties/launchSettings.json @@ -4,7 +4,7 @@ "anonymousAuthentication": true }, "profiles": { - "YYApi": { + "SimApi": { "commandName": "Project", "launchBrowser": true, "environmentVariables": { diff --git a/SimApi.csproj b/SimApi.csproj index e3cee1a..e6f9eea 100644 --- a/SimApi.csproj +++ b/SimApi.csproj @@ -17,7 +17,6 @@ net6.0 - @@ -28,9 +27,9 @@ - - - + + +