ShareX/ShareX.UploadersLib/FileUploaders/Lithiio.cs

101 lines
3.2 KiB
C#
Raw Normal View History

#region License Information (GPL v3)
/*
ShareX - A program that allows you to take screenshots and share any file type
2017-01-11 21:39:40 +13:00
Copyright (c) 2007-2017 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)
2016-05-16 00:22:13 +12:00
// Credits: https://github.com/lithium720
using Newtonsoft.Json;
2016-06-28 05:20:55 +12:00
using ShareX.UploadersLib.Properties;
using System.Collections.Generic;
2016-06-28 05:20:55 +12:00
using System.Drawing;
using System.IO;
using System.Windows.Forms;
namespace ShareX.UploadersLib.FileUploaders
{
public class LithiioFileUploaderService : FileUploaderService
{
public override FileDestination EnumValue { get; } = FileDestination.Lithiio;
2016-06-28 05:20:55 +12:00
public override Icon ServiceIcon => Resources.Lithiio;
public override bool CheckConfig(UploadersConfig config)
{
2016-07-23 17:15:46 +12:00
return config.LithiioSettings != null && !string.IsNullOrEmpty(config.LithiioSettings.UserAPIKey);
}
public override GenericUploader CreateUploader(UploadersConfig config, TaskReferenceHelper taskInfo)
{
return new Lithiio(config.LithiioSettings);
}
public override TabPage GetUploadersConfigTabPage(UploadersConfigForm form) => form.tpLithiio;
}
public sealed class Lithiio : FileUploader
{
public LithiioSettings Config { get; private set; }
public Lithiio(LithiioSettings config)
{
Config = config;
}
public override UploadResult Upload(Stream stream, string fileName)
{
Dictionary<string, string> arguments = new Dictionary<string, string>();
arguments.Add("key", Config.UserAPIKey);
UploadResult result = SendRequestFile("https://upload.lithi.io/v1.php", stream, fileName, "file", arguments);
if (result.IsSuccess)
{
LithiioResponse response = JsonConvert.DeserializeObject<LithiioResponse>(result.Response);
if (response.Success)
{
result.URL = response.URL;
}
else
{
Errors.Add(response.Error);
}
}
return result;
}
public class LithiioResponse
{
public bool Success { get; set; }
public string URL { get; set; }
public string Error { get; set; }
}
}
public class LithiioSettings
{
2016-05-25 06:15:45 +12:00
public string UserAPIKey { get; set; } = "";
}
2016-05-25 06:15:45 +12:00
}