Use API v1 account info in Dropbox status label

This commit is contained in:
Jaex 2016-06-30 23:35:24 +03:00
parent bb9ac92e5b
commit 21fcf2d16d
4 changed files with 42 additions and 72 deletions

View file

@ -106,6 +106,18 @@ public Dropbox(OAuth2Info oauth)
AuthInfo = oauth; AuthInfo = oauth;
} }
public override UploadResult Upload(Stream stream, string fileName)
{
if (OAuth2Info.CheckOAuth(AuthInfo) && !AutoCreateShareableLink)
{
string url = GetPublicURL(URLHelpers.CombineURL(UploadPath, fileName));
OnEarlyURLCopyRequested(url);
}
return UploadFile(stream, UploadPath, fileName, AutoCreateShareableLink, ShareURLType);
}
public string GetAuthorizationURL() public string GetAuthorizationURL()
{ {
Dictionary<string, string> args = new Dictionary<string, string>(); Dictionary<string, string> args = new Dictionary<string, string>();
@ -146,7 +158,28 @@ private NameValueCollection GetAuthHeaders()
return headers; return headers;
} }
#region Dropbox accounts public static string VerifyPath(string path, string filename = null)
{
if (!string.IsNullOrEmpty(path))
{
path = path.Trim().Replace('\\', '/').Trim('/');
path = URLHelpers.AddSlash(path, SlashType.Prefix);
if (!string.IsNullOrEmpty(filename))
{
path = URLHelpers.CombineURL(path, filename);
}
return path;
}
if (!string.IsNullOrEmpty(filename))
{
return filename;
}
return "";
}
public DropboxAccount GetCurrentAccount() public DropboxAccount GetCurrentAccount()
{ {
@ -170,10 +203,6 @@ public DropboxAccount GetCurrentAccount()
return account; return account;
} }
#endregion Dropbox accounts
#region Files and metadata
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))
@ -284,7 +313,7 @@ public string CreateShareableLink(string path, DropboxURLType urlType)
} }
}); });
// TODO: args.Add("short_url", urlType == DropboxURLType.Shortened ? "true" : "false"); // TODO: Missing: args.Add("short_url", urlType == DropboxURLType.Shortened ? "true" : "false");
string response = SendRequestJSON(URLCreateSharedLink, json, GetAuthHeaders()); string response = SendRequestJSON(URLCreateSharedLink, json, GetAuthHeaders());
@ -316,10 +345,6 @@ public string CreateShareableLink(string path, DropboxURLType urlType)
return null; return null;
} }
#endregion Files and metadata
#region File operations
public DropboxMetadata Copy(string fromPath, string toPath) public DropboxMetadata Copy(string fromPath, string toPath)
{ {
DropboxMetadata metadata = null; DropboxMetadata metadata = null;
@ -410,48 +435,6 @@ public DropboxMetadata Move(string fromPath, string toPath)
return metadata; return metadata;
} }
#endregion File operations
public override UploadResult Upload(Stream stream, string fileName)
{
CheckEarlyURLCopy(UploadPath, fileName);
return UploadFile(stream, UploadPath, fileName, AutoCreateShareableLink, ShareURLType);
}
private void CheckEarlyURLCopy(string path, string fileName)
{
if (OAuth2Info.CheckOAuth(AuthInfo) && !AutoCreateShareableLink)
{
string url = GetPublicURL(URLHelpers.CombineURL(path, fileName));
OnEarlyURLCopyRequested(url);
}
}
public static string VerifyPath(string path, string filename = null)
{
if (!string.IsNullOrEmpty(path))
{
path = path.Trim().Replace('\\', '/').Trim('/');
path = URLHelpers.AddSlash(path, SlashType.Prefix);
if (!string.IsNullOrEmpty(filename))
{
path = URLHelpers.CombineURL(path, filename);
}
return path;
}
if (!string.IsNullOrEmpty(filename))
{
return filename;
}
return "";
}
public string GetPublicURL(string path) public string GetPublicURL(string path)
{ {
return GetPublicURL(AccountInfo.Uid.ToString(), path); return GetPublicURL(AccountInfo.Uid.ToString(), path);

View file

@ -161,8 +161,6 @@ public FTP(FTPAccount account)
} }
} }
#region FileUploader methods
public override UploadResult Upload(Stream stream, string fileName) public override UploadResult Upload(Stream stream, string fileName)
{ {
UploadResult result = new UploadResult(); UploadResult result = new UploadResult();
@ -209,8 +207,6 @@ public override void StopUpload()
} }
} }
#endregion FileUploader methods
public bool Connect() public bool Connect()
{ {
if (!client.IsConnected) if (!client.IsConnected)

View file

@ -61,8 +61,6 @@ public SFTP(FTPAccount account)
Account = account; Account = account;
} }
#region FileUploader methods
public override UploadResult Upload(Stream stream, string fileName) public override UploadResult Upload(Stream stream, string fileName)
{ {
UploadResult result = new UploadResult(); UploadResult result = new UploadResult();
@ -109,8 +107,6 @@ public override void StopUpload()
} }
} }
#endregion FileUploader methods
public bool Connect() public bool Connect()
{ {
if (client == null) if (client == null)

View file

@ -504,16 +504,16 @@ public void DropboxAuthComplete(string code)
private void UpdateDropboxStatus() private void UpdateDropboxStatus()
{ {
if (OAuth2Info.CheckOAuth(Config.DropboxOAuth2Info) && Config.DropboxAccount != null) if (OAuth2Info.CheckOAuth(Config.DropboxOAuth2Info) && Config.DropboxAccountInfo != null)
{ {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.AppendLine(Resources.UploadersConfigForm_UpdateDropboxStatus_Email_ + " " + Config.DropboxAccount.email); sb.AppendLine(Resources.UploadersConfigForm_UpdateDropboxStatus_Email_ + " " + Config.DropboxAccountInfo.Email);
sb.AppendLine(Resources.UploadersConfigForm_UpdateDropboxStatus_Name_ + " " + Config.DropboxAccount.name.display_name); sb.AppendLine(Resources.UploadersConfigForm_UpdateDropboxStatus_Name_ + " " + Config.DropboxAccountInfo.Display_name);
sb.AppendLine(Resources.UploadersConfigForm_UpdateDropboxStatus_User_ID_ + " " + Config.DropboxAccount.account_id); sb.AppendLine(Resources.UploadersConfigForm_UpdateDropboxStatus_User_ID_ + " " + Config.DropboxAccountInfo.Uid);
string uploadPath = GetDropboxUploadPath(); string uploadPath = NameParser.Parse(NameParserType.URL, Dropbox.VerifyPath(Config.DropboxUploadPath));
sb.AppendLine(Resources.UploadersConfigForm_UpdateDropboxStatus_Upload_path_ + " " + uploadPath); sb.AppendLine(Resources.UploadersConfigForm_UpdateDropboxStatus_Upload_path_ + " " + uploadPath);
// TODO: uid sb.AppendLine(Resources.UploadersConfigForm_UpdateDropboxStatus_Download_path_ + " " +
sb.AppendLine(Resources.UploadersConfigForm_UpdateDropboxStatus_Download_path_ + " " + Dropbox.GetPublicURL(Config.DropboxAccount.account_id, uploadPath + "Example.png")); Dropbox.GetPublicURL(Config.DropboxAccountInfo.Uid.ToString(), URLHelpers.CombineURL(uploadPath, "Example.png")));
lblDropboxStatus.Text = sb.ToString(); lblDropboxStatus.Text = sb.ToString();
} }
else else
@ -522,11 +522,6 @@ private void UpdateDropboxStatus()
} }
} }
private string GetDropboxUploadPath()
{
return NameParser.Parse(NameParserType.URL, Dropbox.VerifyPath(Config.DropboxUploadPath));
}
#endregion Dropbox #endregion Dropbox
#region Amazon S3 #region Amazon S3