From d46e40ce53fbe88f5b90469ba31f286cc7d9daf2 Mon Sep 17 00:00:00 2001 From: Jaex Date: Sun, 10 Jul 2022 08:39:00 +0300 Subject: [PATCH] Added input parameter support to custom uploader json function --- .../Functions/CustomUploaderFunctionJson.cs | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/ShareX.UploadersLib/CustomUploader/Functions/CustomUploaderFunctionJson.cs b/ShareX.UploadersLib/CustomUploader/Functions/CustomUploaderFunctionJson.cs index b02feb091..209dd5a94 100644 --- a/ShareX.UploadersLib/CustomUploader/Functions/CustomUploaderFunctionJson.cs +++ b/ShareX.UploadersLib/CustomUploader/Functions/CustomUploaderFunctionJson.cs @@ -28,6 +28,7 @@ You should have received a copy of the GNU General Public License namespace ShareX.UploadersLib { // Example: {json:files[0].url} + // Example: {json:{response}|files[0].url} internal class CustomUploaderFunctionJson : CustomUploaderFunction { public override string Name { get; } = "json"; @@ -37,16 +38,29 @@ internal class CustomUploaderFunctionJson : CustomUploaderFunction public override string Call(ShareXCustomUploaderSyntaxParser parser, string[] parameters) { // https://goessner.net/articles/JsonPath/ - string jsonPath = parameters[0]; + string input, jsonPath; - if (!string.IsNullOrEmpty(jsonPath)) + // {json:input|jsonPath} + if (parameters.Length > 1) + { + input = parameters[0]; + jsonPath = parameters[1]; + } + else + { + // {json:jsonPath} + input = parser.ResponseInfo.ResponseText; + jsonPath = parameters[0]; + } + + if (!string.IsNullOrEmpty(input) && !string.IsNullOrEmpty(jsonPath)) { if (!jsonPath.StartsWith("$.")) { jsonPath = "$." + jsonPath; } - return (string)JToken.Parse(parser.ResponseInfo.ResponseText).SelectToken(jsonPath); + return (string)JToken.Parse(input).SelectToken(jsonPath); } return null;