mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-02 18:26:27 +13:00
Added login support to Lithiio
This commit is contained in:
parent
a7aea349cf
commit
7388cd3ee2
5 changed files with 8423 additions and 1882 deletions
|
@ -592,9 +592,10 @@ public static void RefreshSelectedItem(this ListBox lb)
|
|||
}
|
||||
}
|
||||
|
||||
public static void ShowError(this Exception e)
|
||||
public static void ShowError(this Exception e, bool fullError = true)
|
||||
{
|
||||
MessageBox.Show(e.ToString(), "ShareX - " + Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
string error = fullError ? e.ToString() : e.Message;
|
||||
MessageBox.Show(error, "ShareX - " + Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -27,6 +27,7 @@ You should have received a copy of the GNU General Public License
|
|||
|
||||
using Newtonsoft.Json;
|
||||
using ShareX.UploadersLib.Properties;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
|
@ -57,6 +58,10 @@ public sealed class Lithiio : FileUploader
|
|||
{
|
||||
public LithiioSettings Config { get; private set; }
|
||||
|
||||
public Lithiio()
|
||||
{
|
||||
}
|
||||
|
||||
public Lithiio(LithiioSettings config)
|
||||
{
|
||||
Config = config;
|
||||
|
@ -64,34 +69,68 @@ public Lithiio(LithiioSettings config)
|
|||
|
||||
public override UploadResult Upload(Stream stream, string fileName)
|
||||
{
|
||||
Dictionary<string, string> arguments = new Dictionary<string, string>();
|
||||
arguments.Add("key", Config.UserAPIKey);
|
||||
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", arguments);
|
||||
UploadResult result = SendRequestFile("https://upload.lithi.io/v1.php", stream, fileName, "file", args);
|
||||
|
||||
if (result.IsSuccess)
|
||||
{
|
||||
LithiioResponse response = JsonConvert.DeserializeObject<LithiioResponse>(result.Response);
|
||||
LithiioUploadResponse uploadResponse = JsonConvert.DeserializeObject<LithiioUploadResponse>(result.Response);
|
||||
|
||||
if (response.Success)
|
||||
if (uploadResponse.Success)
|
||||
{
|
||||
result.URL = response.URL;
|
||||
result.URL = uploadResponse.URL;
|
||||
}
|
||||
else
|
||||
{
|
||||
Errors.Add(response.Error);
|
||||
Errors.Add(uploadResponse.Error);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public class LithiioResponse
|
||||
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 URL { 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
|
||||
|
|
|
@ -437,9 +437,15 @@ private void InitializeComponent()
|
|||
this.lblStreamablePassword = new System.Windows.Forms.Label();
|
||||
this.cbStreamableAnonymous = new System.Windows.Forms.CheckBox();
|
||||
this.tpSul = new System.Windows.Forms.TabPage();
|
||||
this.btnSulGetAPIKey = new System.Windows.Forms.Button();
|
||||
this.txtSulAPIKey = new System.Windows.Forms.TextBox();
|
||||
this.lblSulAPIKey = new System.Windows.Forms.Label();
|
||||
this.tpLithiio = new System.Windows.Forms.TabPage();
|
||||
this.btnLithiioLogin = new System.Windows.Forms.Button();
|
||||
this.txtLithiioPassword = new System.Windows.Forms.TextBox();
|
||||
this.txtLithiioEmail = new System.Windows.Forms.TextBox();
|
||||
this.lblLithiioPassword = new System.Windows.Forms.Label();
|
||||
this.lblLithiioEmail = new System.Windows.Forms.Label();
|
||||
this.btnLithiioGetAPIKey = new System.Windows.Forms.Button();
|
||||
this.lblLithiioApiKey = new System.Windows.Forms.Label();
|
||||
this.txtLithiioApiKey = new System.Windows.Forms.TextBox();
|
||||
|
@ -617,7 +623,6 @@ private void InitializeComponent()
|
|||
this.lblWidthHint = new System.Windows.Forms.Label();
|
||||
this.ttlvMain = new ShareX.HelpersLib.TabToListView();
|
||||
this.actRapidShareAccountType = new ShareX.UploadersLib.AccountTypeControl();
|
||||
this.btnSulGetAPIKey = new System.Windows.Forms.Button();
|
||||
this.tpOtherUploaders.SuspendLayout();
|
||||
this.tcOtherUploaders.SuspendLayout();
|
||||
this.tpTwitter.SuspendLayout();
|
||||
|
@ -3711,6 +3716,13 @@ private void InitializeComponent()
|
|||
this.tpSul.Name = "tpSul";
|
||||
this.tpSul.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// btnSulGetAPIKey
|
||||
//
|
||||
resources.ApplyResources(this.btnSulGetAPIKey, "btnSulGetAPIKey");
|
||||
this.btnSulGetAPIKey.Name = "btnSulGetAPIKey";
|
||||
this.btnSulGetAPIKey.UseVisualStyleBackColor = true;
|
||||
this.btnSulGetAPIKey.Click += new System.EventHandler(this.btnSulGetAPIKey_Click);
|
||||
//
|
||||
// txtSulAPIKey
|
||||
//
|
||||
resources.ApplyResources(this.txtSulAPIKey, "txtSulAPIKey");
|
||||
|
@ -3725,6 +3737,11 @@ private void InitializeComponent()
|
|||
//
|
||||
// tpLithiio
|
||||
//
|
||||
this.tpLithiio.Controls.Add(this.btnLithiioLogin);
|
||||
this.tpLithiio.Controls.Add(this.txtLithiioPassword);
|
||||
this.tpLithiio.Controls.Add(this.txtLithiioEmail);
|
||||
this.tpLithiio.Controls.Add(this.lblLithiioPassword);
|
||||
this.tpLithiio.Controls.Add(this.lblLithiioEmail);
|
||||
this.tpLithiio.Controls.Add(this.btnLithiioGetAPIKey);
|
||||
this.tpLithiio.Controls.Add(this.lblLithiioApiKey);
|
||||
this.tpLithiio.Controls.Add(this.txtLithiioApiKey);
|
||||
|
@ -3732,6 +3749,34 @@ private void InitializeComponent()
|
|||
this.tpLithiio.Name = "tpLithiio";
|
||||
this.tpLithiio.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// btnLithiioLogin
|
||||
//
|
||||
resources.ApplyResources(this.btnLithiioLogin, "btnLithiioLogin");
|
||||
this.btnLithiioLogin.Name = "btnLithiioLogin";
|
||||
this.btnLithiioLogin.UseVisualStyleBackColor = true;
|
||||
this.btnLithiioLogin.Click += new System.EventHandler(this.btnLithiioLogin_Click);
|
||||
//
|
||||
// txtLithiioPassword
|
||||
//
|
||||
resources.ApplyResources(this.txtLithiioPassword, "txtLithiioPassword");
|
||||
this.txtLithiioPassword.Name = "txtLithiioPassword";
|
||||
this.txtLithiioPassword.UseSystemPasswordChar = true;
|
||||
//
|
||||
// txtLithiioEmail
|
||||
//
|
||||
resources.ApplyResources(this.txtLithiioEmail, "txtLithiioEmail");
|
||||
this.txtLithiioEmail.Name = "txtLithiioEmail";
|
||||
//
|
||||
// lblLithiioPassword
|
||||
//
|
||||
resources.ApplyResources(this.lblLithiioPassword, "lblLithiioPassword");
|
||||
this.lblLithiioPassword.Name = "lblLithiioPassword";
|
||||
//
|
||||
// lblLithiioEmail
|
||||
//
|
||||
resources.ApplyResources(this.lblLithiioEmail, "lblLithiioEmail");
|
||||
this.lblLithiioEmail.Name = "lblLithiioEmail";
|
||||
//
|
||||
// btnLithiioGetAPIKey
|
||||
//
|
||||
resources.ApplyResources(this.btnLithiioGetAPIKey, "btnLithiioGetAPIKey");
|
||||
|
@ -5027,13 +5072,6 @@ private void InitializeComponent()
|
|||
this.actRapidShareAccountType.Name = "actRapidShareAccountType";
|
||||
this.actRapidShareAccountType.SelectedAccountType = ShareX.UploadersLib.AccountType.Anonymous;
|
||||
//
|
||||
// btnSulGetAPIKey
|
||||
//
|
||||
resources.ApplyResources(this.btnSulGetAPIKey, "btnSulGetAPIKey");
|
||||
this.btnSulGetAPIKey.Name = "btnSulGetAPIKey";
|
||||
this.btnSulGetAPIKey.UseVisualStyleBackColor = true;
|
||||
this.btnSulGetAPIKey.Click += new System.EventHandler(this.btnSulGetAPIKey_Click);
|
||||
//
|
||||
// UploadersConfigForm
|
||||
//
|
||||
resources.ApplyResources(this, "$this");
|
||||
|
@ -5795,5 +5833,10 @@ private void InitializeComponent()
|
|||
private OAuthControl oauthFlickr;
|
||||
private System.Windows.Forms.CheckBox cbFlickrDirectLink;
|
||||
private System.Windows.Forms.Button btnSulGetAPIKey;
|
||||
private System.Windows.Forms.Button btnLithiioLogin;
|
||||
private System.Windows.Forms.TextBox txtLithiioPassword;
|
||||
private System.Windows.Forms.TextBox txtLithiioEmail;
|
||||
private System.Windows.Forms.Label lblLithiioPassword;
|
||||
private System.Windows.Forms.Label lblLithiioEmail;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2807,6 +2807,26 @@ private void txtLithiioApiKey_TextChanged(object sender, EventArgs e)
|
|||
Config.LithiioSettings.UserAPIKey = txtLithiioApiKey.Text;
|
||||
}
|
||||
|
||||
private void btnLithiioLogin_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
Cursor = Cursors.WaitCursor;
|
||||
|
||||
Lithiio lithiio = new Lithiio();
|
||||
string apiKey = lithiio.FetchAPIKey(txtLithiioEmail.Text, txtLithiioPassword.Text);
|
||||
txtLithiioApiKey.Text = apiKey ?? "";
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ex.ShowError(false);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Cursor = Cursors.Default;
|
||||
}
|
||||
}
|
||||
|
||||
private void btnLithiioGetAPIKey_Click(object sender, EventArgs e)
|
||||
{
|
||||
URLHelpers.OpenURL("https://lithi.io/my-account.php");
|
||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue