Few OneDrive changes

This commit is contained in:
Jaex 2014-07-15 15:17:02 +03:00
parent b4d2fb0ca6
commit 036a0190c4
4 changed files with 27 additions and 16 deletions

View file

@ -775,6 +775,9 @@ public UploadResult UploadFile(Stream stream, string fileName)
ShareURLType = Program.UploadersConfig.DropboxURLType
};
break;
case FileDestination.OneDrive:
fileUploader = new OneDrive(Program.UploadersConfig.OneDriveOAuth2Info);
break;
case FileDestination.Copy:
fileUploader = new Copy(Program.UploadersConfig.CopyOAuthInfo, Program.UploadersConfig.CopyAccountInfo)
{
@ -790,8 +793,7 @@ public UploadResult UploadFile(Stream stream, string fileName)
};
break;
case FileDestination.RapidShare:
fileUploader = new RapidShare(Program.UploadersConfig.RapidShareUsername, Program.UploadersConfig.RapidSharePassword,
Program.UploadersConfig.RapidShareFolderID);
fileUploader = new RapidShare(Program.UploadersConfig.RapidShareUsername, Program.UploadersConfig.RapidSharePassword, Program.UploadersConfig.RapidShareFolderID);
break;
case FileDestination.SendSpace:
fileUploader = new SendSpace(APIKeys.SendSpaceKey);

View file

@ -78,10 +78,10 @@ public enum FileDestination
{
[Description("Dropbox")]
Dropbox,
[Description("OneDrive")]
OneDrive,
[Description("FTP")]
FTP,
[Description("OneDrive")]
OneDrive,
[Description("Copy")]
Copy,
[Description("Google Drive")]

View file

@ -36,7 +36,7 @@ public sealed class OneDrive : FileUploader, IOAuth2
{
public OAuth2Info AuthInfo { get; private set; }
public string FolderId { get; set; }
public string FolderID { get; set; }
public OneDrive(OAuth2Info authInfo)
{
@ -50,20 +50,24 @@ public override UploadResult Upload(Stream stream, string fileName)
return null;
}
if (string.IsNullOrEmpty(FolderId))
if (string.IsNullOrEmpty(FolderID))
{
FolderId = "me/skydrive/files";
FolderID = "me/skydrive/files";
}
var uploadUri = string.Format("https://apis.live.net/v5.0/{0}/{1}?access_token={2}&overwrite=true", FolderId, fileName, AuthInfo.Token.access_token);
var result = UploadData(stream, uploadUri, string.Empty, string.Empty, null, null, null, ResponseType.Text, HttpMethod.PUT);
if (!result.IsSuccess)
Dictionary<string, string> args = new Dictionary<string, string>();
args.Add("access_token", AuthInfo.Token.access_token);
args.Add("overwrite", "true");
string url = string.Format("https://apis.live.net/v5.0/{0}/{1}", FolderID, fileName);
UploadResult result = UploadData(stream, url, string.Empty, arguments: args, method: HttpMethod.PUT);
if (result.IsSuccess)
{
return result;
OneDriveUploadInfo resultJson = JsonConvert.DeserializeObject<OneDriveUploadInfo>(result.Response);
result.URL = resultJson.source;
}
var resultJson = JsonConvert.DeserializeObject<OneDriveUploadInfo>(result.Response);
result.URL = resultJson.source;
return result;
}
@ -73,6 +77,7 @@ public string GetAuthorizationURL()
args.Add("response_type", "code");
args.Add("client_id", AuthInfo.Client_ID);
args.Add("scope", "wl.skydrive_update");
return CreateQuery("https://login.live.com/oauth20_authorize.srf", args);
}
@ -84,7 +89,7 @@ public bool GetAccessToken(string code)
args.Add("client_id", AuthInfo.Client_ID);
args.Add("client_secret", AuthInfo.Client_Secret);
var response = SendRequest(HttpMethod.POST, "https://login.live.com/oauth20_token.srf", args);
string response = SendRequest(HttpMethod.POST, "https://login.live.com/oauth20_token.srf", args);
if (string.IsNullOrEmpty(response))
{
@ -116,7 +121,7 @@ public bool RefreshAccessToken()
args.Add("client_id", AuthInfo.Client_ID);
args.Add("client_secret", AuthInfo.Client_Secret);
var response = SendRequest(HttpMethod.POST, "https://login.live.com/oauth20_token.srf", args);
string response = SendRequest(HttpMethod.POST, "https://login.live.com/oauth20_token.srf", args);
if (string.IsNullOrEmpty(response))
{
@ -148,7 +153,7 @@ public bool CheckAuthorization()
return false;
}
Errors.Add("Live Id login is required.");
Errors.Add("OneDrive login is required.");
return false;
}
}

View file

@ -112,6 +112,10 @@ public class UploadersConfig : SettingsBase<UploadersConfig>
public bool DropboxAutoCreateShareableLink = false;
public DropboxURLType DropboxURLType = DropboxURLType.Default;
// OneDrive
public OAuth2Info OneDriveOAuth2Info = null;
// Copy
public OAuthInfo CopyOAuthInfo = null;