diff --git a/S3Client/S3Client.cs b/S3Client/S3Client.cs index 3afcee5..d58f5d1 100644 --- a/S3Client/S3Client.cs +++ b/S3Client/S3Client.cs @@ -77,8 +77,7 @@ public async Task UploadImage(string hash, string dataB64) Key = key, Link = $"{GetBaseUrl()}/{key}", }; - } - else + } else { return null; } @@ -112,7 +111,22 @@ public void Dispose() private string GetBaseUrl() { - return _config.CustomDomain ?? _config.Endpoint; + string url = _config.CustomDomain ?? _config.Endpoint; + + // I was considering removing the url setting above entirely, as it doesn't seem to work. But it may just be my problem, so if it fails, continue to setting it through getting the bucket + if (string.IsNullOrEmpty(url)) + { + // Fetch the bucket region + var regionResponse = _client.GetBucketLocationAsync(new GetBucketLocationRequest + { + BucketName = _config.BucketName + }).GetAwaiter().GetResult(); + + var region = regionResponse.Location?.Value ?? "us-east-1"; // Default to us-east-1 if region is null + url = $"https://{_config.BucketName}.s3.{region}.amazonaws.com"; + } + + return url; } } } diff --git a/UI/SettingsWindow.cs b/UI/SettingsWindow.cs index 1c0c564..dfde960 100644 --- a/UI/SettingsWindow.cs +++ b/UI/SettingsWindow.cs @@ -1,9 +1,7 @@ namespace MusicBeePlugin.UI { using System; - using System.Collections.Generic; using System.Drawing; - using System.Linq; using System.Windows.Forms; public partial class SettingsWindow : Form @@ -263,17 +261,16 @@ private void comboBoxArtworkUploader_SelectedIndexChanged(object sender, EventAr { ValidateInputs(); - if (comboBoxArtworkUploader.SelectedIndex == comboBoxArtworkUploader.FindString("Amazon S3")) - { - labelImgurClientId.Visible = false; - textBoxImgurClientId.Visible = false; - buttonS3Settings.Visible = true; - } - else + if (comboBoxArtworkUploader.SelectedIndex == comboBoxArtworkUploader.FindString("Imgur")) { labelImgurClientId.Visible = true; textBoxImgurClientId.Visible = true; buttonS3Settings.Visible = false; + } else if (comboBoxArtworkUploader.SelectedIndex == comboBoxArtworkUploader.FindString("Amazon S3")) + { + labelImgurClientId.Visible = false; + textBoxImgurClientId.Visible = false; + buttonS3Settings.Visible = true; } }