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)
|
||||
|
||||
using Microsoft.Win32;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using ShareX.HelpersLib;
|
||||
using ShareX.HelpersLib.Properties;
|
||||
using System;
|
||||
|
@ -1049,5 +1050,11 @@ public static void CopyAll(DirectoryInfo source, DirectoryInfo target)
|
|||
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;
|
||||
cbPastebinRaw.Checked = Config.PastebinSettings.Raw;
|
||||
cbPastebinRaw.Checked = Config.PastebinSettings.RawURL;
|
||||
|
||||
// Paste.ee
|
||||
|
||||
|
@ -291,13 +291,15 @@ public void LoadSettings()
|
|||
// Gist
|
||||
|
||||
atcGistAccountType.SelectedAccountType = Config.GistAnonymousLogin ? AccountType.Anonymous : AccountType.User;
|
||||
chkGistPublishPublic.Checked = Config.GistPublishPublic;
|
||||
|
||||
if (OAuth2Info.CheckOAuth(Config.GistOAuth2Info))
|
||||
{
|
||||
oAuth2Gist.Status = OAuthLoginStatus.LoginSuccessful;
|
||||
}
|
||||
|
||||
cbGistPublishPublic.Checked = Config.GistPublishPublic;
|
||||
cbGistUseRawURL.Checked = Config.GistRawURL;
|
||||
|
||||
// Upaste
|
||||
|
||||
txtUpasteUserKey.Text = Config.UpasteUserKey;
|
||||
|
@ -411,7 +413,7 @@ public void LoadSettings()
|
|||
nudEmailSmtpPort.SetValue(Config.EmailSmtpPort);
|
||||
txtEmailFrom.Text = Config.EmailFrom;
|
||||
txtEmailPassword.Text = Config.EmailPassword;
|
||||
chkEmailConfirm.Checked = Config.EmailConfirmSend;
|
||||
cbEmailConfirm.Checked = Config.EmailConfirmSend;
|
||||
cbEmailRememberLastTo.Checked = Config.EmailRememberLastTo;
|
||||
txtEmailDefaultSubject.Text = Config.EmailDefaultSubject;
|
||||
txtEmailDefaultBody.Text = Config.EmailDefaultBody;
|
||||
|
@ -1118,7 +1120,7 @@ private void txtPastebinTitle_TextChanged(object sender, EventArgs e)
|
|||
|
||||
private void cbPastebinRaw_CheckedChanged(object sender, EventArgs e)
|
||||
{
|
||||
Config.PastebinSettings.Raw = cbPastebinRaw.Checked;
|
||||
Config.PastebinSettings.RawURL = cbPastebinRaw.Checked;
|
||||
}
|
||||
|
||||
#endregion Pastebin
|
||||
|
@ -1157,7 +1159,12 @@ private void oAuth2Gist_ClearButtonClicked()
|
|||
|
||||
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
|
||||
|
@ -1440,7 +1447,7 @@ private void cboMinusFolders_SelectedIndexChanged(object sender, EventArgs e)
|
|||
{
|
||||
Config.MinusConfig.FolderID = cboMinusFolders.SelectedIndex;
|
||||
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;
|
||||
|
||||
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)
|
||||
{
|
||||
cboMinusFolders.Items.Add(dir);
|
||||
|
@ -1638,7 +1645,7 @@ private void txtPassword_TextChanged(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)
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -321,7 +321,7 @@ private string ParseRegexSyntax(string syntax)
|
|||
// http://goessner.net/articles/JsonPath/
|
||||
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
|
||||
|
|
|
@ -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\Argument.cs" />
|
||||
<Compile Include="HelperClasses\KeyFileNameEditor.cs" />
|
||||
<Compile Include="HelperClasses\JSONHelper.cs" />
|
||||
<Compile Include="HelperClasses\OAuth\IOAuth.cs" />
|
||||
<Compile Include="HelperClasses\OAuth\IOAuth2.cs" />
|
||||
<Compile Include="HelperClasses\OAuth\IOAuth2Basic.cs" />
|
||||
|
|
|
@ -40,21 +40,15 @@ public sealed class Gist : TextUploader, IOAuth2Basic
|
|||
|
||||
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)
|
||||
: this(false, oAuthInfos)
|
||||
{
|
||||
}
|
||||
|
||||
public Gist(bool publishPublic)
|
||||
: this(publishPublic, null)
|
||||
{
|
||||
}
|
||||
|
||||
public Gist(bool publishPublic, OAuth2Info oAuthInfos)
|
||||
{
|
||||
this.publishPublic = publishPublic;
|
||||
AuthInfo = oAuthInfos;
|
||||
}
|
||||
|
||||
|
@ -102,7 +96,7 @@ public override UploadResult UploadText(string text, string fileName)
|
|||
{
|
||||
var gistUploadObject = new
|
||||
{
|
||||
@public = publishPublic,
|
||||
@public = PublicUpload,
|
||||
files = new Dictionary<string, object>
|
||||
{
|
||||
{ fileName, new { content = text } }
|
||||
|
@ -122,9 +116,14 @@ public override UploadResult UploadText(string text, string fileName)
|
|||
|
||||
if (response != null)
|
||||
{
|
||||
var gistReturnType = new { html_url = string.Empty };
|
||||
var gistReturnObject = JsonConvert.DeserializeAnonymousType(response, gistReturnType);
|
||||
ur.URL = gistReturnObject.html_url;
|
||||
if (RawURL)
|
||||
{
|
||||
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 (Settings.Raw)
|
||||
if (Settings.RawURL)
|
||||
{
|
||||
string paste_key = URLHelpers.GetFileName(ur.Response);
|
||||
ur.URL = "http://pastebin.com/raw/" + paste_key;
|
||||
|
@ -480,6 +480,6 @@ public class PastebinSettings
|
|||
public string Title { get; set; }
|
||||
public string TextFormat { get; set; } = "text";
|
||||
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 OAuth2Info GistOAuth2Info = null;
|
||||
public bool GistPublishPublic = false;
|
||||
public bool GistRawURL = false;
|
||||
|
||||
// uPaste
|
||||
|
||||
|
|
|
@ -931,8 +931,11 @@ public UploadResult UploadText(Stream stream, string fileName)
|
|||
textUploader = new Paste_ee(Program.UploadersConfig.Paste_eeUserAPIKey);
|
||||
break;
|
||||
case TextDestination.Gist:
|
||||
textUploader = Program.UploadersConfig.GistAnonymousLogin ? new Gist(Program.UploadersConfig.GistPublishPublic) :
|
||||
new Gist(Program.UploadersConfig.GistPublishPublic, Program.UploadersConfig.GistOAuth2Info);
|
||||
textUploader = new Gist(Program.UploadersConfig.GistAnonymousLogin ? null : Program.UploadersConfig.GistOAuth2Info)
|
||||
{
|
||||
PublicUpload = Program.UploadersConfig.GistPublishPublic,
|
||||
RawURL = Program.UploadersConfig.GistRawURL
|
||||
};
|
||||
break;
|
||||
case TextDestination.Upaste:
|
||||
textUploader = new Upaste(Program.UploadersConfig.UpasteUserKey)
|
||||
|
|
Loading…
Reference in a new issue