mirror of
https://github.com/ShareX/ShareX.git
synced 2024-07-04 22:21:23 +12:00
fixed #2805: If Dropbox shared link already exists then get URL of it
This commit is contained in:
parent
452a039392
commit
4d54841c73
|
@ -85,6 +85,7 @@ public sealed class Dropbox : FileUploader, IOAuth2Basic
|
|||
private const string URLUpload = URLContent + "/files/upload";
|
||||
private const string URLGetMetadata = URLAPI + "/files/get_metadata";
|
||||
private const string URLCreateSharedLink = URLAPI + "/sharing/create_shared_link_with_settings";
|
||||
private const string URLListSharedLinks = URLAPI + "/sharing/list_shared_links";
|
||||
private const string URLCopy = URLAPI + "/files/copy";
|
||||
private const string URLCreateFolder = URLAPI + "/files/create_folder";
|
||||
private const string URLDelete = URLAPI + "/files/delete";
|
||||
|
@ -296,10 +297,24 @@ public string CreateShareableLink(string path, bool directLink)
|
|||
|
||||
string response = SendRequest(HttpMethod.POST, URLCreateSharedLink, json, ContentTypeJSON, null, GetAuthHeaders());
|
||||
|
||||
DropboxLinkMetadata linkMetadata = null;
|
||||
|
||||
if (!string.IsNullOrEmpty(response))
|
||||
{
|
||||
DropboxLinkMetadata linkMetadata = JsonConvert.DeserializeObject<DropboxLinkMetadata>(response);
|
||||
linkMetadata = JsonConvert.DeserializeObject<DropboxLinkMetadata>(response);
|
||||
}
|
||||
else if (IsError && Errors[Errors.Count - 1].Contains("\"shared_link_already_exists\"")) // Ugly workaround
|
||||
{
|
||||
DropboxListSharedLinksResult result = ListSharedLinks(path, true);
|
||||
|
||||
if (result != null && result.links != null && result.links.Length > 0)
|
||||
{
|
||||
linkMetadata = result.links[0];
|
||||
}
|
||||
}
|
||||
|
||||
if (linkMetadata != null)
|
||||
{
|
||||
if (directLink)
|
||||
{
|
||||
return GetDirectShareableURL(linkMetadata.url);
|
||||
|
@ -314,6 +329,29 @@ public string CreateShareableLink(string path, bool directLink)
|
|||
return null;
|
||||
}
|
||||
|
||||
public DropboxListSharedLinksResult ListSharedLinks(string path, bool directOnly = false)
|
||||
{
|
||||
DropboxListSharedLinksResult result = null;
|
||||
|
||||
if (path != null && OAuth2Info.CheckOAuth(AuthInfo))
|
||||
{
|
||||
string json = JsonConvert.SerializeObject(new
|
||||
{
|
||||
path = VerifyPath(path),
|
||||
direct_only = directOnly
|
||||
});
|
||||
|
||||
string response = SendRequest(HttpMethod.POST, URLListSharedLinks, json, ContentTypeJSON, null, GetAuthHeaders());
|
||||
|
||||
if (!string.IsNullOrEmpty(response))
|
||||
{
|
||||
result = JsonConvert.DeserializeObject<DropboxListSharedLinksResult>(response);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public DropboxMetadata Copy(string fromPath, string toPath)
|
||||
{
|
||||
DropboxMetadata metadata = null;
|
||||
|
@ -541,4 +579,11 @@ public class DropboxLinkMetadataTeamInfo
|
|||
public string id { get; set; }
|
||||
public string name { get; set; }
|
||||
}
|
||||
|
||||
public class DropboxListSharedLinksResult
|
||||
{
|
||||
public DropboxLinkMetadata[] links { get; set; }
|
||||
public bool has_more { get; set; }
|
||||
public string cursor { get; set; }
|
||||
}
|
||||
}
|
|
@ -441,7 +441,7 @@ private void InitializeComponent()
|
|||
this.txtSulAPIKey = new System.Windows.Forms.TextBox();
|
||||
this.lblSulAPIKey = new System.Windows.Forms.Label();
|
||||
this.tpLithiio = new System.Windows.Forms.TabPage();
|
||||
this.btnLithiioLogin = new System.Windows.Forms.Button();
|
||||
this.btnLithiioFetchAPIKey = new System.Windows.Forms.Button();
|
||||
this.txtLithiioPassword = new System.Windows.Forms.TextBox();
|
||||
this.txtLithiioEmail = new System.Windows.Forms.TextBox();
|
||||
this.lblLithiioPassword = new System.Windows.Forms.Label();
|
||||
|
@ -3737,7 +3737,7 @@ private void InitializeComponent()
|
|||
//
|
||||
// tpLithiio
|
||||
//
|
||||
this.tpLithiio.Controls.Add(this.btnLithiioLogin);
|
||||
this.tpLithiio.Controls.Add(this.btnLithiioFetchAPIKey);
|
||||
this.tpLithiio.Controls.Add(this.txtLithiioPassword);
|
||||
this.tpLithiio.Controls.Add(this.txtLithiioEmail);
|
||||
this.tpLithiio.Controls.Add(this.lblLithiioPassword);
|
||||
|
@ -3749,12 +3749,12 @@ private void InitializeComponent()
|
|||
this.tpLithiio.Name = "tpLithiio";
|
||||
this.tpLithiio.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// btnLithiioLogin
|
||||
// btnLithiioFetchAPIKey
|
||||
//
|
||||
resources.ApplyResources(this.btnLithiioLogin, "btnLithiioLogin");
|
||||
this.btnLithiioLogin.Name = "btnLithiioLogin";
|
||||
this.btnLithiioLogin.UseVisualStyleBackColor = true;
|
||||
this.btnLithiioLogin.Click += new System.EventHandler(this.btnLithiioLogin_Click);
|
||||
resources.ApplyResources(this.btnLithiioFetchAPIKey, "btnLithiioFetchAPIKey");
|
||||
this.btnLithiioFetchAPIKey.Name = "btnLithiioFetchAPIKey";
|
||||
this.btnLithiioFetchAPIKey.UseVisualStyleBackColor = true;
|
||||
this.btnLithiioFetchAPIKey.Click += new System.EventHandler(this.btnLithiioLogin_Click);
|
||||
//
|
||||
// txtLithiioPassword
|
||||
//
|
||||
|
@ -5833,7 +5833,7 @@ private void InitializeComponent()
|
|||
private OAuthControl oauthFlickr;
|
||||
private System.Windows.Forms.CheckBox cbFlickrDirectLink;
|
||||
private System.Windows.Forms.Button btnSulGetAPIKey;
|
||||
private System.Windows.Forms.Button btnLithiioLogin;
|
||||
private System.Windows.Forms.Button btnLithiioFetchAPIKey;
|
||||
private System.Windows.Forms.TextBox txtLithiioPassword;
|
||||
private System.Windows.Forms.TextBox txtLithiioEmail;
|
||||
private System.Windows.Forms.Label lblLithiioPassword;
|
||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue