2022-01-31 20:39:43 +13:00
|
|
|
|
#region License Information (GPL v3)
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
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
|
2022-01-31 20:39:43 +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)
|
|
|
|
|
|
|
|
|
|
using ShareX.HelpersLib;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
namespace ShareX.UploadersLib
|
|
|
|
|
{
|
2022-04-13 17:12:14 +12:00
|
|
|
|
public class ShareXCustomUploaderSyntaxParser : ShareXSyntaxParser
|
2022-01-31 20:39:43 +13:00
|
|
|
|
{
|
|
|
|
|
private static IEnumerable<CustomUploaderFunction> Functions = Helpers.GetInstances<CustomUploaderFunction>();
|
|
|
|
|
|
|
|
|
|
public string FileName { get; set; }
|
|
|
|
|
public string Input { get; set; }
|
|
|
|
|
public ResponseInfo ResponseInfo { get; set; }
|
|
|
|
|
public bool URLEncode { get; set; } // Only URL encodes file name and input
|
2022-01-31 21:09:40 +13:00
|
|
|
|
public bool UseNameParser { get; set; }
|
|
|
|
|
public NameParserType NameParserType { get; set; } = NameParserType.Text;
|
|
|
|
|
|
2022-04-13 17:12:14 +12:00
|
|
|
|
public ShareXCustomUploaderSyntaxParser()
|
2022-02-01 00:17:12 +13:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-13 17:12:14 +12:00
|
|
|
|
public ShareXCustomUploaderSyntaxParser(CustomUploaderInput input)
|
2022-02-01 00:17:12 +13:00
|
|
|
|
{
|
|
|
|
|
FileName = input.FileName;
|
|
|
|
|
Input = input.Input;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-31 21:09:40 +13:00
|
|
|
|
public override string Parse(string text)
|
|
|
|
|
{
|
|
|
|
|
if (UseNameParser && !string.IsNullOrEmpty(text))
|
|
|
|
|
{
|
|
|
|
|
NameParser nameParser = new NameParser(NameParserType);
|
|
|
|
|
EscapeHelper escapeHelper = new EscapeHelper();
|
|
|
|
|
escapeHelper.KeepEscapeCharacter = true;
|
|
|
|
|
text = escapeHelper.Parse(text, nameParser.Parse);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return base.Parse(text);
|
|
|
|
|
}
|
2022-01-31 20:39:43 +13:00
|
|
|
|
|
2022-04-13 17:47:57 +12:00
|
|
|
|
protected override string CallFunction(string functionName, string[] parameters = null)
|
2022-01-31 20:39:43 +13:00
|
|
|
|
{
|
2022-04-13 17:47:57 +12:00
|
|
|
|
if (string.IsNullOrEmpty(functionName))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Function name cannot be empty.");
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-31 20:39:43 +13:00
|
|
|
|
foreach (CustomUploaderFunction function in Functions)
|
|
|
|
|
{
|
|
|
|
|
if (function.Name.Equals(functionName, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
2022-04-13 23:02:44 +12:00
|
|
|
|
if (function.MinParameterCount > 0 && (parameters == null || parameters.Length < function.MinParameterCount))
|
2022-04-13 18:16:00 +12:00
|
|
|
|
{
|
2022-04-13 23:02:44 +12:00
|
|
|
|
throw new Exception($"Minimum parameter count for function \"{function.Name}\" is {function.MinParameterCount}.");
|
2022-04-13 18:16:00 +12:00
|
|
|
|
}
|
|
|
|
|
|
2022-02-02 14:34:56 +13:00
|
|
|
|
return function.Call(this, parameters);
|
2022-01-31 20:39:43 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
throw new Exception("Invalid function name: " + functionName);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|