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
|
2018-01-02 03:59:14 +13:00
|
|
|
Copyright (c) 2007-2018 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)
|
|
|
|
|
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;
|
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
|
|
|
|
{
|
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
|
|
|
|
|
|
|
[DefaultValue(CustomUploaderRequestType.POST)]
|
2013-11-03 23:53:49 +13:00
|
|
|
public CustomUploaderRequestType RequestType { get; set; }
|
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
|
|
|
|
|
|
|
[DefaultValue("")]
|
2013-11-03 23:53:49 +13:00
|
|
|
public string FileFormName { get; set; }
|
2017-09-06 11:18:36 +12:00
|
|
|
|
|
|
|
[DefaultValue(null)]
|
2017-09-03 12:13:07 +12:00
|
|
|
public Dictionary<string, string> Arguments { get; set; }
|
2017-09-06 11:18:36 +12:00
|
|
|
|
2017-09-06 11:33:02 +12:00
|
|
|
public bool ShouldSerializeArguments() => Arguments != null && Arguments.Count > 0;
|
|
|
|
|
2017-09-06 11:18:36 +12:00
|
|
|
[DefaultValue(null)]
|
2017-09-03 12:13:07 +12:00
|
|
|
public Dictionary<string, string> Headers { get; set; }
|
2017-09-06 11:18:36 +12:00
|
|
|
|
2017-09-06 11:33:02 +12:00
|
|
|
public bool ShouldSerializeHeaders() => Headers != null && Headers.Count > 0;
|
|
|
|
|
2017-09-06 11:18:36 +12:00
|
|
|
[DefaultValue(ResponseType.Text)]
|
2013-11-03 23:53:49 +13:00
|
|
|
public ResponseType ResponseType { get; set; }
|
2017-09-06 11:18:36 +12:00
|
|
|
|
|
|
|
[DefaultValue(null)]
|
2017-09-03 12:13:07 +12:00
|
|
|
public List<string> RegexList { get; set; }
|
2017-09-06 11:18:36 +12:00
|
|
|
|
2017-09-06 11:33:02 +12:00
|
|
|
public bool ShouldSerializeRegexList() => RegexList != null && RegexList.Count > 0;
|
|
|
|
|
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; }
|
|
|
|
|
|
|
|
public CustomUploaderItem()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
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";
|
|
|
|
}
|
|
|
|
|
2014-11-14 09:55:25 +13:00
|
|
|
public HttpMethod GetHttpMethod()
|
|
|
|
{
|
|
|
|
switch (RequestType)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case CustomUploaderRequestType.POST:
|
|
|
|
return HttpMethod.POST;
|
|
|
|
case CustomUploaderRequestType.GET:
|
|
|
|
return HttpMethod.GET;
|
|
|
|
case CustomUploaderRequestType.PUT:
|
|
|
|
return HttpMethod.PUT;
|
|
|
|
case CustomUploaderRequestType.PATCH:
|
|
|
|
return HttpMethod.PATCH;
|
|
|
|
case CustomUploaderRequestType.DELETE:
|
|
|
|
return HttpMethod.DELETE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-29 07:30:55 +12:00
|
|
|
public string GetRequestURL()
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-10-08 19:10:59 +13:00
|
|
|
CustomUploaderParser parser = new CustomUploaderParser();
|
|
|
|
string url = parser.Parse(RequestURL);
|
2017-08-18 06:45:07 +12:00
|
|
|
return URLHelpers.FixPrefix(url);
|
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-02-04 08:21:24 +13:00
|
|
|
public Dictionary<string, string> GetArguments(CustomUploaderArgumentInput 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
|
|
|
{
|
2015-12-23 11:21:19 +13:00
|
|
|
foreach (KeyValuePair<string, string> arg in Arguments)
|
|
|
|
{
|
2018-02-04 08:21:24 +13:00
|
|
|
arguments.Add(arg.Key, input.Parse(arg.Value));
|
2015-12-23 11:21:19 +13:00
|
|
|
}
|
2013-11-03 23:53:49 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
return arguments;
|
|
|
|
}
|
|
|
|
|
2018-02-04 08:21:24 +13:00
|
|
|
public NameValueCollection GetHeaders(CustomUploaderArgumentInput input)
|
2015-10-20 02:26:25 +13:00
|
|
|
{
|
|
|
|
if (Headers != null && Headers.Count > 0)
|
|
|
|
{
|
|
|
|
NameValueCollection collection = new NameValueCollection();
|
|
|
|
|
|
|
|
foreach (KeyValuePair<string, string> header in Headers)
|
|
|
|
{
|
2018-02-04 08:21:24 +13:00
|
|
|
collection.Add(header.Key, input.Parse(header.Value));
|
2015-10-20 02:26:25 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
return collection;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2013-12-08 05:08:38 +13:00
|
|
|
public void ParseResponse(UploadResult result, bool isShortenedURL = false)
|
2013-11-03 23:53:49 +13:00
|
|
|
{
|
2013-12-08 05:08:38 +13:00
|
|
|
if (result != null && !string.IsNullOrEmpty(result.Response))
|
2013-11-03 23:53:49 +13:00
|
|
|
{
|
2018-10-08 19:10:59 +13:00
|
|
|
CustomUploaderParser parser = new CustomUploaderParser(result.Response, RegexList);
|
2013-11-03 23:53:49 +13:00
|
|
|
|
2013-12-08 05:08:38 +13:00
|
|
|
string url;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
2013-12-08 05:08:38 +13:00
|
|
|
if (!string.IsNullOrEmpty(URL))
|
|
|
|
{
|
2018-10-08 19:10:59 +13:00
|
|
|
url = parser.Parse(URL);
|
2013-12-08 05:08:38 +13:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-10-08 19:10:59 +13:00
|
|
|
url = parser.Response;
|
2013-12-08 05:08:38 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
if (isShortenedURL)
|
|
|
|
{
|
|
|
|
result.ShortenedURL = url;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result.URL = url;
|
|
|
|
}
|
|
|
|
|
2018-10-08 19:10:59 +13:00
|
|
|
result.ThumbnailURL = parser.Parse(ThumbnailURL);
|
|
|
|
result.DeletionURL = parser.Parse(DeletionURL);
|
2013-11-03 23:53:49 +13:00
|
|
|
}
|
2013-12-08 05:08:38 +13:00
|
|
|
}
|
2013-11-03 23:53:49 +13:00
|
|
|
}
|
|
|
|
}
|