mirror of
https://github.com/ShareX/ShareX.git
synced 2024-06-30 20:20:34 +12:00
Added $responseurl$ syntax support to custom uploader, which can be used in place of previously removed redirection url response type
This commit is contained in:
parent
58cd13db01
commit
bab795bb57
|
@ -241,11 +241,11 @@ public NameValueCollection GetHeaders(CustomUploaderInput input)
|
|||
return null;
|
||||
}
|
||||
|
||||
public void ParseResponse(UploadResult result, CustomUploaderInput input, bool isShortenedURL = false)
|
||||
public void ParseResponse(UploadResult result, ResponseInfo responseInfo, CustomUploaderInput input, bool isShortenedURL = false)
|
||||
{
|
||||
if (result != null && !string.IsNullOrEmpty(result.Response))
|
||||
if (result != null && responseInfo != null && !string.IsNullOrEmpty(responseInfo.ResponseText))
|
||||
{
|
||||
CustomUploaderParser parser = new CustomUploaderParser(result.Response, RegexList);
|
||||
CustomUploaderParser parser = new CustomUploaderParser(responseInfo, RegexList);
|
||||
parser.Filename = input.Filename;
|
||||
parser.URLEncode = true;
|
||||
|
||||
|
@ -257,7 +257,7 @@ public void ParseResponse(UploadResult result, CustomUploaderInput input, bool i
|
|||
}
|
||||
else
|
||||
{
|
||||
url = parser.Response;
|
||||
url = parser.ResponseInfo.ResponseText;
|
||||
}
|
||||
|
||||
if (isShortenedURL)
|
||||
|
|
|
@ -23,14 +23,12 @@
|
|||
|
||||
#endregion License Information (GPL v3)
|
||||
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using ShareX.HelpersLib;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Security;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Windows.Forms;
|
||||
|
@ -47,7 +45,7 @@ public class CustomUploaderParser
|
|||
public bool IsOutput { get; set; }
|
||||
public string Filename { get; set; }
|
||||
public string Input { get; set; }
|
||||
public string Response { get; set; }
|
||||
public ResponseInfo ResponseInfo { get; set; }
|
||||
public List<Match> RegexMatches { get; set; }
|
||||
public bool URLEncode { get; set; } // Only URL encodes filename and input
|
||||
public bool JSONEncode { get; set; }
|
||||
|
@ -70,9 +68,9 @@ public CustomUploaderParser(string filename, string input)
|
|||
IsOutput = false;
|
||||
}
|
||||
|
||||
public CustomUploaderParser(string response, List<string> regexList)
|
||||
public CustomUploaderParser(ResponseInfo responseInfo, List<string> regexList)
|
||||
{
|
||||
Response = response;
|
||||
ResponseInfo = responseInfo;
|
||||
|
||||
RegexMatches = new List<Match>();
|
||||
|
||||
|
@ -80,7 +78,7 @@ public CustomUploaderParser(string response, List<string> regexList)
|
|||
{
|
||||
foreach (string regex in regexList)
|
||||
{
|
||||
Match match = Regex.Match(response, regex);
|
||||
Match match = Regex.Match(ResponseInfo.ResponseText, regex);
|
||||
RegexMatches.Add(match);
|
||||
}
|
||||
}
|
||||
|
@ -201,7 +199,11 @@ private string ParseSyntax(string syntax, bool isOutput)
|
|||
{
|
||||
if (CheckKeyword(syntax, "response")) // Example: $response$
|
||||
{
|
||||
return Response;
|
||||
return ResponseInfo.ResponseText;
|
||||
}
|
||||
else if (CheckKeyword(syntax, "responseurl")) // Example: $responseurl$
|
||||
{
|
||||
return ResponseInfo.ResponseURL;
|
||||
}
|
||||
else if (CheckKeyword(syntax, "regex", out value)) // Examples: $regex:1$ $regex:1|1$ $regex:1|thumbnail$
|
||||
{
|
||||
|
@ -334,7 +336,12 @@ private string ParseSyntaxJson(string syntaxJsonPath)
|
|||
{
|
||||
if (!string.IsNullOrEmpty(syntaxJsonPath))
|
||||
{
|
||||
return (string)JToken.Parse(Response).SelectToken("$." + syntaxJsonPath);
|
||||
if (!syntaxJsonPath.StartsWith("$."))
|
||||
{
|
||||
syntaxJsonPath = "$." + syntaxJsonPath;
|
||||
}
|
||||
|
||||
return (string)JToken.Parse(ResponseInfo.ResponseText).SelectToken(syntaxJsonPath);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
@ -346,7 +353,7 @@ private string ParseSyntaxXml(string syntaxXPath)
|
|||
{
|
||||
if (!string.IsNullOrEmpty(syntaxXPath))
|
||||
{
|
||||
using (StringReader sr = new StringReader(Response))
|
||||
using (StringReader sr = new StringReader(ResponseInfo.ResponseText))
|
||||
{
|
||||
XPathDocument doc = new XPathDocument(sr);
|
||||
XPathNavigator nav = doc.CreateNavigator();
|
||||
|
|
|
@ -100,7 +100,7 @@ public override UploadResult Upload(Stream stream, string fileName)
|
|||
|
||||
try
|
||||
{
|
||||
uploader.ParseResponse(result, input);
|
||||
uploader.ParseResponse(result, LastResponseInfo, input);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
|
|
@ -97,7 +97,7 @@ public override UploadResult Upload(Stream stream, string fileName)
|
|||
|
||||
try
|
||||
{
|
||||
uploader.ParseResponse(result, input);
|
||||
uploader.ParseResponse(result, LastResponseInfo, input);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
|
|
@ -129,7 +129,7 @@ public override UploadResult UploadText(string text, string fileName)
|
|||
|
||||
try
|
||||
{
|
||||
uploader.ParseResponse(result, input);
|
||||
uploader.ParseResponse(result, LastResponseInfo, input);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
|
|
@ -102,7 +102,7 @@ public override UploadResult ShortenURL(string url)
|
|||
|
||||
try
|
||||
{
|
||||
uploader.ParseResponse(result, input, true);
|
||||
uploader.ParseResponse(result, LastResponseInfo, input, true);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue