mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-04 04:06:05 +13:00
Use Dropbox API v1 to get account info for public folder support
This commit is contained in:
parent
b82c386d59
commit
ebea75d076
3 changed files with 28 additions and 4 deletions
|
@ -97,6 +97,7 @@ 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 URLAccountInfo = "https://api.dropbox.com/1/account/info"; // API v1
|
||||||
|
|
||||||
private const string URLPublicDirect = "https://dl.dropboxusercontent.com/u";
|
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";
|
||||||
|
@ -203,6 +204,29 @@ public DropboxAccount GetCurrentAccount()
|
||||||
return account;
|
return account;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// API v1
|
||||||
|
public DropboxAccountInfo GetAccountInfo()
|
||||||
|
{
|
||||||
|
DropboxAccountInfo account = null;
|
||||||
|
|
||||||
|
if (OAuth2Info.CheckOAuth(AuthInfo))
|
||||||
|
{
|
||||||
|
string response = SendRequest(HttpMethod.GET, URLAccountInfo, headers: GetAuthHeaders());
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(response))
|
||||||
|
{
|
||||||
|
account = JsonConvert.DeserializeObject<DropboxAccountInfo>(response);
|
||||||
|
|
||||||
|
if (account != null)
|
||||||
|
{
|
||||||
|
AccountInfo = account;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return account;
|
||||||
|
}
|
||||||
|
|
||||||
public bool DownloadFile(string path, Stream downloadStream)
|
public bool DownloadFile(string path, Stream downloadStream)
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(path) && OAuth2Info.CheckOAuth(AuthInfo))
|
if (!string.IsNullOrEmpty(path) && OAuth2Info.CheckOAuth(AuthInfo))
|
||||||
|
|
|
@ -468,12 +468,12 @@ public void DropboxAuthComplete(string code)
|
||||||
|
|
||||||
if (result)
|
if (result)
|
||||||
{
|
{
|
||||||
Config.DropboxAccount = dropbox.GetCurrentAccount();
|
Config.DropboxAccountInfo = dropbox.GetAccountInfo();
|
||||||
UpdateDropboxStatus();
|
UpdateDropboxStatus();
|
||||||
|
|
||||||
oauth2Dropbox.Status = OAuthLoginStatus.LoginSuccessful;
|
oauth2Dropbox.Status = OAuthLoginStatus.LoginSuccessful;
|
||||||
|
|
||||||
if (Config.DropboxAccount != null)
|
if (Config.DropboxAccountInfo != null)
|
||||||
{
|
{
|
||||||
MessageBox.Show(Resources.UploadersConfigForm_Login_successful, "ShareX", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
MessageBox.Show(Resources.UploadersConfigForm_Login_successful, "ShareX", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
}
|
}
|
||||||
|
@ -492,7 +492,7 @@ public void DropboxAuthComplete(string code)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Config.DropboxAccount = null;
|
Config.DropboxAccountInfo = null;
|
||||||
UpdateDropboxStatus();
|
UpdateDropboxStatus();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|
|
@ -130,7 +130,7 @@ public class UploadersConfig : SettingsBase<UploadersConfig>
|
||||||
// Dropbox
|
// Dropbox
|
||||||
|
|
||||||
public OAuth2Info DropboxOAuth2Info = null;
|
public OAuth2Info DropboxOAuth2Info = null;
|
||||||
public DropboxAccount DropboxAccount = null;
|
//public DropboxAccount DropboxAccount = null;
|
||||||
public string DropboxUploadPath = "Public/ShareX/%y/%mo";
|
public string DropboxUploadPath = "Public/ShareX/%y/%mo";
|
||||||
public bool DropboxAutoCreateShareableLink = false;
|
public bool DropboxAutoCreateShareableLink = false;
|
||||||
public DropboxURLType DropboxURLType = DropboxURLType.Default;
|
public DropboxURLType DropboxURLType = DropboxURLType.Default;
|
||||||
|
|
Loading…
Reference in a new issue