mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-01 09:47:22 +13:00
fixed #91: Added OneDrive support
This commit is contained in:
parent
470818f753
commit
43c59a8236
4 changed files with 47 additions and 20 deletions
|
@ -82,12 +82,12 @@ public enum FileDestination
|
|||
Dropbox,
|
||||
[Description("FTP")]
|
||||
FTP,
|
||||
//[Description("OneDrive")]
|
||||
//OneDrive,
|
||||
[Description("Copy")]
|
||||
Copy,
|
||||
[Description("OneDrive")]
|
||||
OneDrive,
|
||||
[Description("Google Drive")]
|
||||
GoogleDrive,
|
||||
[Description("Copy")]
|
||||
Copy,
|
||||
[Description("Box")]
|
||||
Box,
|
||||
[Description("MEGA")]
|
||||
|
|
|
@ -26,11 +26,9 @@ You should have received a copy of the GNU General Public License
|
|||
using Newtonsoft.Json;
|
||||
using ShareX.HelpersLib;
|
||||
using ShareX.UploadersLib.HelperClasses;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace ShareX.UploadersLib.FileUploaders
|
||||
{
|
||||
|
@ -48,7 +46,7 @@ public string GetAuthorizationURL()
|
|||
{
|
||||
Dictionary<string, string> args = new Dictionary<string, string>();
|
||||
args.Add("client_id", AuthInfo.Client_ID);
|
||||
args.Add("scope", "wl.offline_access wl.basic wl.skydrive_update");
|
||||
args.Add("scope", "wl.offline_access wl.basic wl.skydrive");
|
||||
args.Add("response_type", "code");
|
||||
args.Add("redirect_uri", Links.URL_CALLBACK);
|
||||
|
||||
|
@ -131,9 +129,40 @@ public bool CheckAuthorization()
|
|||
return true;
|
||||
}
|
||||
|
||||
private NameValueCollection GetAuthHeaders()
|
||||
{
|
||||
NameValueCollection headers = new NameValueCollection();
|
||||
headers.Add("Authorization", "Bearer " + AuthInfo.Token.access_token);
|
||||
return headers;
|
||||
}
|
||||
|
||||
public override UploadResult Upload(Stream stream, string fileName)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
if (!CheckAuthorization()) return null;
|
||||
|
||||
Dictionary<string, string> args = new Dictionary<string, string>();
|
||||
args.Add("access_token", AuthInfo.Token.access_token);
|
||||
args.Add("overwrite", "true");
|
||||
args.Add("downsize_photo_uploads", "false");
|
||||
|
||||
string url = CreateQuery("https://apis.live.net/v5.0/me/skydrive/files", args);
|
||||
|
||||
UploadResult result = UploadData(stream, url, fileName);
|
||||
|
||||
if (result.IsSuccess)
|
||||
{
|
||||
OneDriveUploadInfo uploadInfo = JsonConvert.DeserializeObject<OneDriveUploadInfo>(result.Response);
|
||||
result.URL = uploadInfo.source;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private class OneDriveUploadInfo
|
||||
{
|
||||
public string id { get; set; }
|
||||
public string name { get; set; }
|
||||
public string source { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
|
@ -49,13 +49,11 @@ public UploadersConfigForm(UploadersConfig uploadersConfig)
|
|||
Config = uploadersConfig;
|
||||
InitializeComponent();
|
||||
|
||||
// TODO: Add OneDrive support
|
||||
//tcFileUploaders.TabPages.Remove(tpOneDrive);
|
||||
|
||||
if (!string.IsNullOrEmpty(Config.FilePath))
|
||||
{
|
||||
Text += " - " + Config.FilePath;
|
||||
}
|
||||
|
||||
Icon = ShareXResources.Icon;
|
||||
}
|
||||
|
||||
|
|
|
@ -829,15 +829,8 @@ public UploadResult UploadFile(Stream stream, string fileName)
|
|||
ShareURLType = Program.UploadersConfig.DropboxURLType
|
||||
};
|
||||
break;
|
||||
/*case FileDestination.OneDrive:
|
||||
case FileDestination.OneDrive:
|
||||
fileUploader = new OneDrive(Program.UploadersConfig.OneDriveOAuth2Info);
|
||||
break;*/
|
||||
case FileDestination.Copy:
|
||||
fileUploader = new Copy(Program.UploadersConfig.CopyOAuthInfo, Program.UploadersConfig.CopyAccountInfo)
|
||||
{
|
||||
UploadPath = NameParser.Parse(NameParserType.URL, Copy.TidyUploadPath(Program.UploadersConfig.CopyUploadPath)),
|
||||
URLType = Program.UploadersConfig.CopyURLType
|
||||
};
|
||||
break;
|
||||
case FileDestination.GoogleDrive:
|
||||
fileUploader = new GoogleDrive(Program.UploadersConfig.GoogleDriveOAuth2Info)
|
||||
|
@ -846,6 +839,13 @@ public UploadResult UploadFile(Stream stream, string fileName)
|
|||
FolderID = Program.UploadersConfig.GoogleDriveUseFolder ? Program.UploadersConfig.GoogleDriveFolderID : null
|
||||
};
|
||||
break;
|
||||
case FileDestination.Copy:
|
||||
fileUploader = new Copy(Program.UploadersConfig.CopyOAuthInfo, Program.UploadersConfig.CopyAccountInfo)
|
||||
{
|
||||
UploadPath = NameParser.Parse(NameParserType.URL, Copy.TidyUploadPath(Program.UploadersConfig.CopyUploadPath)),
|
||||
URLType = Program.UploadersConfig.CopyURLType
|
||||
};
|
||||
break;
|
||||
case FileDestination.RapidShare:
|
||||
fileUploader = new RapidShare(Program.UploadersConfig.RapidShareUsername, Program.UploadersConfig.RapidSharePassword, Program.UploadersConfig.RapidShareFolderID);
|
||||
break;
|
||||
|
|
Loading…
Reference in a new issue