diff --git a/ShareX.UploadersLib/Enums.cs b/ShareX.UploadersLib/Enums.cs index 6b3071a46..d1d57bfbe 100644 --- a/ShareX.UploadersLib/Enums.cs +++ b/ShareX.UploadersLib/Enums.cs @@ -120,6 +120,8 @@ public enum FileDestination Localhostr, [Description("JIRA")] Jira, + [Description("λ")] + Lambda, SharedFolder, // Localized Email, // Localized CustomFileUploader // Localized diff --git a/ShareX.UploadersLib/Favicons/Lambda.ico b/ShareX.UploadersLib/Favicons/Lambda.ico new file mode 100644 index 000000000..5b8909ed4 Binary files /dev/null and b/ShareX.UploadersLib/Favicons/Lambda.ico differ diff --git a/ShareX.UploadersLib/FileUploaders/Lambda.cs b/ShareX.UploadersLib/FileUploaders/Lambda.cs new file mode 100644 index 000000000..72807f6fa --- /dev/null +++ b/ShareX.UploadersLib/FileUploaders/Lambda.cs @@ -0,0 +1,95 @@ +#region License Information (GPL v3) + +/* + ShareX - A program that allows you to take screenshots and share any file type + Copyright © 2007-2015 ShareX Developers + + 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 . +*/ + +#endregion License Information (GPL v3) + +using Newtonsoft.Json; +using ShareX.HelpersLib; +using System; +using System.Collections.Generic; +using System.Collections.Specialized; +using System.IO; +using System.Linq; + +namespace ShareX.UploadersLib.FileUploaders +{ + public sealed class Lambda : FileUploader + { + public LambdaSettings Config { get; private set; } + + public Lambda(LambdaSettings config) + { + Config = config; + } + + private const string uploadUrl = "https://lambda.sx/upload"; + private const string responseUrl = "https://λ.pw/"; + + public override UploadResult Upload(Stream stream, string fileName) + { + if (string.IsNullOrEmpty(Config.UserAPIKey)) + { + Errors.Add("Missing API key. Set one in destination settings."); + return null; + } + + Dictionary arguments = new Dictionary(); + arguments.Add("apikey", Config.UserAPIKey); + UploadResult result = UploadData(stream, uploadUrl, fileName, "file", arguments); + + if (result.IsSuccess) { + LambdaResponse response = JsonConvert.DeserializeObject(result.Response); + + if (response.success) + { + result.URL = responseUrl + response.files[0].url; + } + else + { + foreach (String e in response.errors) { + Errors.Add(e); + } + } + } + + return result; + } + + internal class LambdaResponse + { + public bool success { get; set; } + public List files { get; set; } + public List errors { get; set; } + } + + internal class LambdaFile + { + public string url { get; set; } + } + } + + public class LambdaSettings + { + public string UserAPIKey = string.Empty; + } +} \ No newline at end of file diff --git a/ShareX.UploadersLib/Forms/UploadersConfigForm.Designer.cs b/ShareX.UploadersLib/Forms/UploadersConfigForm.Designer.cs index 4bd00fc55..2907a044a 100644 --- a/ShareX.UploadersLib/Forms/UploadersConfigForm.Designer.cs +++ b/ShareX.UploadersLib/Forms/UploadersConfigForm.Designer.cs @@ -293,6 +293,10 @@ private void InitializeComponent() this.txtJiraHost = new System.Windows.Forms.TextBox(); this.lblJiraHost = new System.Windows.Forms.Label(); this.oAuthJira = new ShareX.UploadersLib.OAuthControl(); + this.tpLambda = new System.Windows.Forms.TabPage(); + this.lambdaInfoLabel = new System.Windows.Forms.Label(); + this.lambdaApiKeyLabel = new System.Windows.Forms.Label(); + this.txtLambdaApiKey = new System.Windows.Forms.TextBox(); this.tpEmail = new System.Windows.Forms.TabPage(); this.chkEmailConfirm = new System.Windows.Forms.CheckBox(); this.lblEmailSmtpServer = new System.Windows.Forms.Label(); @@ -467,6 +471,7 @@ private void InitializeComponent() this.gbMinusUpload.SuspendLayout(); this.tpJira.SuspendLayout(); this.gpJiraServer.SuspendLayout(); + this.tpLambda.SuspendLayout(); this.tpEmail.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.nudEmailSmtpPort)).BeginInit(); this.tpSharedFolder.SuspendLayout(); @@ -1182,6 +1187,7 @@ private void InitializeComponent() this.tcFileUploaders.Controls.Add(this.tpHostr); this.tcFileUploaders.Controls.Add(this.tpMinus); this.tcFileUploaders.Controls.Add(this.tpJira); + this.tcFileUploaders.Controls.Add(this.tpLambda); this.tcFileUploaders.Controls.Add(this.tpEmail); this.tcFileUploaders.Controls.Add(this.tpSharedFolder); resources.ApplyResources(this.tcFileUploaders, "tcFileUploaders"); @@ -2423,6 +2429,33 @@ private void InitializeComponent() this.oAuthJira.ClearButtonClicked += new ShareX.UploadersLib.OAuthControl.ClearButtonclickedEventHandler(this.oAuthJira_ClearButtonClicked); this.oAuthJira.RefreshButtonClicked += new ShareX.UploadersLib.OAuthControl.RefreshButtonClickedEventHandler(this.oAuthJira_RefreshButtonClicked); // + // tpLambda + // + this.tpLambda.Controls.Add(this.lambdaInfoLabel); + this.tpLambda.Controls.Add(this.lambdaApiKeyLabel); + this.tpLambda.Controls.Add(this.txtLambdaApiKey); + resources.ApplyResources(this.tpLambda, "tpLambda"); + this.tpLambda.Name = "tpLambda"; + this.tpLambda.UseVisualStyleBackColor = true; + // + // lambdaInfoLabel + // + resources.ApplyResources(this.lambdaInfoLabel, "lambdaInfoLabel"); + this.lambdaInfoLabel.Name = "lambdaInfoLabel"; + this.lambdaInfoLabel.Click += new System.EventHandler(this.lambdaInfoLabel_Click); + // + // lambdaApiKeyLabel + // + resources.ApplyResources(this.lambdaApiKeyLabel, "lambdaApiKeyLabel"); + this.lambdaApiKeyLabel.Name = "lambdaApiKeyLabel"; + // + // txtLambdaApiKey + // + resources.ApplyResources(this.txtLambdaApiKey, "txtLambdaApiKey"); + this.txtLambdaApiKey.Name = "txtLambdaApiKey"; + this.txtLambdaApiKey.UseSystemPasswordChar = true; + this.txtLambdaApiKey.TextChanged += new System.EventHandler(this.txtLambdaApiKey_TextChanged); + // // tpEmail // this.tpEmail.Controls.Add(this.chkEmailConfirm); @@ -3480,6 +3513,8 @@ private void InitializeComponent() this.tpJira.PerformLayout(); this.gpJiraServer.ResumeLayout(false); this.gpJiraServer.PerformLayout(); + this.tpLambda.ResumeLayout(false); + this.tpLambda.PerformLayout(); this.tpEmail.ResumeLayout(false); this.tpEmail.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.nudEmailSmtpPort)).EndInit(); @@ -3921,6 +3956,10 @@ private void InitializeComponent() private System.Windows.Forms.ColumnHeader chHubicFolderName; private System.Windows.Forms.Label lblHubicSelectedFolder; private System.Windows.Forms.Button btnHubicRefreshFolders; - private System.Windows.Forms.CheckBox cbHubicPublishLink; + private System.Windows.Forms.CheckBox cbHubicPublishLink; + private System.Windows.Forms.TabPage tpLambda; + private System.Windows.Forms.Label lambdaApiKeyLabel; + private System.Windows.Forms.TextBox txtLambdaApiKey; + private System.Windows.Forms.Label lambdaInfoLabel; } } \ No newline at end of file diff --git a/ShareX.UploadersLib/Forms/UploadersConfigForm.cs b/ShareX.UploadersLib/Forms/UploadersConfigForm.cs index 0f8940437..a02fbd325 100644 --- a/ShareX.UploadersLib/Forms/UploadersConfigForm.cs +++ b/ShareX.UploadersLib/Forms/UploadersConfigForm.cs @@ -112,6 +112,7 @@ private void FormSettings() AddIconToTab(tpTwitter, Resources.Twitter); AddIconToTab(tpUpaste, Resources.Upaste); AddIconToTab(tpYourls, Resources.Yourls); + AddIconToTab(tpLambda, Resources.Lambda); tcFileUploaders.TabPages.Remove(tpHubic); @@ -550,6 +551,10 @@ public void LoadSettings(UploadersConfig uploadersConfig) cbMediaCrushDirectLink.Checked = Config.MediaCrushDirectLink; + // Lambda + + txtLambdaApiKey.Text = Config.LambdaSettings.UserAPIKey; + #endregion File uploaders #region URL Shorteners @@ -2062,6 +2067,20 @@ private void cbMediaCrushDirectLink_CheckedChanged(object sender, EventArgs e) #endregion MediaCrush + #region Lambda + + private void txtLambdaApiKey_TextChanged(object sender, EventArgs e) + { + Config.LambdaSettings.UserAPIKey = txtLambdaApiKey.Text; + } + + private void lambdaInfoLabel_Click(object sender, EventArgs e) + { + System.Diagnostics.Process.Start("https://lambda.sx/usercp"); + } + + #endregion Lambda + #endregion File Uploaders #region URL Shorteners diff --git a/ShareX.UploadersLib/Forms/UploadersConfigForm.resx b/ShareX.UploadersLib/Forms/UploadersConfigForm.resx index fe7685fe8..93b3c0cc2 100644 --- a/ShareX.UploadersLib/Forms/UploadersConfigForm.resx +++ b/ShareX.UploadersLib/Forms/UploadersConfigForm.resx @@ -1,3 +1,4 @@ +