Removed Dropbox shortened link option because it is not exists in API v2, added direct link option as checkbox

This commit is contained in:
Jaex 2017-03-19 09:52:03 +03:00
parent 57d7b57ce4
commit fb12be55ac
6 changed files with 7904 additions and 1936 deletions

View file

@ -37,7 +37,7 @@ public class AmazonS3Settings
public string CustomDomain { get; set; }
public bool UseReducedRedundancyStorage { get; set; }
// For backward compatibility
// TEMP: For backward compatibility
public string Endpoint { get; set; }
}
}

View file

@ -52,13 +52,14 @@ public override GenericUploader CreateUploader(UploadersConfig config, TaskRefer
{
UploadPath = NameParser.Parse(NameParserType.URL, Dropbox.VerifyPath(config.DropboxUploadPath)),
AutoCreateShareableLink = config.DropboxAutoCreateShareableLink,
ShareURLType = config.DropboxURLType
UseDirectLink = config.DropboxUseDirectLink
};
}
public override TabPage GetUploadersConfigTabPage(UploadersConfigForm form) => form.tpDropbox;
}
// TEMP: For backward compatibility
public enum DropboxURLType
{
Default,
@ -68,11 +69,6 @@ public enum DropboxURLType
public sealed class Dropbox : FileUploader, IOAuth2Basic
{
public OAuth2Info AuthInfo { get; set; }
public string UploadPath { get; set; }
public bool AutoCreateShareableLink { get; set; }
public DropboxURLType ShareURLType { get; set; }
private const string APIVersion = "2";
private const string URLWEB = "https://www.dropbox.com";
@ -93,10 +89,14 @@ public sealed class Dropbox : FileUploader, IOAuth2Basic
private const string URLCreateFolder = URLAPI + "/files/create_folder";
private const string URLDelete = URLAPI + "/files/delete";
private const string URLMove = URLAPI + "/files/move";
private const string URLShares = "https://api.dropbox.com/1/shares/dropbox"; // API v1
private const string URLPublicDirect = "https://dl.dropboxusercontent.com/u";
private const string URLShareDirect = "https://dl.dropboxusercontent.com/s";
private const string URLPublicDirect = "https://dl.dropboxusercontent.com/u";
public OAuth2Info AuthInfo { get; set; }
public string UploadPath { get; set; }
public bool AutoCreateShareableLink { get; set; }
public bool UseDirectLink { get; set; }
public Dropbox(OAuth2Info oauth)
{
@ -105,7 +105,7 @@ public Dropbox(OAuth2Info oauth)
public override UploadResult Upload(Stream stream, string fileName)
{
return UploadFile(stream, UploadPath, fileName, AutoCreateShareableLink, ShareURLType);
return UploadFile(stream, UploadPath, fileName, AutoCreateShareableLink, UseDirectLink);
}
public string GetAuthorizationURL()
@ -204,7 +204,7 @@ public bool DownloadFile(string path, Stream downloadStream)
return false;
}
public UploadResult UploadFile(Stream stream, string path, string filename, bool createShareableURL = false, DropboxURLType urlType = DropboxURLType.Default)
public UploadResult UploadFile(Stream stream, string path, string filename, bool createShareableLink = false, bool useDirectLink = false)
{
if (stream.Length > 150000000)
{
@ -231,11 +231,11 @@ public UploadResult UploadFile(Stream stream, string path, string filename, bool
{
DropboxMetadata metadata = JsonConvert.DeserializeObject<DropboxMetadata>(ur.Response);
if (metadata != null && createShareableURL)
if (metadata != null && createShareableLink)
{
AllowReportProgress = false;
ur.URL = CreateShareableLinkAPIv1(metadata.path_display, urlType);
ur.URL = CreateShareableLink(metadata.path_display, useDirectLink);
}
}
@ -274,7 +274,7 @@ public bool IsExists(string path)
return metadata != null && !metadata.tag.Equals("deleted", StringComparison.InvariantCultureIgnoreCase);
}
public string CreateShareableLink(string path, DropboxURLType urlType)
public string CreateShareableLink(string path, bool directLink)
{
if (!string.IsNullOrEmpty(path) && OAuth2Info.CheckOAuth(AuthInfo))
{
@ -293,7 +293,7 @@ public string CreateShareableLink(string path, DropboxURLType urlType)
{
DropboxLinkMetadata linkMetadata = JsonConvert.DeserializeObject<DropboxLinkMetadata>(response);
if (urlType == DropboxURLType.Direct)
if (directLink)
{
return GetDirectShareableURL(linkMetadata.url);
}
@ -307,35 +307,6 @@ public string CreateShareableLink(string path, DropboxURLType urlType)
return null;
}
public string CreateShareableLinkAPIv1(string path, DropboxURLType urlType)
{
if (!string.IsNullOrEmpty(path) && OAuth2Info.CheckOAuth(AuthInfo))
{
string url = URLHelpers.CombineURL(URLShares, URLHelpers.URLPathEncode(path));
Dictionary<string, string> args = new Dictionary<string, string>();
args.Add("short_url", urlType == DropboxURLType.Shortened ? "true" : "false");
string response = SendRequestMultiPart(url, args, GetAuthHeaders());
if (!string.IsNullOrEmpty(response))
{
DropboxShares shares = JsonConvert.DeserializeObject<DropboxShares>(response);
if (urlType == DropboxURLType.Direct)
{
return GetDirectShareableURL(shares.URL);
}
else
{
return shares.URL;
}
}
}
return null;
}
public DropboxMetadata Copy(string fromPath, string toPath)
{
DropboxMetadata metadata = null;
@ -563,14 +534,4 @@ public class DropboxLinkMetadataTeamInfo
public string id { get; set; }
public string name { get; set; }
}
#region API v1
public class DropboxShares
{
public string URL { get; set; }
public string Expires { get; set; }
}
#endregion API v1
}

View file

@ -181,7 +181,6 @@ private void InitializeComponent()
this.ucFTPAccounts = new ShareX.UploadersLib.AccountsControl();
this.tpDropbox = new System.Windows.Forms.TabPage();
this.oauth2Dropbox = new ShareX.UploadersLib.OAuthControl();
this.cbDropboxURLType = new System.Windows.Forms.ComboBox();
this.cbDropboxAutoCreateShareableLink = new System.Windows.Forms.CheckBox();
this.pbDropboxLogo = new System.Windows.Forms.PictureBox();
this.lblDropboxPath = new System.Windows.Forms.Label();
@ -598,6 +597,7 @@ private void InitializeComponent()
this.ttlvMain = new ShareX.HelpersLib.TabToListView();
this.actRapidShareAccountType = new ShareX.UploadersLib.AccountTypeControl();
this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
this.cbDropboxUseDirectLink = new System.Windows.Forms.CheckBox();
this.tpOtherUploaders.SuspendLayout();
this.tcOtherUploaders.SuspendLayout();
this.tpTwitter.SuspendLayout();
@ -1818,8 +1818,8 @@ private void InitializeComponent()
//
// tpDropbox
//
this.tpDropbox.Controls.Add(this.cbDropboxUseDirectLink);
this.tpDropbox.Controls.Add(this.oauth2Dropbox);
this.tpDropbox.Controls.Add(this.cbDropboxURLType);
this.tpDropbox.Controls.Add(this.cbDropboxAutoCreateShareableLink);
this.tpDropbox.Controls.Add(this.pbDropboxLogo);
this.tpDropbox.Controls.Add(this.lblDropboxPath);
@ -1837,14 +1837,6 @@ private void InitializeComponent()
this.oauth2Dropbox.CompleteButtonClicked += new ShareX.UploadersLib.OAuthControl.CompleteButtonClickedEventHandler(this.oauth2Dropbox_CompleteButtonClicked);
this.oauth2Dropbox.ClearButtonClicked += new ShareX.UploadersLib.OAuthControl.ClearButtonclickedEventHandler(this.oauth2Dropbox_ClearButtonClicked);
//
// cbDropboxURLType
//
this.cbDropboxURLType.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cbDropboxURLType.FormattingEnabled = true;
resources.ApplyResources(this.cbDropboxURLType, "cbDropboxURLType");
this.cbDropboxURLType.Name = "cbDropboxURLType";
this.cbDropboxURLType.SelectedIndexChanged += new System.EventHandler(this.cbDropboxURLType_SelectedIndexChanged);
//
// cbDropboxAutoCreateShareableLink
//
resources.ApplyResources(this.cbDropboxAutoCreateShareableLink, "cbDropboxAutoCreateShareableLink");
@ -4820,6 +4812,13 @@ private void InitializeComponent()
this.actRapidShareAccountType.Name = "actRapidShareAccountType";
this.actRapidShareAccountType.SelectedAccountType = ShareX.UploadersLib.AccountType.Anonymous;
//
// cbDropboxUseDirectLink
//
resources.ApplyResources(this.cbDropboxUseDirectLink, "cbDropboxUseDirectLink");
this.cbDropboxUseDirectLink.Name = "cbDropboxUseDirectLink";
this.cbDropboxUseDirectLink.UseVisualStyleBackColor = true;
this.cbDropboxUseDirectLink.CheckedChanged += new System.EventHandler(this.cbDropboxUseDirectLink_CheckedChanged);
//
// UploadersConfigForm
//
resources.ApplyResources(this, "$this");
@ -5064,7 +5063,6 @@ private void InitializeComponent()
private System.Windows.Forms.Label lblYourlsAPIURL;
internal System.Windows.Forms.TabPage tpFileUploaders;
private System.Windows.Forms.TabControl tcFileUploaders;
private System.Windows.Forms.ComboBox cbDropboxURLType;
private System.Windows.Forms.CheckBox cbDropboxAutoCreateShareableLink;
private System.Windows.Forms.PictureBox pbDropboxLogo;
private System.Windows.Forms.Label lblDropboxPath;
@ -5559,5 +5557,6 @@ private void InitializeComponent()
private System.Windows.Forms.Label lblAmazonS3Identifier;
private System.Windows.Forms.ToolTip toolTip1;
private System.Windows.Forms.Label lblAmazonS3Hostname;
private System.Windows.Forms.CheckBox cbDropboxUseDirectLink;
}
}

View file

@ -350,9 +350,8 @@ public void LoadSettings()
txtDropboxPath.Text = Config.DropboxUploadPath;
cbDropboxAutoCreateShareableLink.Checked = Config.DropboxAutoCreateShareableLink;
cbDropboxURLType.Enabled = Config.DropboxAutoCreateShareableLink;
cbDropboxURLType.Items.AddRange(Helpers.GetEnumNamesProper<DropboxURLType>());
cbDropboxURLType.SelectedIndex = (int)Config.DropboxURLType;
cbDropboxUseDirectLink.Enabled = Config.DropboxAutoCreateShareableLink;
cbDropboxUseDirectLink.Checked = Config.DropboxUseDirectLink;
// OneDrive
@ -1384,12 +1383,12 @@ private void txtDropboxPath_TextChanged(object sender, EventArgs e)
private void cbDropboxAutoCreateShareableLink_CheckedChanged(object sender, EventArgs e)
{
Config.DropboxAutoCreateShareableLink = cbDropboxAutoCreateShareableLink.Checked;
cbDropboxURLType.Enabled = Config.DropboxAutoCreateShareableLink;
cbDropboxUseDirectLink.Enabled = Config.DropboxAutoCreateShareableLink;
}
private void cbDropboxURLType_SelectedIndexChanged(object sender, EventArgs e)
private void cbDropboxUseDirectLink_CheckedChanged(object sender, EventArgs e)
{
Config.DropboxURLType = (DropboxURLType)cbDropboxURLType.SelectedIndex;
Config.DropboxUseDirectLink = cbDropboxUseDirectLink.Checked;
}
#endregion Dropbox

File diff suppressed because it is too large Load diff

View file

@ -138,6 +138,9 @@ public class UploadersConfig : SettingsBase<UploadersConfig>
public OAuth2Info DropboxOAuth2Info = null;
public string DropboxUploadPath = "ShareX/%y/%mo";
public bool DropboxAutoCreateShareableLink = true;
public bool DropboxUseDirectLink = false;
// TEMP: For backward compatibility
public DropboxURLType DropboxURLType = DropboxURLType.Default;
// FTP Server