mirror of
https://github.com/ShareX/ShareX.git
synced 2024-07-04 22:21:23 +12:00
fixed #1416: Added raw URL support to GitHub Gist
This commit is contained in:
parent
3ce8312cfc
commit
a04d10c05c
|
@ -24,6 +24,7 @@
|
||||||
#endregion License Information (GPL v3)
|
#endregion License Information (GPL v3)
|
||||||
|
|
||||||
using Microsoft.Win32;
|
using Microsoft.Win32;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
using ShareX.HelpersLib;
|
using ShareX.HelpersLib;
|
||||||
using ShareX.HelpersLib.Properties;
|
using ShareX.HelpersLib.Properties;
|
||||||
using System;
|
using System;
|
||||||
|
@ -1049,5 +1050,11 @@ public static void CopyAll(DirectoryInfo source, DirectoryInfo target)
|
||||||
handle.Free();
|
handle.Free();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// http://goessner.net/articles/JsonPath/
|
||||||
|
public static string ParseJSON(string text, string jsonPath)
|
||||||
|
{
|
||||||
|
return (string)JToken.Parse(text).SelectToken("$." + jsonPath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
File diff suppressed because it is too large
Load diff
|
@ -282,7 +282,7 @@ public void LoadSettings()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
txtPastebinTitle.Text = Config.PastebinSettings.Title;
|
txtPastebinTitle.Text = Config.PastebinSettings.Title;
|
||||||
cbPastebinRaw.Checked = Config.PastebinSettings.Raw;
|
cbPastebinRaw.Checked = Config.PastebinSettings.RawURL;
|
||||||
|
|
||||||
// Paste.ee
|
// Paste.ee
|
||||||
|
|
||||||
|
@ -291,13 +291,15 @@ public void LoadSettings()
|
||||||
// Gist
|
// Gist
|
||||||
|
|
||||||
atcGistAccountType.SelectedAccountType = Config.GistAnonymousLogin ? AccountType.Anonymous : AccountType.User;
|
atcGistAccountType.SelectedAccountType = Config.GistAnonymousLogin ? AccountType.Anonymous : AccountType.User;
|
||||||
chkGistPublishPublic.Checked = Config.GistPublishPublic;
|
|
||||||
|
|
||||||
if (OAuth2Info.CheckOAuth(Config.GistOAuth2Info))
|
if (OAuth2Info.CheckOAuth(Config.GistOAuth2Info))
|
||||||
{
|
{
|
||||||
oAuth2Gist.Status = OAuthLoginStatus.LoginSuccessful;
|
oAuth2Gist.Status = OAuthLoginStatus.LoginSuccessful;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cbGistPublishPublic.Checked = Config.GistPublishPublic;
|
||||||
|
cbGistUseRawURL.Checked = Config.GistRawURL;
|
||||||
|
|
||||||
// Upaste
|
// Upaste
|
||||||
|
|
||||||
txtUpasteUserKey.Text = Config.UpasteUserKey;
|
txtUpasteUserKey.Text = Config.UpasteUserKey;
|
||||||
|
@ -411,7 +413,7 @@ public void LoadSettings()
|
||||||
nudEmailSmtpPort.SetValue(Config.EmailSmtpPort);
|
nudEmailSmtpPort.SetValue(Config.EmailSmtpPort);
|
||||||
txtEmailFrom.Text = Config.EmailFrom;
|
txtEmailFrom.Text = Config.EmailFrom;
|
||||||
txtEmailPassword.Text = Config.EmailPassword;
|
txtEmailPassword.Text = Config.EmailPassword;
|
||||||
chkEmailConfirm.Checked = Config.EmailConfirmSend;
|
cbEmailConfirm.Checked = Config.EmailConfirmSend;
|
||||||
cbEmailRememberLastTo.Checked = Config.EmailRememberLastTo;
|
cbEmailRememberLastTo.Checked = Config.EmailRememberLastTo;
|
||||||
txtEmailDefaultSubject.Text = Config.EmailDefaultSubject;
|
txtEmailDefaultSubject.Text = Config.EmailDefaultSubject;
|
||||||
txtEmailDefaultBody.Text = Config.EmailDefaultBody;
|
txtEmailDefaultBody.Text = Config.EmailDefaultBody;
|
||||||
|
@ -1118,7 +1120,7 @@ private void txtPastebinTitle_TextChanged(object sender, EventArgs e)
|
||||||
|
|
||||||
private void cbPastebinRaw_CheckedChanged(object sender, EventArgs e)
|
private void cbPastebinRaw_CheckedChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Config.PastebinSettings.Raw = cbPastebinRaw.Checked;
|
Config.PastebinSettings.RawURL = cbPastebinRaw.Checked;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion Pastebin
|
#endregion Pastebin
|
||||||
|
@ -1157,7 +1159,12 @@ private void oAuth2Gist_ClearButtonClicked()
|
||||||
|
|
||||||
private void chkGistPublishPublic_CheckedChanged(object sender, EventArgs e)
|
private void chkGistPublishPublic_CheckedChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Config.GistPublishPublic = ((CheckBox)sender).Checked;
|
Config.GistPublishPublic = cbGistPublishPublic.Checked;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void cbGistUseRawURL_CheckedChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Config.GistRawURL = cbGistUseRawURL.Checked;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion Gist
|
#endregion Gist
|
||||||
|
@ -1440,7 +1447,7 @@ private void cboMinusFolders_SelectedIndexChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Config.MinusConfig.FolderID = cboMinusFolders.SelectedIndex;
|
Config.MinusConfig.FolderID = cboMinusFolders.SelectedIndex;
|
||||||
MinusFolder tempMf = Config.MinusConfig.GetActiveFolder();
|
MinusFolder tempMf = Config.MinusConfig.GetActiveFolder();
|
||||||
chkMinusPublic.Checked = tempMf.is_public;
|
cbMinusPublic.Checked = tempMf.is_public;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1451,7 +1458,7 @@ private void btnMinusFolderAdd_Click(object sender, EventArgs e)
|
||||||
btnMinusFolderAdd.Enabled = false;
|
btnMinusFolderAdd.Enabled = false;
|
||||||
|
|
||||||
Minus minus = new Minus(Config.MinusConfig, Config.MinusOAuth2Info);
|
Minus minus = new Minus(Config.MinusConfig, Config.MinusOAuth2Info);
|
||||||
MinusFolder dir = minus.CreateFolder(cboMinusFolders.Text, chkMinusPublic.Checked);
|
MinusFolder dir = minus.CreateFolder(cboMinusFolders.Text, cbMinusPublic.Checked);
|
||||||
if (dir != null)
|
if (dir != null)
|
||||||
{
|
{
|
||||||
cboMinusFolders.Items.Add(dir);
|
cboMinusFolders.Items.Add(dir);
|
||||||
|
@ -1638,7 +1645,7 @@ private void txtPassword_TextChanged(object sender, EventArgs e)
|
||||||
|
|
||||||
private void chkEmailConfirm_CheckedChanged(object sender, EventArgs e)
|
private void chkEmailConfirm_CheckedChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Config.EmailConfirmSend = chkEmailConfirm.Checked;
|
Config.EmailConfirmSend = cbEmailConfirm.Checked;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void cbRememberLastToEmail_CheckedChanged(object sender, EventArgs e)
|
private void cbRememberLastToEmail_CheckedChanged(object sender, EventArgs e)
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -321,7 +321,7 @@ private string ParseRegexSyntax(string syntax)
|
||||||
// http://goessner.net/articles/JsonPath/
|
// http://goessner.net/articles/JsonPath/
|
||||||
private string ParseJsonSyntax(string syntaxJsonPath)
|
private string ParseJsonSyntax(string syntaxJsonPath)
|
||||||
{
|
{
|
||||||
return (string)JToken.Parse(response).SelectToken("$." + syntaxJsonPath);
|
return Helpers.ParseJSON(response, syntaxJsonPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
// http://www.w3schools.com/xsl/xpath_syntax.asp
|
// http://www.w3schools.com/xsl/xpath_syntax.asp
|
||||||
|
|
|
@ -1,79 +0,0 @@
|
||||||
#region License Information (GPL v3)
|
|
||||||
|
|
||||||
/*
|
|
||||||
ShareX - A program that allows you to take screenshots and share any file type
|
|
||||||
Copyright (c) 2007-2016 ShareX Team
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
|
||||||
modify it under the terms of the GNU General Public License
|
|
||||||
as published by the Free Software Foundation; either version 2
|
|
||||||
of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program; if not, write to the Free Software
|
|
||||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
||||||
|
|
||||||
Optionally you can also view the license at <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#endregion License Information (GPL v3)
|
|
||||||
|
|
||||||
using ShareX.HelpersLib;
|
|
||||||
using System;
|
|
||||||
using System.IO;
|
|
||||||
using System.Runtime.Serialization.Json;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace ShareX.UploadersLib
|
|
||||||
{
|
|
||||||
public static class JSONHelper
|
|
||||||
{
|
|
||||||
public static T JSONToObject<T>(string json)
|
|
||||||
{
|
|
||||||
if (!string.IsNullOrEmpty(json))
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(T));
|
|
||||||
using (MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(json)))
|
|
||||||
{
|
|
||||||
return (T)serializer.ReadObject(stream);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
DebugHelper.WriteException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return default(T);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string ObjectToJSON<T>(T obj)
|
|
||||||
{
|
|
||||||
if (obj != null)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
using (MemoryStream stream = new MemoryStream())
|
|
||||||
{
|
|
||||||
DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(T));
|
|
||||||
serializer.WriteObject(stream, obj);
|
|
||||||
return new StreamReader(stream, Encoding.UTF8).ReadToEnd();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
DebugHelper.WriteException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -250,7 +250,6 @@
|
||||||
<Compile Include="HelperClasses\AccountInfo.cs" />
|
<Compile Include="HelperClasses\AccountInfo.cs" />
|
||||||
<Compile Include="HelperClasses\Argument.cs" />
|
<Compile Include="HelperClasses\Argument.cs" />
|
||||||
<Compile Include="HelperClasses\KeyFileNameEditor.cs" />
|
<Compile Include="HelperClasses\KeyFileNameEditor.cs" />
|
||||||
<Compile Include="HelperClasses\JSONHelper.cs" />
|
|
||||||
<Compile Include="HelperClasses\OAuth\IOAuth.cs" />
|
<Compile Include="HelperClasses\OAuth\IOAuth.cs" />
|
||||||
<Compile Include="HelperClasses\OAuth\IOAuth2.cs" />
|
<Compile Include="HelperClasses\OAuth\IOAuth2.cs" />
|
||||||
<Compile Include="HelperClasses\OAuth\IOAuth2Basic.cs" />
|
<Compile Include="HelperClasses\OAuth\IOAuth2Basic.cs" />
|
||||||
|
|
|
@ -40,21 +40,15 @@ public sealed class Gist : TextUploader, IOAuth2Basic
|
||||||
|
|
||||||
public OAuth2Info AuthInfo { get; private set; }
|
public OAuth2Info AuthInfo { get; private set; }
|
||||||
|
|
||||||
private readonly bool publishPublic;
|
public bool PublicUpload { get; set; }
|
||||||
|
public bool RawURL { get; set; }
|
||||||
|
|
||||||
|
public Gist()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
public Gist(OAuth2Info oAuthInfos)
|
public Gist(OAuth2Info oAuthInfos)
|
||||||
: this(false, oAuthInfos)
|
|
||||||
{
|
{
|
||||||
}
|
|
||||||
|
|
||||||
public Gist(bool publishPublic)
|
|
||||||
: this(publishPublic, null)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public Gist(bool publishPublic, OAuth2Info oAuthInfos)
|
|
||||||
{
|
|
||||||
this.publishPublic = publishPublic;
|
|
||||||
AuthInfo = oAuthInfos;
|
AuthInfo = oAuthInfos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,7 +96,7 @@ public override UploadResult UploadText(string text, string fileName)
|
||||||
{
|
{
|
||||||
var gistUploadObject = new
|
var gistUploadObject = new
|
||||||
{
|
{
|
||||||
@public = publishPublic,
|
@public = PublicUpload,
|
||||||
files = new Dictionary<string, object>
|
files = new Dictionary<string, object>
|
||||||
{
|
{
|
||||||
{ fileName, new { content = text } }
|
{ fileName, new { content = text } }
|
||||||
|
@ -122,9 +116,14 @@ public override UploadResult UploadText(string text, string fileName)
|
||||||
|
|
||||||
if (response != null)
|
if (response != null)
|
||||||
{
|
{
|
||||||
var gistReturnType = new { html_url = string.Empty };
|
if (RawURL)
|
||||||
var gistReturnObject = JsonConvert.DeserializeAnonymousType(response, gistReturnType);
|
{
|
||||||
ur.URL = gistReturnObject.html_url;
|
ur.URL = Helpers.ParseJSON(response, "files.*.raw_url");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ur.URL = Helpers.ParseJSON(response, "html_url");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -99,7 +99,7 @@ public override UploadResult UploadText(string text, string fileName)
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(ur.Response) && !ur.Response.StartsWith("Bad API request") && ur.Response.IsValidUrl())
|
if (!string.IsNullOrEmpty(ur.Response) && !ur.Response.StartsWith("Bad API request") && ur.Response.IsValidUrl())
|
||||||
{
|
{
|
||||||
if (Settings.Raw)
|
if (Settings.RawURL)
|
||||||
{
|
{
|
||||||
string paste_key = URLHelpers.GetFileName(ur.Response);
|
string paste_key = URLHelpers.GetFileName(ur.Response);
|
||||||
ur.URL = "http://pastebin.com/raw/" + paste_key;
|
ur.URL = "http://pastebin.com/raw/" + paste_key;
|
||||||
|
@ -480,6 +480,6 @@ public class PastebinSettings
|
||||||
public string Title { get; set; }
|
public string Title { get; set; }
|
||||||
public string TextFormat { get; set; } = "text";
|
public string TextFormat { get; set; } = "text";
|
||||||
public string UserKey { get; set; }
|
public string UserKey { get; set; }
|
||||||
public bool Raw { get; set; }
|
public bool RawURL { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -107,6 +107,7 @@ public class UploadersConfig : SettingsBase<UploadersConfig>
|
||||||
public bool GistAnonymousLogin = true;
|
public bool GistAnonymousLogin = true;
|
||||||
public OAuth2Info GistOAuth2Info = null;
|
public OAuth2Info GistOAuth2Info = null;
|
||||||
public bool GistPublishPublic = false;
|
public bool GistPublishPublic = false;
|
||||||
|
public bool GistRawURL = false;
|
||||||
|
|
||||||
// uPaste
|
// uPaste
|
||||||
|
|
||||||
|
|
|
@ -931,8 +931,11 @@ public UploadResult UploadText(Stream stream, string fileName)
|
||||||
textUploader = new Paste_ee(Program.UploadersConfig.Paste_eeUserAPIKey);
|
textUploader = new Paste_ee(Program.UploadersConfig.Paste_eeUserAPIKey);
|
||||||
break;
|
break;
|
||||||
case TextDestination.Gist:
|
case TextDestination.Gist:
|
||||||
textUploader = Program.UploadersConfig.GistAnonymousLogin ? new Gist(Program.UploadersConfig.GistPublishPublic) :
|
textUploader = new Gist(Program.UploadersConfig.GistAnonymousLogin ? null : Program.UploadersConfig.GistOAuth2Info)
|
||||||
new Gist(Program.UploadersConfig.GistPublishPublic, Program.UploadersConfig.GistOAuth2Info);
|
{
|
||||||
|
PublicUpload = Program.UploadersConfig.GistPublishPublic,
|
||||||
|
RawURL = Program.UploadersConfig.GistRawURL
|
||||||
|
};
|
||||||
break;
|
break;
|
||||||
case TextDestination.Upaste:
|
case TextDestination.Upaste:
|
||||||
textUploader = new Upaste(Program.UploadersConfig.UpasteUserKey)
|
textUploader = new Upaste(Program.UploadersConfig.UpasteUserKey)
|
||||||
|
|
Loading…
Reference in a new issue