mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-02 18:26:27 +13:00
Tweaked class name. Changed "Region" back to "Endpoint" in settings.
This commit is contained in:
parent
bf149e98f1
commit
524ecdc9b8
2 changed files with 24 additions and 15 deletions
|
@ -41,17 +41,20 @@ namespace ShareX.UploadersLib.FileUploaders
|
|||
{
|
||||
public sealed class AmazonS3 : FileUploader
|
||||
{
|
||||
private AmazonS3Settings s3Settings { get; set; }
|
||||
|
||||
private static readonly S3RegionEndpoint DreamObjectsEndpoint = new S3RegionEndpoint("DreamObjects", "dreamobjects", "objects.dreamhost.com");
|
||||
private AmazonS3Settings s3Settings { get; set; }
|
||||
|
||||
public static IEnumerable<S3RegionEndpoint> RegionEndpoints
|
||||
private static readonly AmazonS3Region UnknownEndpoint = new AmazonS3Region("Unknown Endpoint");
|
||||
private static readonly AmazonS3Region DreamObjectsEndpoint = new AmazonS3Region("DreamObjects", "dreamobjects", "objects.dreamhost.com");
|
||||
|
||||
public static IEnumerable<AmazonS3Region> RegionEndpoints
|
||||
{
|
||||
get
|
||||
{
|
||||
yield return UnknownEndpoint;
|
||||
|
||||
foreach (var endpoint in RegionEndpoint.EnumerableAllRegions)
|
||||
{
|
||||
yield return new S3RegionEndpoint(endpoint);
|
||||
yield return new AmazonS3Region(endpoint);
|
||||
}
|
||||
|
||||
yield return DreamObjectsEndpoint;
|
||||
|
@ -68,9 +71,9 @@ private string GetObjectStorageClass()
|
|||
return s3Settings.UseReducedRedundancyStorage ? "REDUCED_REDUNDANCY" : "STANDARD";
|
||||
}
|
||||
|
||||
public static S3RegionEndpoint GetCurrentRegion(AmazonS3Settings s3Settings)
|
||||
public static AmazonS3Region GetCurrentRegion(AmazonS3Settings s3Settings)
|
||||
{
|
||||
return RegionEndpoints.SingleOrDefault(r => r.Identifier == s3Settings.Region);
|
||||
return RegionEndpoints.SingleOrDefault(r => r.Identifier == s3Settings.Endpoint) ?? UnknownEndpoint;
|
||||
}
|
||||
|
||||
private string GetEndpoint()
|
||||
|
@ -131,7 +134,8 @@ public override UploadResult Upload(Stream stream, string fileName)
|
|||
{
|
||||
if (string.IsNullOrEmpty(s3Settings.AccessKeyID)) throw new Exception("'Access Key' must not be empty.");
|
||||
if (string.IsNullOrEmpty(s3Settings.SecretAccessKey)) throw new Exception("'Secret Access Key' must not be empty.");
|
||||
if (string.IsNullOrEmpty(s3Settings.Bucket)) throw new Exception("'Bucket' must not be empty.");
|
||||
if (string.IsNullOrEmpty(s3Settings.Bucket)) throw new Exception("'Bucket' must not be empty.");
|
||||
if (GetCurrentRegion(s3Settings) == UnknownEndpoint) throw new Exception("Please select an endpoint.");
|
||||
|
||||
var region = GetCurrentRegion(s3Settings);
|
||||
|
||||
|
@ -184,16 +188,21 @@ public override UploadResult Upload(Stream stream, string fileName)
|
|||
}
|
||||
}
|
||||
|
||||
public class S3RegionEndpoint
|
||||
{
|
||||
public S3RegionEndpoint(string name, string identifier, string hostname)
|
||||
public class AmazonS3Region
|
||||
{
|
||||
public AmazonS3Region(string name)
|
||||
{
|
||||
Name = name;
|
||||
}
|
||||
|
||||
public AmazonS3Region(string name, string identifier, string hostname)
|
||||
{
|
||||
Name = name;
|
||||
Identifier = identifier;
|
||||
Hostname = hostname;
|
||||
}
|
||||
|
||||
public S3RegionEndpoint(RegionEndpoint region)
|
||||
public AmazonS3Region(RegionEndpoint region)
|
||||
{
|
||||
Name = region.DisplayName;
|
||||
Identifier = region.SystemName;
|
||||
|
@ -211,7 +220,7 @@ public class AmazonS3Settings
|
|||
{
|
||||
public string AccessKeyID { get; set; }
|
||||
public string SecretAccessKey { get; set; }
|
||||
public string Region { get; set; }
|
||||
public string Endpoint { get; set; }
|
||||
public string Bucket { get; set; }
|
||||
public string ObjectPrefix { get; set; }
|
||||
public bool UseCustomCNAME { get; set; }
|
||||
|
|
|
@ -1786,10 +1786,10 @@ private void txtAmazonS3SecretKey_TextChanged(object sender, EventArgs e)
|
|||
|
||||
private void cbAmazonS3Endpoint_SelectionChangeCommitted(object sender, EventArgs e)
|
||||
{
|
||||
var region = cbAmazonS3Endpoint.SelectedItem as S3RegionEndpoint;
|
||||
var region = cbAmazonS3Endpoint.SelectedItem as AmazonS3Region;
|
||||
if (region != null)
|
||||
{
|
||||
Config.AmazonS3Settings.Region = region.Identifier;
|
||||
Config.AmazonS3Settings.Endpoint = region.Identifier;
|
||||
UpdateAmazonS3Status();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue