Skip to content

Commit

Permalink
Added additional logic in GetBaseUrl() as what was present did not wo…
Browse files Browse the repository at this point in the history
…rk for me.
  • Loading branch information
suflors committed Aug 28, 2024
1 parent 0960dab commit cdd36fd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
20 changes: 17 additions & 3 deletions S3Client/S3Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ public async Task<S3Image> UploadImage(string hash, string dataB64)
Key = key,
Link = $"{GetBaseUrl()}/{key}",
};
}
else
} else
{
return null;
}
Expand Down Expand Up @@ -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;
}
}
}
15 changes: 6 additions & 9 deletions UI/SettingsWindow.cs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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;
}
}

Expand Down

0 comments on commit cdd36fd

Please sign in to comment.