2015-08-03 06:46:02 +12:00
|
|
|
|
#region License Information (GPL v3)
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
ShareX - A program that allows you to take screenshots and share any file type
|
2016-01-04 04:16:01 +13:00
|
|
|
|
Copyright (c) 2007-2016 ShareX Team
|
2015-08-03 06:46:02 +12: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)
|
|
|
|
|
|
2015-09-17 20:37:58 +12:00
|
|
|
|
// Credits: https://github.com/DanielMcAssey
|
|
|
|
|
|
2016-02-15 19:53:30 +13:00
|
|
|
|
using Newtonsoft.Json;
|
2016-06-28 05:20:55 +12:00
|
|
|
|
using ShareX.UploadersLib.Properties;
|
2016-02-15 01:48:35 +13:00
|
|
|
|
using System;
|
2015-08-03 06:46:02 +12:00
|
|
|
|
using System.Collections.Generic;
|
2016-06-28 05:20:55 +12:00
|
|
|
|
using System.Drawing;
|
2015-08-03 06:46:02 +12:00
|
|
|
|
using System.IO;
|
2016-04-30 09:47:33 +12:00
|
|
|
|
using System.Windows.Forms;
|
2015-08-03 06:46:02 +12:00
|
|
|
|
|
|
|
|
|
namespace ShareX.UploadersLib.ImageUploaders
|
|
|
|
|
{
|
2016-03-23 05:11:01 +13:00
|
|
|
|
public class SomeImageImageUploaderService : ImageUploaderService
|
|
|
|
|
{
|
|
|
|
|
public override ImageDestination EnumValue { get; } = ImageDestination.SomeImage;
|
|
|
|
|
|
2016-06-28 05:20:55 +12:00
|
|
|
|
public override Icon ServiceIcon => Resources.SomeImage;
|
|
|
|
|
|
2016-03-24 07:47:59 +13:00
|
|
|
|
public override bool CheckConfig(UploadersConfig config) => true;
|
2016-03-23 05:11:01 +13:00
|
|
|
|
|
2016-04-04 21:53:11 +12:00
|
|
|
|
public override GenericUploader CreateUploader(UploadersConfig config, TaskReferenceHelper taskInfo)
|
2016-03-23 05:11:01 +13:00
|
|
|
|
{
|
2016-03-24 07:47:59 +13:00
|
|
|
|
string someImageAPIKey = config.SomeImageAPIKey;
|
2016-03-23 05:11:01 +13:00
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(someImageAPIKey))
|
|
|
|
|
{
|
|
|
|
|
someImageAPIKey = APIKeys.SomeImageKey;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new SomeImage(someImageAPIKey)
|
|
|
|
|
{
|
2016-03-24 07:47:59 +13:00
|
|
|
|
DirectURL = config.SomeImageDirectURL
|
2016-03-23 05:11:01 +13:00
|
|
|
|
};
|
|
|
|
|
}
|
2016-04-30 09:47:33 +12:00
|
|
|
|
|
|
|
|
|
public override TabPage GetUploadersConfigTabPage(UploadersConfigForm form) => form.tpSomeImage;
|
2016-03-23 05:11:01 +13:00
|
|
|
|
}
|
|
|
|
|
|
2015-08-03 06:46:02 +12:00
|
|
|
|
public sealed class SomeImage : ImageUploader
|
|
|
|
|
{
|
|
|
|
|
private const string API_ENDPOINT = "https://someimage.com/api/2/image/upload";
|
|
|
|
|
|
2016-02-15 19:53:30 +13:00
|
|
|
|
public string API_KEY { get; set; }
|
2016-02-15 01:12:53 +13:00
|
|
|
|
public bool DirectURL { get; set; }
|
|
|
|
|
|
2015-08-03 06:46:02 +12:00
|
|
|
|
public SomeImage(string apiKey)
|
|
|
|
|
{
|
|
|
|
|
API_KEY = apiKey;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override UploadResult Upload(Stream stream, string fileName)
|
|
|
|
|
{
|
|
|
|
|
Dictionary<string, string> arguments = new Dictionary<string, string>();
|
|
|
|
|
arguments.Add("apikey", API_KEY);
|
|
|
|
|
arguments.Add("familysafe", "0"); // Set to 0 as images could possibly not be family safe.
|
|
|
|
|
|
|
|
|
|
UploadResult result = UploadData(stream, API_ENDPOINT, fileName, "file", arguments);
|
|
|
|
|
|
|
|
|
|
if (result.IsSuccess)
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrEmpty(result.Response))
|
|
|
|
|
{
|
|
|
|
|
SomeImageResponse jsonResponse = JsonConvert.DeserializeObject<SomeImageResponse>(result.Response);
|
|
|
|
|
|
|
|
|
|
if (jsonResponse != null)
|
|
|
|
|
{
|
2016-02-15 01:48:35 +13:00
|
|
|
|
if (DirectURL)
|
|
|
|
|
{
|
2016-02-15 19:53:30 +13:00
|
|
|
|
if (!string.IsNullOrEmpty(jsonResponse.imagelink))
|
2016-02-15 01:48:35 +13:00
|
|
|
|
{
|
|
|
|
|
Uri responseUri = new Uri(jsonResponse.imagelink); // http://someimage.com/asdf
|
|
|
|
|
string host = responseUri.Host; // someimage.com
|
|
|
|
|
string filename = Path.GetFileName(responseUri.AbsolutePath); // /asdf
|
|
|
|
|
if (filename.StartsWith("/"))
|
|
|
|
|
{
|
|
|
|
|
filename = filename.Remove(0, 1); // asdf
|
|
|
|
|
}
|
|
|
|
|
if (host.StartsWith("www."))
|
|
|
|
|
{
|
|
|
|
|
host = host.Remove(0, 4);
|
|
|
|
|
}
|
2016-02-15 20:02:33 +13:00
|
|
|
|
string extension = Path.GetExtension(fileName);
|
2016-02-15 19:53:30 +13:00
|
|
|
|
result.URL = $"https://i1.{host}/{filename}{extension}";
|
2016-02-15 01:48:35 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
result.URL = jsonResponse.imagelink;
|
|
|
|
|
}
|
2015-08-03 06:46:02 +12:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-19 02:43:40 +13:00
|
|
|
|
public class SomeImageResponse
|
|
|
|
|
{
|
|
|
|
|
public string success { get; set; }
|
|
|
|
|
public string imageid { get; set; }
|
|
|
|
|
public string imagelink { get; set; }
|
|
|
|
|
public string thumblink { get; set; }
|
|
|
|
|
public string embedhtml { get; set; }
|
|
|
|
|
public string embedbb { get; set; }
|
|
|
|
|
}
|
2016-02-15 01:48:35 +13:00
|
|
|
|
}
|