mirror of
https://github.com/ShareX/ShareX.git
synced 2024-09-30 01:07:21 +13:00
fixed #366: Added PUT, PATCH, DELETE http methods for custom uploader
This commit is contained in:
parent
8333bacd21
commit
620d865ff2
7 changed files with 32 additions and 17 deletions
2
HelpersLib/Properties/Resources.Designer.cs
generated
2
HelpersLib/Properties/Resources.Designer.cs
generated
|
@ -80,7 +80,7 @@ internal static string ActionsCodeMenuEntry_OutputFilePath_File_path_without_ext
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Add image effects.
|
||||
/// Looks up a localized string similar to Add image effects / watermark.
|
||||
/// </summary>
|
||||
internal static string AfterCaptureTasks_AddImageEffects {
|
||||
get {
|
||||
|
|
|
@ -529,7 +529,7 @@ File size: {2:n0} / {3:n0} KB</value>
|
|||
<value>Custom URL shortener</value>
|
||||
</data>
|
||||
<data name="AfterCaptureTasks_AddImageEffects" xml:space="preserve">
|
||||
<value>Add image effects</value>
|
||||
<value>Add image effects / watermark</value>
|
||||
</data>
|
||||
<data name="AfterCaptureTasks_AnnotateImage" xml:space="preserve">
|
||||
<value>Open in image editor</value>
|
||||
|
|
|
@ -507,7 +507,7 @@ Dosya boyutu: {2:n0} / {3:n0} KB</value>
|
|||
<value>Özel adres kısaltıcı</value>
|
||||
</data>
|
||||
<data name="AfterCaptureTasks_AddImageEffects" xml:space="preserve">
|
||||
<value>Resim efekti ekle</value>
|
||||
<value>Resim efekti / filigran ekle</value>
|
||||
</data>
|
||||
<data name="AfterCaptureTasks_AnnotateImage" xml:space="preserve">
|
||||
<value>Resim düzenleyicide aç</value>
|
||||
|
|
|
@ -178,6 +178,7 @@ public enum HttpMethod
|
|||
GET,
|
||||
POST,
|
||||
PUT,
|
||||
PATCH,
|
||||
DELETE
|
||||
}
|
||||
|
||||
|
@ -271,7 +272,10 @@ public enum CustomUploaderType
|
|||
public enum CustomUploaderRequestType
|
||||
{
|
||||
POST,
|
||||
GET
|
||||
GET,
|
||||
PUT,
|
||||
PATCH,
|
||||
DELETE
|
||||
}
|
||||
|
||||
public enum FTPSEncryption
|
||||
|
|
|
@ -62,6 +62,24 @@ public override string ToString()
|
|||
return Name;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
public Dictionary<string, string> ParseArguments(string input = null)
|
||||
{
|
||||
Dictionary<string, string> arguments = new Dictionary<string, string>();
|
||||
|
|
|
@ -44,9 +44,9 @@ public override UploadResult UploadText(string text, string fileName)
|
|||
{
|
||||
if (string.IsNullOrEmpty(customUploader.RequestURL)) throw new Exception("'Request URL' must be not empty.");
|
||||
|
||||
if ((customUploader.RequestType == CustomUploaderRequestType.GET || string.IsNullOrEmpty(customUploader.FileFormName)) &&
|
||||
if ((customUploader.RequestType != CustomUploaderRequestType.POST || string.IsNullOrEmpty(customUploader.FileFormName)) &&
|
||||
(customUploader.Arguments == null || !customUploader.Arguments.Any(x => x.Value.Contains("$input$") || x.Value.Contains("%input"))))
|
||||
throw new Exception("Atleast one '$input$' required for argument value when using GET or non-file POST.");
|
||||
throw new Exception("Atleast one '$input$' required for argument value.");
|
||||
|
||||
UploadResult result = new UploadResult();
|
||||
|
||||
|
@ -67,9 +67,9 @@ public override UploadResult UploadText(string text, string fileName)
|
|||
}
|
||||
}
|
||||
}
|
||||
else if (customUploader.RequestType == CustomUploaderRequestType.GET)
|
||||
else
|
||||
{
|
||||
result.Response = SendRequest(HttpMethod.GET, customUploader.RequestURL, args, responseType: customUploader.ResponseType);
|
||||
result.Response = SendRequest(customUploader.GetHttpMethod(), customUploader.RequestURL, args, responseType: customUploader.ResponseType);
|
||||
}
|
||||
|
||||
customUploader.ParseResponse(result);
|
||||
|
|
|
@ -46,20 +46,13 @@ public override UploadResult ShortenURL(string url)
|
|||
if (string.IsNullOrEmpty(customUploader.RequestURL)) throw new Exception("'Request URL' must be not empty.");
|
||||
|
||||
if (customUploader.Arguments == null || !customUploader.Arguments.Any(x => x.Value.Contains("$input$") || x.Value.Contains("%input")))
|
||||
throw new Exception("Atleast one '$input$' required for argument value when using custom URL shortener.");
|
||||
throw new Exception("Atleast one '$input$' required for argument value.");
|
||||
|
||||
UploadResult result = new UploadResult { URL = url };
|
||||
|
||||
Dictionary<string, string> args = customUploader.ParseArguments(url);
|
||||
|
||||
if (customUploader.RequestType == CustomUploaderRequestType.POST)
|
||||
{
|
||||
result.Response = SendRequest(HttpMethod.POST, customUploader.RequestURL, args, responseType: customUploader.ResponseType);
|
||||
}
|
||||
else if (customUploader.RequestType == CustomUploaderRequestType.GET)
|
||||
{
|
||||
result.Response = SendRequest(HttpMethod.GET, customUploader.RequestURL, args, responseType: customUploader.ResponseType);
|
||||
}
|
||||
result.Response = SendRequest(customUploader.GetHttpMethod(), customUploader.RequestURL, args, responseType: customUploader.ResponseType);
|
||||
|
||||
customUploader.ParseResponse(result, true);
|
||||
|
||||
|
|
Loading…
Reference in a new issue