fixed #1584: Added sli.mg image uploader

This commit is contained in:
Jaex 2016-05-28 12:20:28 +03:00
parent bce1a75aa0
commit 99f2629e4e
5 changed files with 167 additions and 3 deletions

View file

@ -28,11 +28,11 @@ namespace ShareX.UploadersLib
public static partial class APIKeys
{
// Image Uploaders
public static string ImgurClientID = "";
public static string ImgurClientSecret = "";
public static string ImageShackKey = "";
public static string TinyPicID = "";
public static string TinyPicKey = "";
public static string ImgurClientID = "";
public static string ImgurClientSecret = "";
public static string FlickrKey = "";
public static string FlickrSecret = "";
public static string PhotobucketConsumerKey = "";
@ -40,6 +40,8 @@ public static partial class APIKeys
public static string TwitsnapsKey = "";
public static string TwitPicKey = "";
public static string SomeImageKey = "";
public static string SlimgClientID = "";
public static string SlimgClientSecret = "";
// File Uploaders
public static string DropboxConsumerKey = "";

View file

@ -52,6 +52,8 @@ public enum ImageDestination
SomeImage,
[Description("Imgland")]
Imgland,
[Description("SLiMG")]
Slimg,
CustomImageUploader, // Localized
FileUploader // Localized
}

View file

@ -0,0 +1,159 @@
#region License Information (GPL v3)
/*
ShareX - A program that allows you to take screenshots and share any file type
Copyright (c) 2007-2016 ShareX Team
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 Newtonsoft.Json;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
using System.Threading;
namespace ShareX.UploadersLib.ImageUploaders
{
public class SlimgImageUploaderService : ImageUploaderService
{
public override ImageDestination EnumValue { get; } = ImageDestination.Slimg;
public override bool CheckConfig(UploadersConfig config) => true;
public override GenericUploader CreateUploader(UploadersConfig config, TaskReferenceHelper taskInfo)
{
OAuth2Info oauth = new OAuth2Info(APIKeys.SlimgClientID, APIKeys.SlimgClientSecret);
return new Slimg(oauth)
{
UploadMethod = AccountType.Anonymous
};
}
}
public sealed class Slimg : ImageUploader
{
public AccountType UploadMethod { get; set; }
public OAuth2Info AuthInfo { get; set; }
public Slimg(OAuth2Info oauth)
{
AuthInfo = oauth;
}
private NameValueCollection GetAuthHeaders()
{
NameValueCollection headers = new NameValueCollection();
if (UploadMethod == AccountType.Anonymous)
{
headers.Add("Authorization", "Client-ID " + AuthInfo.Client_ID);
}
else if (UploadMethod == AccountType.User)
{
headers.Add("Authorization", "Bearer " + AuthInfo.Token.access_token);
}
return headers;
}
public override UploadResult Upload(Stream stream, string fileName)
{
Dictionary<string, string> arguments = new Dictionary<string, string>();
arguments.Add("type", "binary");
arguments.Add("shared", "false");
UploadResult result = UploadData(stream, "https://api.sli.mg/media", fileName, "data", arguments, GetAuthHeaders());
if (result.IsSuccess)
{
SlimgResponse response = JsonConvert.DeserializeObject<SlimgResponse>(result.Response);
while (response != null && response.success && response.data != null)
{
if (response.data.status == 1)
{
result.URL = response.data.url_direct;
break;
}
else if (response.data.status == 20 || response.data.status == 21)
{
Thread.Sleep(200);
string media_response = SendRequest(HttpMethod.GET, "https://api.sli.mg/media/" + response.data.media_key, headers: GetAuthHeaders());
if (string.IsNullOrEmpty(media_response))
{
break;
}
response = JsonConvert.DeserializeObject<SlimgResponse>(media_response);
}
else
{
break;
}
}
}
return result;
}
public class SlimgResponse
{
public bool success { get; set; }
public int status { get; set; }
public SlimgData data { get; set; }
}
public class SlimgData
{
public string media_key { get; set; }
public string media_secret { get; set; }
public string title { get; set; }
public string description { get; set; }
public string username { get; set; }
public int status { get; set; }
public int created { get; set; }
public string mimetype { get; set; }
public string extension { get; set; }
public int size { get; set; }
public string url { get; set; }
public string url_direct { get; set; }
public bool animated { get; set; }
public bool gifv { get; set; }
public string url_gifv { get; set; }
public bool webm { get; set; }
public string url_webm { get; set; }
public bool mp4 { get; set; }
public string url_mp4 { get; set; }
public int height { get; set; }
public int width { get; set; }
public List<SlimgTag> tags { get; set; }
public string album_key { get; set; }
}
public class SlimgTag
{
public string tag_key { get; set; }
public string url { get; set; }
}
}
}

View file

@ -219,6 +219,7 @@
<Compile Include="Helpers\OAuth\IOAuthBase.cs" />
<Compile Include="Helpers\SSLBypassHelper.cs" />
<Compile Include="BaseServices\URLSharingService.cs" />
<Compile Include="ImageUploaders\Slimg.cs" />
<Compile Include="OtherServices\OCRSpace.cs" />
<Compile Include="SharingServices\DeliciousSharingService.cs" />
<Compile Include="SharingServices\EmailSharingService.cs" />

View file

@ -1430,7 +1430,7 @@ private void niTray_MouseClick(object sender, MouseEventArgs e)
}
else
{
timerTraySingleClick.Interval = (int)(SystemInformation.DoubleClickTime * 1.1);
timerTraySingleClick.Interval = SystemInformation.DoubleClickTime;
timerTraySingleClick.Start();
}
break;