2017-08-18 06:45:07 +12:00
|
|
|
#region License Information (GPL v3)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
|
|
/*
|
|
|
|
ShareX - A program that allows you to take screenshots and share any file type
|
2023-01-10 09:31:02 +13:00
|
|
|
Copyright (c) 2007-2023 ShareX Team
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
2019-01-09 04:57:49 +13:00
|
|
|
using Newtonsoft.Json;
|
2014-12-11 09:25:20 +13:00
|
|
|
using ShareX.HelpersLib;
|
2017-10-29 09:40:50 +13:00
|
|
|
using ShareX.UploadersLib.Properties;
|
2015-06-29 07:30:55 +12:00
|
|
|
using System;
|
2013-11-03 23:53:49 +13:00
|
|
|
using System.Collections.Generic;
|
2015-10-20 02:26:25 +13:00
|
|
|
using System.Collections.Specialized;
|
2017-09-06 11:18:36 +12:00
|
|
|
using System.ComponentModel;
|
2022-02-02 20:54:51 +13:00
|
|
|
using System.Linq;
|
|
|
|
using System.Text;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
2014-12-11 09:25:20 +13:00
|
|
|
namespace ShareX.UploadersLib
|
2013-11-03 23:53:49 +13:00
|
|
|
{
|
|
|
|
public class CustomUploaderItem
|
|
|
|
{
|
2019-01-05 00:37:24 +13:00
|
|
|
[DefaultValue("")]
|
|
|
|
public string Version { get; set; }
|
|
|
|
|
2017-09-06 11:18:36 +12:00
|
|
|
[DefaultValue("")]
|
2017-09-03 12:13:07 +12:00
|
|
|
public string Name { get; set; }
|
2017-09-06 11:18:36 +12:00
|
|
|
|
2017-09-24 20:30:03 +13:00
|
|
|
public bool ShouldSerializeName() => !string.IsNullOrEmpty(Name) && Name != URLHelpers.GetHostName(RequestURL);
|
2017-09-19 12:33:22 +12:00
|
|
|
|
2017-09-06 11:18:36 +12:00
|
|
|
[DefaultValue(CustomUploaderDestinationType.None)]
|
2017-01-23 05:26:17 +13:00
|
|
|
public CustomUploaderDestinationType DestinationType { get; set; }
|
2017-09-06 11:18:36 +12:00
|
|
|
|
2019-02-18 23:34:24 +13:00
|
|
|
[DefaultValue(HttpMethod.POST), JsonProperty(DefaultValueHandling = DefaultValueHandling.Include)]
|
2019-01-09 04:57:49 +13:00
|
|
|
public HttpMethod RequestMethod { get; set; } = HttpMethod.POST;
|
|
|
|
|
|
|
|
// For backward compatibility
|
|
|
|
[JsonProperty]
|
|
|
|
private HttpMethod RequestType { set => RequestMethod = value; }
|
2017-09-06 11:18:36 +12:00
|
|
|
|
|
|
|
[DefaultValue("")]
|
2013-11-03 23:53:49 +13:00
|
|
|
public string RequestURL { get; set; }
|
2017-09-06 11:18:36 +12:00
|
|
|
|
2019-01-06 23:09:01 +13:00
|
|
|
[DefaultValue(null)]
|
|
|
|
public Dictionary<string, string> Parameters { get; set; }
|
|
|
|
|
|
|
|
public bool ShouldSerializeParameters() => Parameters != null && Parameters.Count > 0;
|
|
|
|
|
|
|
|
[DefaultValue(null)]
|
|
|
|
public Dictionary<string, string> Headers { get; set; }
|
|
|
|
|
|
|
|
public bool ShouldSerializeHeaders() => Headers != null && Headers.Count > 0;
|
|
|
|
|
2019-01-09 04:02:21 +13:00
|
|
|
[DefaultValue(CustomUploaderBody.None)]
|
2019-02-20 20:36:44 +13:00
|
|
|
public CustomUploaderBody Body { get; set; }
|
2019-01-09 04:02:21 +13:00
|
|
|
|
|
|
|
[DefaultValue(null)]
|
|
|
|
public Dictionary<string, string> Arguments { get; set; }
|
|
|
|
|
|
|
|
public bool ShouldSerializeArguments() => (Body == CustomUploaderBody.MultipartFormData || Body == CustomUploaderBody.FormURLEncoded) &&
|
|
|
|
Arguments != null && Arguments.Count > 0;
|
2018-11-22 03:16:14 +13:00
|
|
|
|
2017-09-06 11:18:36 +12:00
|
|
|
[DefaultValue("")]
|
2013-11-03 23:53:49 +13:00
|
|
|
public string FileFormName { get; set; }
|
2017-09-06 11:18:36 +12:00
|
|
|
|
2019-01-09 04:02:21 +13:00
|
|
|
public bool ShouldSerializeFileFormName() => Body == CustomUploaderBody.MultipartFormData && !string.IsNullOrEmpty(FileFormName);
|
2018-11-25 07:18:43 +13:00
|
|
|
|
2018-11-22 05:48:04 +13:00
|
|
|
[DefaultValue("")]
|
|
|
|
public string Data { get; set; }
|
|
|
|
|
2019-01-10 05:08:55 +13:00
|
|
|
public bool ShouldSerializeData() => (Body == CustomUploaderBody.JSON || Body == CustomUploaderBody.XML) && !string.IsNullOrEmpty(Data);
|
2017-09-06 11:33:02 +12:00
|
|
|
|
2019-01-22 01:37:31 +13:00
|
|
|
// For backward compatibility
|
2019-01-22 04:09:23 +13:00
|
|
|
public ResponseType ResponseType { private get; set; }
|
2017-09-06 11:18:36 +12:00
|
|
|
|
|
|
|
[DefaultValue("")]
|
2013-11-03 23:53:49 +13:00
|
|
|
public string URL { get; set; }
|
2017-09-06 11:18:36 +12:00
|
|
|
|
|
|
|
[DefaultValue("")]
|
2013-11-03 23:53:49 +13:00
|
|
|
public string ThumbnailURL { get; set; }
|
2017-09-06 11:18:36 +12:00
|
|
|
|
|
|
|
[DefaultValue("")]
|
2013-11-03 23:53:49 +13:00
|
|
|
public string DeletionURL { get; set; }
|
|
|
|
|
2020-09-22 18:53:01 +12:00
|
|
|
[DefaultValue("")]
|
|
|
|
public string ErrorMessage { get; set; }
|
|
|
|
|
2019-02-20 20:36:44 +13:00
|
|
|
private CustomUploaderItem()
|
2013-11-03 23:53:49 +13:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-02-20 20:36:44 +13:00
|
|
|
public static CustomUploaderItem Init()
|
|
|
|
{
|
|
|
|
return new CustomUploaderItem()
|
|
|
|
{
|
2023-03-06 08:16:45 +13:00
|
|
|
Version = Helpers.GetApplicationVersion(),
|
2019-02-20 20:36:44 +13:00
|
|
|
RequestMethod = HttpMethod.POST,
|
|
|
|
Body = CustomUploaderBody.MultipartFormData
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2013-11-03 23:53:49 +13:00
|
|
|
public override string ToString()
|
|
|
|
{
|
2017-09-24 20:30:03 +13:00
|
|
|
if (!string.IsNullOrEmpty(Name))
|
2017-09-06 11:18:36 +12:00
|
|
|
{
|
2017-09-24 20:30:03 +13:00
|
|
|
return Name;
|
2017-09-06 11:18:36 +12:00
|
|
|
}
|
|
|
|
|
2017-09-24 20:30:03 +13:00
|
|
|
string name = URLHelpers.GetHostName(RequestURL);
|
2013-11-03 23:53:49 +13:00
|
|
|
|
2017-09-24 20:30:03 +13:00
|
|
|
if (!string.IsNullOrEmpty(name))
|
2017-09-19 12:33:22 +12:00
|
|
|
{
|
2017-09-24 20:30:03 +13:00
|
|
|
return name;
|
2017-09-19 12:33:22 +12:00
|
|
|
}
|
|
|
|
|
2017-09-24 20:30:03 +13:00
|
|
|
return "Name";
|
2017-09-19 12:33:22 +12:00
|
|
|
}
|
|
|
|
|
2018-01-02 20:38:28 +13:00
|
|
|
public string GetFileName()
|
|
|
|
{
|
|
|
|
return ToString() + ".sxcu";
|
|
|
|
}
|
|
|
|
|
2018-11-25 09:23:18 +13:00
|
|
|
public string GetRequestURL(CustomUploaderInput input)
|
2015-06-29 07:30:55 +12:00
|
|
|
{
|
|
|
|
if (string.IsNullOrEmpty(RequestURL))
|
|
|
|
{
|
2017-10-29 09:40:50 +13:00
|
|
|
throw new Exception(Resources.CustomUploaderItem_GetRequestURL_RequestURLMustBeConfigured);
|
2015-06-29 07:30:55 +12:00
|
|
|
}
|
|
|
|
|
2022-04-13 17:12:14 +12:00
|
|
|
ShareXCustomUploaderSyntaxParser parser = new ShareXCustomUploaderSyntaxParser(input);
|
2019-01-09 03:35:17 +13:00
|
|
|
parser.URLEncode = true;
|
|
|
|
string url = parser.Parse(RequestURL);
|
2019-01-07 05:04:40 +13:00
|
|
|
|
2019-01-09 03:35:17 +13:00
|
|
|
url = URLHelpers.FixPrefix(url);
|
2019-01-07 05:04:40 +13:00
|
|
|
|
2019-01-09 03:35:17 +13:00
|
|
|
Dictionary<string, string> parameters = GetParameters(input);
|
2019-01-07 05:04:40 +13:00
|
|
|
return URLHelpers.CreateQueryString(url, parameters);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Dictionary<string, string> GetParameters(CustomUploaderInput input)
|
|
|
|
{
|
|
|
|
Dictionary<string, string> parameters = new Dictionary<string, string>();
|
|
|
|
|
|
|
|
if (Parameters != null)
|
|
|
|
{
|
2022-04-13 17:12:14 +12:00
|
|
|
ShareXCustomUploaderSyntaxParser parser = new ShareXCustomUploaderSyntaxParser(input);
|
2019-01-07 05:04:40 +13:00
|
|
|
parser.UseNameParser = true;
|
|
|
|
|
|
|
|
foreach (KeyValuePair<string, string> parameter in Parameters)
|
|
|
|
{
|
|
|
|
parameters.Add(parameter.Key, parser.Parse(parameter.Value));
|
|
|
|
}
|
|
|
|
}
|
2018-11-29 02:14:19 +13:00
|
|
|
|
2019-01-07 05:04:40 +13:00
|
|
|
return parameters;
|
2015-06-29 07:30:55 +12:00
|
|
|
}
|
|
|
|
|
2019-01-10 05:08:55 +13:00
|
|
|
public string GetContentType()
|
|
|
|
{
|
|
|
|
switch (Body)
|
|
|
|
{
|
2019-01-17 20:57:50 +13:00
|
|
|
case CustomUploaderBody.MultipartFormData:
|
2019-03-15 00:06:54 +13:00
|
|
|
return RequestHelpers.ContentTypeMultipartFormData;
|
2019-01-17 20:57:50 +13:00
|
|
|
case CustomUploaderBody.FormURLEncoded:
|
2019-03-15 00:06:54 +13:00
|
|
|
return RequestHelpers.ContentTypeURLEncoded;
|
2019-01-10 05:08:55 +13:00
|
|
|
case CustomUploaderBody.JSON:
|
2019-03-15 00:06:54 +13:00
|
|
|
return RequestHelpers.ContentTypeJSON;
|
2019-01-10 05:08:55 +13:00
|
|
|
case CustomUploaderBody.XML:
|
2019-03-15 00:06:54 +13:00
|
|
|
return RequestHelpers.ContentTypeXML;
|
2019-01-17 20:57:50 +13:00
|
|
|
case CustomUploaderBody.Binary:
|
2019-03-15 00:06:54 +13:00
|
|
|
return RequestHelpers.ContentTypeOctetStream;
|
2019-01-10 05:08:55 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2018-11-25 09:23:18 +13:00
|
|
|
public string GetData(CustomUploaderInput input)
|
2018-11-22 07:05:39 +13:00
|
|
|
{
|
2022-02-02 14:34:56 +13:00
|
|
|
NameParser nameParser = new NameParser(NameParserType.Text);
|
|
|
|
string result = nameParser.Parse(Data);
|
|
|
|
|
|
|
|
Dictionary<string, string> replace = new Dictionary<string, string>();
|
|
|
|
replace.Add("{input}", EncodeBodyData(input.Input));
|
|
|
|
replace.Add("{filename}", EncodeBodyData(input.FileName));
|
|
|
|
result = result.BatchReplace(replace, StringComparison.OrdinalIgnoreCase);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
private string EncodeBodyData(string input)
|
|
|
|
{
|
|
|
|
if (!string.IsNullOrEmpty(input))
|
|
|
|
{
|
|
|
|
if (Body == CustomUploaderBody.JSON)
|
|
|
|
{
|
|
|
|
return URLHelpers.JSONEncode(input);
|
|
|
|
}
|
|
|
|
else if (Body == CustomUploaderBody.XML)
|
|
|
|
{
|
|
|
|
return URLHelpers.XMLEncode(input);
|
|
|
|
}
|
|
|
|
}
|
2018-11-25 09:23:18 +13:00
|
|
|
|
2022-02-02 14:34:56 +13:00
|
|
|
return input;
|
2018-11-22 07:05:39 +13:00
|
|
|
}
|
|
|
|
|
2015-06-29 07:30:55 +12:00
|
|
|
public string GetFileFormName()
|
|
|
|
{
|
|
|
|
if (string.IsNullOrEmpty(FileFormName))
|
|
|
|
{
|
2017-10-29 09:40:50 +13:00
|
|
|
throw new Exception(Resources.CustomUploaderItem_GetFileFormName_FileFormNameMustBeConfigured);
|
2015-06-29 07:30:55 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
return FileFormName;
|
|
|
|
}
|
|
|
|
|
2018-11-25 09:23:18 +13:00
|
|
|
public Dictionary<string, string> GetArguments(CustomUploaderInput input)
|
2013-11-03 23:53:49 +13:00
|
|
|
{
|
|
|
|
Dictionary<string, string> arguments = new Dictionary<string, string>();
|
|
|
|
|
2015-12-23 11:21:19 +13:00
|
|
|
if (Arguments != null)
|
2013-11-03 23:53:49 +13:00
|
|
|
{
|
2022-04-13 17:12:14 +12:00
|
|
|
ShareXCustomUploaderSyntaxParser parser = new ShareXCustomUploaderSyntaxParser(input);
|
2018-11-25 09:23:18 +13:00
|
|
|
parser.UseNameParser = true;
|
|
|
|
|
2015-12-23 11:21:19 +13:00
|
|
|
foreach (KeyValuePair<string, string> arg in Arguments)
|
|
|
|
{
|
2018-11-25 09:23:18 +13:00
|
|
|
arguments.Add(arg.Key, parser.Parse(arg.Value));
|
2015-12-23 11:21:19 +13:00
|
|
|
}
|
2013-11-03 23:53:49 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
return arguments;
|
|
|
|
}
|
|
|
|
|
2018-11-25 09:23:18 +13:00
|
|
|
public NameValueCollection GetHeaders(CustomUploaderInput input)
|
2015-10-20 02:26:25 +13:00
|
|
|
{
|
|
|
|
if (Headers != null && Headers.Count > 0)
|
|
|
|
{
|
|
|
|
NameValueCollection collection = new NameValueCollection();
|
2018-11-29 02:14:19 +13:00
|
|
|
|
2022-04-13 17:12:14 +12:00
|
|
|
ShareXCustomUploaderSyntaxParser parser = new ShareXCustomUploaderSyntaxParser(input);
|
2018-11-25 09:23:18 +13:00
|
|
|
parser.UseNameParser = true;
|
2015-10-20 02:26:25 +13:00
|
|
|
|
|
|
|
foreach (KeyValuePair<string, string> header in Headers)
|
|
|
|
{
|
2018-11-25 09:23:18 +13:00
|
|
|
collection.Add(header.Key, parser.Parse(header.Value));
|
2015-10-20 02:26:25 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
return collection;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2022-10-05 22:17:20 +13:00
|
|
|
public void ParseResponse(UploadResult result, ResponseInfo responseInfo, UploaderErrorManager errors, CustomUploaderInput input, bool isShortenedURL = false)
|
2013-11-03 23:53:49 +13:00
|
|
|
{
|
2019-01-31 13:50:01 +13:00
|
|
|
if (result != null && responseInfo != null)
|
2013-11-03 23:53:49 +13:00
|
|
|
{
|
2019-01-31 13:50:01 +13:00
|
|
|
result.ResponseInfo = responseInfo;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
2020-09-22 19:16:39 +12:00
|
|
|
if (responseInfo.ResponseText == null)
|
2013-12-08 05:08:38 +13:00
|
|
|
{
|
2020-09-22 19:16:39 +12:00
|
|
|
responseInfo.ResponseText = "";
|
|
|
|
}
|
2019-03-01 02:34:04 +13:00
|
|
|
|
2022-04-13 17:12:14 +12:00
|
|
|
ShareXCustomUploaderSyntaxParser parser = new ShareXCustomUploaderSyntaxParser()
|
2022-01-31 15:10:10 +13:00
|
|
|
{
|
|
|
|
FileName = input.FileName,
|
|
|
|
ResponseInfo = responseInfo,
|
|
|
|
URLEncode = true
|
|
|
|
};
|
2019-01-31 13:50:01 +13:00
|
|
|
|
2020-09-22 19:16:39 +12:00
|
|
|
if (responseInfo.IsSuccess)
|
|
|
|
{
|
2019-01-31 13:50:01 +13:00
|
|
|
string url;
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(URL))
|
|
|
|
{
|
|
|
|
url = parser.Parse(URL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
url = parser.ResponseInfo.ResponseText;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isShortenedURL)
|
|
|
|
{
|
|
|
|
result.ShortenedURL = url;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result.URL = url;
|
|
|
|
}
|
|
|
|
|
|
|
|
result.ThumbnailURL = parser.Parse(ThumbnailURL);
|
|
|
|
result.DeletionURL = parser.Parse(DeletionURL);
|
2013-12-08 05:08:38 +13:00
|
|
|
}
|
2020-09-22 19:16:39 +12:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!string.IsNullOrEmpty(ErrorMessage))
|
|
|
|
{
|
2020-09-22 19:36:12 +12:00
|
|
|
string parsedErrorMessage = parser.Parse(ErrorMessage);
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(parsedErrorMessage))
|
|
|
|
{
|
2022-10-05 22:17:20 +13:00
|
|
|
errors.AddFirst(parsedErrorMessage);
|
2020-09-22 19:36:12 +12:00
|
|
|
}
|
2020-09-22 19:16:39 +12:00
|
|
|
}
|
|
|
|
}
|
2013-11-03 23:53:49 +13:00
|
|
|
}
|
2013-12-08 05:08:38 +13:00
|
|
|
}
|
2019-01-05 00:37:24 +13:00
|
|
|
|
2022-10-05 22:17:20 +13:00
|
|
|
public void TryParseResponse(UploadResult result, ResponseInfo responseInfo, UploaderErrorManager errors, CustomUploaderInput input, bool isShortenedURL = false)
|
2021-07-04 01:10:10 +12:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2022-10-05 22:17:20 +13:00
|
|
|
ParseResponse(result, responseInfo, errors, input, isShortenedURL);
|
2021-07-04 01:10:10 +12:00
|
|
|
}
|
|
|
|
catch (JsonReaderException e)
|
|
|
|
{
|
2021-07-04 01:43:12 +12:00
|
|
|
string hostName = URLHelpers.GetHostName(RequestURL);
|
2022-10-05 22:17:20 +13:00
|
|
|
errors.AddFirst($"Invalid response content is returned from host ({hostName}), expected response content is JSON." +
|
2021-07-04 01:43:12 +12:00
|
|
|
Environment.NewLine + Environment.NewLine + e);
|
2021-07-04 01:10:10 +12:00
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
2021-07-04 01:43:12 +12:00
|
|
|
string hostName = URLHelpers.GetHostName(RequestURL);
|
2022-10-05 22:17:20 +13:00
|
|
|
errors.AddFirst($"Unable to parse response content returned from host ({hostName})." +
|
2021-07-04 01:43:12 +12:00
|
|
|
Environment.NewLine + Environment.NewLine + e);
|
2021-07-04 01:10:10 +12:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-05 00:37:24 +13:00
|
|
|
public void CheckBackwardCompatibility()
|
|
|
|
{
|
2019-01-09 03:35:17 +13:00
|
|
|
CheckRequestURL();
|
|
|
|
|
2019-01-05 00:37:24 +13:00
|
|
|
if (string.IsNullOrEmpty(Version) || Helpers.CompareVersion(Version, "12.3.1") <= 0)
|
|
|
|
{
|
2019-01-09 04:57:49 +13:00
|
|
|
if (RequestMethod == HttpMethod.POST)
|
2019-01-05 00:37:24 +13:00
|
|
|
{
|
2019-01-09 04:02:21 +13:00
|
|
|
Body = CustomUploaderBody.MultipartFormData;
|
2019-01-05 00:37:24 +13:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-01-09 04:02:21 +13:00
|
|
|
Body = CustomUploaderBody.None;
|
2019-01-07 00:47:37 +13:00
|
|
|
|
|
|
|
if (Arguments != null)
|
|
|
|
{
|
2019-02-18 23:08:21 +13:00
|
|
|
if (Parameters == null)
|
|
|
|
{
|
|
|
|
Parameters = new Dictionary<string, string>();
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (KeyValuePair<string, string> pair in Arguments)
|
|
|
|
{
|
|
|
|
if (!Parameters.ContainsKey(pair.Key))
|
|
|
|
{
|
|
|
|
Parameters.Add(pair.Key, pair.Value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-07 00:47:37 +13:00
|
|
|
Arguments = null;
|
|
|
|
}
|
|
|
|
}
|
2019-01-22 04:09:23 +13:00
|
|
|
|
|
|
|
if (ResponseType == ResponseType.RedirectionURL)
|
|
|
|
{
|
|
|
|
if (string.IsNullOrEmpty(URL))
|
|
|
|
{
|
|
|
|
URL = "$responseurl$";
|
|
|
|
}
|
|
|
|
|
|
|
|
URL = URL.Replace("$response$", "$responseurl$");
|
|
|
|
ThumbnailURL = ThumbnailURL?.Replace("$response$", "$responseurl$");
|
|
|
|
DeletionURL = DeletionURL?.Replace("$response$", "$responseurl$");
|
|
|
|
}
|
|
|
|
else if (ResponseType == ResponseType.Headers)
|
|
|
|
{
|
|
|
|
URL = "Response type option is deprecated, please use \\$header:header_name\\$ syntax instead.";
|
|
|
|
}
|
|
|
|
else if (ResponseType == ResponseType.LocationHeader)
|
|
|
|
{
|
|
|
|
if (string.IsNullOrEmpty(URL))
|
|
|
|
{
|
|
|
|
URL = "$header:Location$";
|
|
|
|
}
|
|
|
|
|
|
|
|
URL = URL.Replace("$response$", "$header:Location$");
|
|
|
|
ThumbnailURL = ThumbnailURL?.Replace("$response$", "$header:Location$");
|
|
|
|
DeletionURL = DeletionURL?.Replace("$response$", "$header:Location$");
|
|
|
|
}
|
|
|
|
|
|
|
|
ResponseType = ResponseType.Text;
|
2019-01-09 03:35:17 +13:00
|
|
|
|
2022-02-02 20:54:51 +13:00
|
|
|
Version = "13.7.1";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Helpers.CompareVersion(Version, "13.7.1") <= 0)
|
|
|
|
{
|
|
|
|
RequestURL = MigrateOldSyntax(RequestURL);
|
|
|
|
|
|
|
|
if (Parameters != null)
|
|
|
|
{
|
|
|
|
foreach (string key in Parameters.Keys.ToList())
|
|
|
|
{
|
|
|
|
Parameters[key] = MigrateOldSyntax(Parameters[key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Headers != null)
|
|
|
|
{
|
|
|
|
foreach (string key in Headers.Keys.ToList())
|
|
|
|
{
|
|
|
|
Headers[key] = MigrateOldSyntax(Headers[key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Arguments != null)
|
|
|
|
{
|
|
|
|
foreach (string key in Arguments.Keys.ToList())
|
|
|
|
{
|
|
|
|
Arguments[key] = MigrateOldSyntax(Arguments[key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-04 02:16:44 +13:00
|
|
|
Data = Data.Replace("$input$", "{input}", StringComparison.OrdinalIgnoreCase).
|
|
|
|
Replace("$filename$", "{filename}", StringComparison.OrdinalIgnoreCase);
|
2022-02-02 20:54:51 +13:00
|
|
|
URL = MigrateOldSyntax(URL);
|
|
|
|
ThumbnailURL = MigrateOldSyntax(ThumbnailURL);
|
|
|
|
DeletionURL = MigrateOldSyntax(DeletionURL);
|
|
|
|
ErrorMessage = MigrateOldSyntax(ErrorMessage);
|
|
|
|
|
2023-03-06 08:16:45 +13:00
|
|
|
Version = Helpers.GetApplicationVersion();
|
2019-03-05 07:11:37 +13:00
|
|
|
}
|
2019-01-09 03:35:17 +13:00
|
|
|
}
|
|
|
|
|
2022-02-02 20:54:51 +13:00
|
|
|
private string MigrateOldSyntax(string input)
|
|
|
|
{
|
|
|
|
if (string.IsNullOrEmpty(input))
|
|
|
|
{
|
|
|
|
return input;
|
|
|
|
}
|
|
|
|
|
2022-02-02 22:57:10 +13:00
|
|
|
StringBuilder sbInput = new StringBuilder();
|
2022-02-02 20:54:51 +13:00
|
|
|
|
|
|
|
bool start = true;
|
|
|
|
|
|
|
|
for (int i = 0; i < input.Length; i++)
|
|
|
|
{
|
|
|
|
if (input[i] == '$')
|
|
|
|
{
|
2022-02-02 22:57:10 +13:00
|
|
|
sbInput.Append(start ? '{' : '}');
|
2022-02-02 20:54:51 +13:00
|
|
|
start = !start;
|
2022-02-02 22:57:10 +13:00
|
|
|
continue;
|
2022-02-02 20:54:51 +13:00
|
|
|
}
|
|
|
|
else if (input[i] == '\\')
|
|
|
|
{
|
|
|
|
i++;
|
2022-02-02 22:57:10 +13:00
|
|
|
continue;
|
2022-02-02 20:54:51 +13:00
|
|
|
}
|
2022-02-02 22:57:10 +13:00
|
|
|
else if (input[i] == '{' || input[i] == '}')
|
|
|
|
{
|
|
|
|
sbInput.Append('\\');
|
|
|
|
}
|
|
|
|
|
|
|
|
sbInput.Append(input[i]);
|
2022-02-02 20:54:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
return sbInput.ToString();
|
|
|
|
}
|
|
|
|
|
2019-01-09 03:35:17 +13:00
|
|
|
private void CheckRequestURL()
|
|
|
|
{
|
|
|
|
if (!string.IsNullOrEmpty(RequestURL))
|
|
|
|
{
|
2019-01-07 00:47:37 +13:00
|
|
|
NameValueCollection nvc = URLHelpers.ParseQueryString(RequestURL);
|
2019-01-09 03:35:17 +13:00
|
|
|
|
2019-01-07 00:47:37 +13:00
|
|
|
if (nvc != null && nvc.Count > 0)
|
|
|
|
{
|
|
|
|
if (Parameters == null)
|
|
|
|
{
|
|
|
|
Parameters = new Dictionary<string, string>();
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (string key in nvc)
|
|
|
|
{
|
|
|
|
if (key == null)
|
|
|
|
{
|
2019-01-09 09:22:41 +13:00
|
|
|
foreach (string value in nvc.GetValues(key))
|
2019-01-07 00:47:37 +13:00
|
|
|
{
|
2019-01-09 09:22:41 +13:00
|
|
|
if (!Parameters.ContainsKey(value))
|
|
|
|
{
|
|
|
|
Parameters.Add(value, "");
|
|
|
|
}
|
2019-01-07 00:47:37 +13:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (!Parameters.ContainsKey(key))
|
|
|
|
{
|
2019-01-09 09:22:41 +13:00
|
|
|
string value = nvc[key];
|
2019-01-07 00:47:37 +13:00
|
|
|
Parameters.Add(key, value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RequestURL = URLHelpers.RemoveQueryString(RequestURL);
|
2019-01-05 00:37:24 +13:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-11-03 23:53:49 +13:00
|
|
|
}
|
|
|
|
}
|