mirror of
https://github.com/ShareX/ShareX.git
synced 2024-08-20 04:32:00 +12:00
140 lines
No EOL
4.3 KiB
C#
140 lines
No EOL
4.3 KiB
C#
#region License Information (GPL v3)
|
|
|
|
/*
|
|
ShareX - A program that allows you to take screenshots and share any file type
|
|
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)
|
|
|
|
// Credits: https://github.com/lithium720
|
|
|
|
using Newtonsoft.Json;
|
|
using ShareX.UploadersLib.Properties;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
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;
|
|
|
|
public override Icon ServiceIcon => Resources.Lithiio;
|
|
|
|
public override bool CheckConfig(UploadersConfig config)
|
|
{
|
|
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()
|
|
{
|
|
}
|
|
|
|
public Lithiio(LithiioSettings config)
|
|
{
|
|
Config = config;
|
|
}
|
|
|
|
public override UploadResult Upload(Stream stream, string fileName)
|
|
{
|
|
Dictionary<string, string> args = new Dictionary<string, string>();
|
|
args.Add("key", Config.UserAPIKey);
|
|
|
|
UploadResult result = SendRequestFile("https://upload.lithi.io/v1.php", stream, fileName, "file", args);
|
|
|
|
if (result.IsSuccess)
|
|
{
|
|
LithiioUploadResponse uploadResponse = JsonConvert.DeserializeObject<LithiioUploadResponse>(result.Response);
|
|
|
|
if (uploadResponse.Success)
|
|
{
|
|
result.URL = uploadResponse.URL;
|
|
}
|
|
else
|
|
{
|
|
Errors.Add(uploadResponse.Error);
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
public string FetchAPIKey(string email, string password)
|
|
{
|
|
Dictionary<string, string> args = new Dictionary<string, string>();
|
|
args.Add("email", email);
|
|
args.Add("password", password);
|
|
|
|
string response = SendRequestMultiPart("https://lithi.io/api/v1/fetch-api-key.php", args);
|
|
|
|
if (!string.IsNullOrEmpty(response))
|
|
{
|
|
LithiioFetchAPIKeyResponse apiKeyResponse = JsonConvert.DeserializeObject<LithiioFetchAPIKeyResponse>(response);
|
|
|
|
if (apiKeyResponse.Success)
|
|
{
|
|
return apiKeyResponse.APIKey;
|
|
}
|
|
else
|
|
{
|
|
throw new Exception(apiKeyResponse.Error);
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
private class LithiioResponse
|
|
{
|
|
public bool Success { get; set; }
|
|
public string Error { get; set; }
|
|
}
|
|
|
|
private class LithiioUploadResponse : LithiioResponse
|
|
{
|
|
public string URL { get; set; }
|
|
}
|
|
|
|
private class LithiioFetchAPIKeyResponse : LithiioResponse
|
|
{
|
|
public string APIKey { get; set; }
|
|
}
|
|
}
|
|
|
|
public class LithiioSettings
|
|
{
|
|
public string UserAPIKey { get; set; } = "";
|
|
}
|
|
} |