Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add S3 uploader #244

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
suflors marked this conversation as resolved.
Show resolved Hide resolved
if (string.IsNullOrEmpty(url))
{
// Fetch the bucket region
var regionResponse = _client.GetBucketLocationAsync(new GetBucketLocationRequest
suflors marked this conversation as resolved.
Show resolved Hide resolved
{
BucketName = _config.BucketName
}).GetAwaiter().GetResult();
suflors marked this conversation as resolved.
Show resolved Hide resolved

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;
suflors marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
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"))
suflors marked this conversation as resolved.
Show resolved Hide resolved
{
labelImgurClientId.Visible = false;
textBoxImgurClientId.Visible = false;
buttonS3Settings.Visible = true;
}
}

Expand Down