mirror of
https://github.com/ShareX/ShareX.git
synced 2024-09-30 01:07:21 +13:00
Hubic changes
This commit is contained in:
parent
721ea8e404
commit
36ac96d4d7
3 changed files with 21 additions and 22 deletions
|
@ -28,10 +28,12 @@ namespace ShareX.HelpersLib
|
|||
public static class Links
|
||||
{
|
||||
public const string URL_WEBSITE = "http://getsharex.com";
|
||||
public const string URL_WEBSITE_SSL = "https://getsharex.com";
|
||||
public const string URL_PROJECT = "https://github.com/ShareX/ShareX";
|
||||
public const string URL_ISSUES = URL_PROJECT + "/issues";
|
||||
public const string URL_UPDATE = URL_WEBSITE + "/Update.xml";
|
||||
public const string URL_CALLBACK = URL_WEBSITE + "/callback/";
|
||||
public const string URL_CALLBACK_SSL = URL_WEBSITE_SSL + "/callback/";
|
||||
public const string URL_VERSION_HISTORY = URL_PROJECT + "/wiki/Changelog";
|
||||
public const string URL_DONATE = "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=PCNWK2G6ZYJ2E";
|
||||
public const string URL_BERK = "https://github.com/Jaex";
|
||||
|
|
|
@ -23,14 +23,13 @@ You should have received a copy of the GNU General Public License
|
|||
|
||||
#endregion License Information (GPL v3)
|
||||
|
||||
using System;
|
||||
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.Net;
|
||||
using System.Text;
|
||||
|
||||
namespace ShareX.UploadersLib.FileUploaders
|
||||
|
@ -58,7 +57,7 @@ public string GetAuthorizationURL()
|
|||
{
|
||||
Dictionary<string, string> args = new Dictionary<string, string>();
|
||||
//Hubic only accepts https callback URL
|
||||
args.Add("redirect_uri", @"https://getsharex.com/callback/");
|
||||
args.Add("redirect_uri", Links.URL_CALLBACK_SSL);
|
||||
args.Add("client_id", AuthInfo.Client_ID);
|
||||
args.Add("scope", Scope);
|
||||
args.Add("response_type", "code");
|
||||
|
@ -71,7 +70,7 @@ public bool GetAccessToken(string code)
|
|||
Dictionary<string, string> args = new Dictionary<string, string>();
|
||||
args.Add("code", code);
|
||||
//Hubic only accepts https callback URL
|
||||
args.Add("redirect_uri", @"https://getsharex.com/callback/");
|
||||
args.Add("redirect_uri", Links.URL_CALLBACK_SSL);
|
||||
args.Add("grant_type", "authorization_code");
|
||||
|
||||
string response = SendRequest(HttpMethod.POST, "https://api.hubic.com/oauth/token/", args, GetAuthHeaders("Basic"));
|
||||
|
@ -177,6 +176,7 @@ public List<HubicFolderInfo> GetFiles(HubicFolderInfo fileInfo)
|
|||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
string response = SendRequest(HttpMethod.GET, HubicOpenstackAuthInfo.endpoint + "/default" + "/?path=" + fileInfo.name + "&format=json", headers: GetAuthHeaders("X-Auth-Token"));
|
||||
|
||||
if (!string.IsNullOrEmpty(response))
|
||||
|
@ -194,12 +194,14 @@ public override UploadResult Upload(Stream stream, string fileName)
|
|||
return null;
|
||||
}
|
||||
|
||||
WebClient wc = new WebClient();
|
||||
wc.Headers.Add("X-Auth-Token", HubicOpenstackAuthInfo.token);
|
||||
wc.Headers.Add("X-Detect-Content-Type", "true");
|
||||
wc.UploadData(new Uri(HubicOpenstackAuthInfo.endpoint + "/default/" + SelectedFolder.path + "/" + fileName), "PUT", stream.GetBytes());
|
||||
string url = URLHelpers.CombineURL(HubicOpenstackAuthInfo.endpoint, "default", SelectedFolder.path, fileName);
|
||||
|
||||
NameValueCollection headers = new NameValueCollection();
|
||||
headers.Add("X-Auth-Token", HubicOpenstackAuthInfo.token);
|
||||
headers.Add("X-Detect-Content-Type", "true");
|
||||
|
||||
UploadResult result = UploadData(stream, url, fileName, headers: headers, method: HttpMethod.PUT);
|
||||
|
||||
UploadResult result = new UploadResult();
|
||||
if (Publish)
|
||||
{
|
||||
AllowReportProgress = false;
|
||||
|
@ -216,20 +218,23 @@ public override UploadResult Upload(Stream stream, string fileName)
|
|||
if (!string.IsNullOrEmpty(response))
|
||||
{
|
||||
HubicPublishURLResponse resp = JsonConvert.DeserializeObject<HubicPublishURLResponse>(response);
|
||||
string url = resp.indirectUrl;
|
||||
string respURL = resp.indirectUrl;
|
||||
result.IsURLExpected = true;
|
||||
result.URL = url;
|
||||
result.URL = respURL;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public class HubicOpenstackAuthInfo
|
||||
{
|
||||
public string token { get; set; }
|
||||
public string endpoint { get; set; }
|
||||
public string expires { get; set; }
|
||||
}
|
||||
|
||||
public class HubicFolderInfo
|
||||
{
|
||||
private string _name;
|
||||
|
@ -248,7 +253,7 @@ public string name
|
|||
path = value;
|
||||
string[] temp = value.Split('/');
|
||||
_name = temp[temp.Length - 1];
|
||||
}
|
||||
}
|
||||
}
|
||||
public string content_type { get; set; }
|
||||
public string path { get; set; }
|
||||
|
@ -263,6 +268,5 @@ public class HubicPublishURLResponse
|
|||
public string creationDate { get; set; }
|
||||
public string comment { get; set; }
|
||||
public string type { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -909,15 +909,8 @@ public void HubicAuthOpen()
|
|||
{
|
||||
Config.HubicOAuth2Info = oauth;
|
||||
Config.HubicOpenstackAuthInfo = osauth;
|
||||
URLHelpers.OpenURL(url);
|
||||
DebugHelper.WriteLine("HubicAuthOpen - Authorization URL is opened: " + url);
|
||||
|
||||
using (OAuthWebForm oauthForm = new OAuthWebForm(url, "https://getsharex.com/callback/"))
|
||||
{
|
||||
if (oauthForm.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
HubicAuthComplete(oauthForm.Code);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue