mirror of
https://github.com/ShareX/ShareX.git
synced 2024-07-02 21:20:28 +12:00
Removed Dropbox shortened link option because it is not exists in API v2, added direct link option as checkbox
This commit is contained in:
parent
57d7b57ce4
commit
fb12be55ac
|
@ -37,7 +37,7 @@ public class AmazonS3Settings
|
||||||
public string CustomDomain { get; set; }
|
public string CustomDomain { get; set; }
|
||||||
public bool UseReducedRedundancyStorage { get; set; }
|
public bool UseReducedRedundancyStorage { get; set; }
|
||||||
|
|
||||||
// For backward compatibility
|
// TEMP: For backward compatibility
|
||||||
public string Endpoint { get; set; }
|
public string Endpoint { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -52,13 +52,14 @@ public override GenericUploader CreateUploader(UploadersConfig config, TaskRefer
|
||||||
{
|
{
|
||||||
UploadPath = NameParser.Parse(NameParserType.URL, Dropbox.VerifyPath(config.DropboxUploadPath)),
|
UploadPath = NameParser.Parse(NameParserType.URL, Dropbox.VerifyPath(config.DropboxUploadPath)),
|
||||||
AutoCreateShareableLink = config.DropboxAutoCreateShareableLink,
|
AutoCreateShareableLink = config.DropboxAutoCreateShareableLink,
|
||||||
ShareURLType = config.DropboxURLType
|
UseDirectLink = config.DropboxUseDirectLink
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public override TabPage GetUploadersConfigTabPage(UploadersConfigForm form) => form.tpDropbox;
|
public override TabPage GetUploadersConfigTabPage(UploadersConfigForm form) => form.tpDropbox;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TEMP: For backward compatibility
|
||||||
public enum DropboxURLType
|
public enum DropboxURLType
|
||||||
{
|
{
|
||||||
Default,
|
Default,
|
||||||
|
@ -68,11 +69,6 @@ public enum DropboxURLType
|
||||||
|
|
||||||
public sealed class Dropbox : FileUploader, IOAuth2Basic
|
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 APIVersion = "2";
|
||||||
|
|
||||||
private const string URLWEB = "https://www.dropbox.com";
|
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 URLCreateFolder = URLAPI + "/files/create_folder";
|
||||||
private const string URLDelete = URLAPI + "/files/delete";
|
private const string URLDelete = URLAPI + "/files/delete";
|
||||||
private const string URLMove = URLAPI + "/files/move";
|
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 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)
|
public Dropbox(OAuth2Info oauth)
|
||||||
{
|
{
|
||||||
|
@ -105,7 +105,7 @@ public Dropbox(OAuth2Info oauth)
|
||||||
|
|
||||||
public override UploadResult Upload(Stream stream, string fileName)
|
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()
|
public string GetAuthorizationURL()
|
||||||
|
@ -204,7 +204,7 @@ public bool DownloadFile(string path, Stream downloadStream)
|
||||||
return false;
|
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)
|
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);
|
DropboxMetadata metadata = JsonConvert.DeserializeObject<DropboxMetadata>(ur.Response);
|
||||||
|
|
||||||
if (metadata != null && createShareableURL)
|
if (metadata != null && createShareableLink)
|
||||||
{
|
{
|
||||||
AllowReportProgress = false;
|
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);
|
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))
|
if (!string.IsNullOrEmpty(path) && OAuth2Info.CheckOAuth(AuthInfo))
|
||||||
{
|
{
|
||||||
|
@ -293,7 +293,7 @@ public string CreateShareableLink(string path, DropboxURLType urlType)
|
||||||
{
|
{
|
||||||
DropboxLinkMetadata linkMetadata = JsonConvert.DeserializeObject<DropboxLinkMetadata>(response);
|
DropboxLinkMetadata linkMetadata = JsonConvert.DeserializeObject<DropboxLinkMetadata>(response);
|
||||||
|
|
||||||
if (urlType == DropboxURLType.Direct)
|
if (directLink)
|
||||||
{
|
{
|
||||||
return GetDirectShareableURL(linkMetadata.url);
|
return GetDirectShareableURL(linkMetadata.url);
|
||||||
}
|
}
|
||||||
|
@ -307,35 +307,6 @@ public string CreateShareableLink(string path, DropboxURLType urlType)
|
||||||
return null;
|
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)
|
public DropboxMetadata Copy(string fromPath, string toPath)
|
||||||
{
|
{
|
||||||
DropboxMetadata metadata = null;
|
DropboxMetadata metadata = null;
|
||||||
|
@ -563,14 +534,4 @@ public class DropboxLinkMetadataTeamInfo
|
||||||
public string id { get; set; }
|
public string id { get; set; }
|
||||||
public string name { 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
|
|
||||||
}
|
}
|
|
@ -181,7 +181,6 @@ private void InitializeComponent()
|
||||||
this.ucFTPAccounts = new ShareX.UploadersLib.AccountsControl();
|
this.ucFTPAccounts = new ShareX.UploadersLib.AccountsControl();
|
||||||
this.tpDropbox = new System.Windows.Forms.TabPage();
|
this.tpDropbox = new System.Windows.Forms.TabPage();
|
||||||
this.oauth2Dropbox = new ShareX.UploadersLib.OAuthControl();
|
this.oauth2Dropbox = new ShareX.UploadersLib.OAuthControl();
|
||||||
this.cbDropboxURLType = new System.Windows.Forms.ComboBox();
|
|
||||||
this.cbDropboxAutoCreateShareableLink = new System.Windows.Forms.CheckBox();
|
this.cbDropboxAutoCreateShareableLink = new System.Windows.Forms.CheckBox();
|
||||||
this.pbDropboxLogo = new System.Windows.Forms.PictureBox();
|
this.pbDropboxLogo = new System.Windows.Forms.PictureBox();
|
||||||
this.lblDropboxPath = new System.Windows.Forms.Label();
|
this.lblDropboxPath = new System.Windows.Forms.Label();
|
||||||
|
@ -598,6 +597,7 @@ private void InitializeComponent()
|
||||||
this.ttlvMain = new ShareX.HelpersLib.TabToListView();
|
this.ttlvMain = new ShareX.HelpersLib.TabToListView();
|
||||||
this.actRapidShareAccountType = new ShareX.UploadersLib.AccountTypeControl();
|
this.actRapidShareAccountType = new ShareX.UploadersLib.AccountTypeControl();
|
||||||
this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
|
this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
|
||||||
|
this.cbDropboxUseDirectLink = new System.Windows.Forms.CheckBox();
|
||||||
this.tpOtherUploaders.SuspendLayout();
|
this.tpOtherUploaders.SuspendLayout();
|
||||||
this.tcOtherUploaders.SuspendLayout();
|
this.tcOtherUploaders.SuspendLayout();
|
||||||
this.tpTwitter.SuspendLayout();
|
this.tpTwitter.SuspendLayout();
|
||||||
|
@ -1818,8 +1818,8 @@ private void InitializeComponent()
|
||||||
//
|
//
|
||||||
// tpDropbox
|
// tpDropbox
|
||||||
//
|
//
|
||||||
|
this.tpDropbox.Controls.Add(this.cbDropboxUseDirectLink);
|
||||||
this.tpDropbox.Controls.Add(this.oauth2Dropbox);
|
this.tpDropbox.Controls.Add(this.oauth2Dropbox);
|
||||||
this.tpDropbox.Controls.Add(this.cbDropboxURLType);
|
|
||||||
this.tpDropbox.Controls.Add(this.cbDropboxAutoCreateShareableLink);
|
this.tpDropbox.Controls.Add(this.cbDropboxAutoCreateShareableLink);
|
||||||
this.tpDropbox.Controls.Add(this.pbDropboxLogo);
|
this.tpDropbox.Controls.Add(this.pbDropboxLogo);
|
||||||
this.tpDropbox.Controls.Add(this.lblDropboxPath);
|
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.CompleteButtonClicked += new ShareX.UploadersLib.OAuthControl.CompleteButtonClickedEventHandler(this.oauth2Dropbox_CompleteButtonClicked);
|
||||||
this.oauth2Dropbox.ClearButtonClicked += new ShareX.UploadersLib.OAuthControl.ClearButtonclickedEventHandler(this.oauth2Dropbox_ClearButtonClicked);
|
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
|
// cbDropboxAutoCreateShareableLink
|
||||||
//
|
//
|
||||||
resources.ApplyResources(this.cbDropboxAutoCreateShareableLink, "cbDropboxAutoCreateShareableLink");
|
resources.ApplyResources(this.cbDropboxAutoCreateShareableLink, "cbDropboxAutoCreateShareableLink");
|
||||||
|
@ -4820,6 +4812,13 @@ private void InitializeComponent()
|
||||||
this.actRapidShareAccountType.Name = "actRapidShareAccountType";
|
this.actRapidShareAccountType.Name = "actRapidShareAccountType";
|
||||||
this.actRapidShareAccountType.SelectedAccountType = ShareX.UploadersLib.AccountType.Anonymous;
|
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
|
// UploadersConfigForm
|
||||||
//
|
//
|
||||||
resources.ApplyResources(this, "$this");
|
resources.ApplyResources(this, "$this");
|
||||||
|
@ -5064,7 +5063,6 @@ private void InitializeComponent()
|
||||||
private System.Windows.Forms.Label lblYourlsAPIURL;
|
private System.Windows.Forms.Label lblYourlsAPIURL;
|
||||||
internal System.Windows.Forms.TabPage tpFileUploaders;
|
internal System.Windows.Forms.TabPage tpFileUploaders;
|
||||||
private System.Windows.Forms.TabControl tcFileUploaders;
|
private System.Windows.Forms.TabControl tcFileUploaders;
|
||||||
private System.Windows.Forms.ComboBox cbDropboxURLType;
|
|
||||||
private System.Windows.Forms.CheckBox cbDropboxAutoCreateShareableLink;
|
private System.Windows.Forms.CheckBox cbDropboxAutoCreateShareableLink;
|
||||||
private System.Windows.Forms.PictureBox pbDropboxLogo;
|
private System.Windows.Forms.PictureBox pbDropboxLogo;
|
||||||
private System.Windows.Forms.Label lblDropboxPath;
|
private System.Windows.Forms.Label lblDropboxPath;
|
||||||
|
@ -5559,5 +5557,6 @@ private void InitializeComponent()
|
||||||
private System.Windows.Forms.Label lblAmazonS3Identifier;
|
private System.Windows.Forms.Label lblAmazonS3Identifier;
|
||||||
private System.Windows.Forms.ToolTip toolTip1;
|
private System.Windows.Forms.ToolTip toolTip1;
|
||||||
private System.Windows.Forms.Label lblAmazonS3Hostname;
|
private System.Windows.Forms.Label lblAmazonS3Hostname;
|
||||||
|
private System.Windows.Forms.CheckBox cbDropboxUseDirectLink;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -350,9 +350,8 @@ public void LoadSettings()
|
||||||
|
|
||||||
txtDropboxPath.Text = Config.DropboxUploadPath;
|
txtDropboxPath.Text = Config.DropboxUploadPath;
|
||||||
cbDropboxAutoCreateShareableLink.Checked = Config.DropboxAutoCreateShareableLink;
|
cbDropboxAutoCreateShareableLink.Checked = Config.DropboxAutoCreateShareableLink;
|
||||||
cbDropboxURLType.Enabled = Config.DropboxAutoCreateShareableLink;
|
cbDropboxUseDirectLink.Enabled = Config.DropboxAutoCreateShareableLink;
|
||||||
cbDropboxURLType.Items.AddRange(Helpers.GetEnumNamesProper<DropboxURLType>());
|
cbDropboxUseDirectLink.Checked = Config.DropboxUseDirectLink;
|
||||||
cbDropboxURLType.SelectedIndex = (int)Config.DropboxURLType;
|
|
||||||
|
|
||||||
// OneDrive
|
// OneDrive
|
||||||
|
|
||||||
|
@ -1384,12 +1383,12 @@ private void txtDropboxPath_TextChanged(object sender, EventArgs e)
|
||||||
private void cbDropboxAutoCreateShareableLink_CheckedChanged(object sender, EventArgs e)
|
private void cbDropboxAutoCreateShareableLink_CheckedChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Config.DropboxAutoCreateShareableLink = cbDropboxAutoCreateShareableLink.Checked;
|
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
|
#endregion Dropbox
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -138,6 +138,9 @@ public class UploadersConfig : SettingsBase<UploadersConfig>
|
||||||
public OAuth2Info DropboxOAuth2Info = null;
|
public OAuth2Info DropboxOAuth2Info = null;
|
||||||
public string DropboxUploadPath = "ShareX/%y/%mo";
|
public string DropboxUploadPath = "ShareX/%y/%mo";
|
||||||
public bool DropboxAutoCreateShareableLink = true;
|
public bool DropboxAutoCreateShareableLink = true;
|
||||||
|
public bool DropboxUseDirectLink = false;
|
||||||
|
|
||||||
|
// TEMP: For backward compatibility
|
||||||
public DropboxURLType DropboxURLType = DropboxURLType.Default;
|
public DropboxURLType DropboxURLType = DropboxURLType.Default;
|
||||||
|
|
||||||
// FTP Server
|
// FTP Server
|
||||||
|
|
Loading…
Reference in a new issue