From 206a79d86e752a5e6e9aadf2e2f7348ee9438645 Mon Sep 17 00:00:00 2001 From: Jaex Date: Mon, 2 Oct 2017 20:15:54 +0300 Subject: [PATCH] Implement new paste.ee API --- ShareX.UploadersLib/APIKeys/APIKeys.cs | 1 + .../Forms/UploadersConfigForm.Designer.cs | 52 ++++--- .../Forms/UploadersConfigForm.cs | 9 +- .../Forms/UploadersConfigForm.resx | 132 +++++++++++------- ShareX.UploadersLib/TextUploaders/Paste_ee.cs | 85 ++++++++--- ShareX.UploadersLib/UploadersConfig.cs | 2 +- 6 files changed, 180 insertions(+), 101 deletions(-) diff --git a/ShareX.UploadersLib/APIKeys/APIKeys.cs b/ShareX.UploadersLib/APIKeys/APIKeys.cs index 0d9982943..8b5aa2004 100644 --- a/ShareX.UploadersLib/APIKeys/APIKeys.cs +++ b/ShareX.UploadersLib/APIKeys/APIKeys.cs @@ -69,6 +69,7 @@ public static partial class APIKeys public static string PastebinCaKey = ""; public static string GitHubID = ""; public static string GitHubSecret = ""; + public static string Paste_eeApplicationKey = ""; // URL Shorteners public static string BitlyClientID = ""; diff --git a/ShareX.UploadersLib/Forms/UploadersConfigForm.Designer.cs b/ShareX.UploadersLib/Forms/UploadersConfigForm.Designer.cs index da599aab4..9ae28dba5 100644 --- a/ShareX.UploadersLib/Forms/UploadersConfigForm.Designer.cs +++ b/ShareX.UploadersLib/Forms/UploadersConfigForm.Designer.cs @@ -270,6 +270,9 @@ private void InitializeComponent() this.btnBoxRefreshFolders = new System.Windows.Forms.Button(); this.oauth2Box = new ShareX.UploadersLib.OAuthControl(); this.tpAmazonS3 = new System.Windows.Forms.TabPage(); + this.btnAmazonS3StorageClassHelp = new System.Windows.Forms.Button(); + this.lblAmazonS3StorageClass = new System.Windows.Forms.Label(); + this.cbAmazonS3StorageClass = new System.Windows.Forms.ComboBox(); this.cbAmazonS3UsePathStyle = new System.Windows.Forms.CheckBox(); this.lblAmazonS3Endpoint = new System.Windows.Forms.Label(); this.txtAmazonS3Endpoint = new System.Windows.Forms.TextBox(); @@ -650,9 +653,7 @@ private void InitializeComponent() this.lblWidthHint = new System.Windows.Forms.Label(); this.ttlvMain = new ShareX.HelpersLib.TabToListView(); this.actRapidShareAccountType = new ShareX.UploadersLib.AccountTypeControl(); - this.cbAmazonS3StorageClass = new System.Windows.Forms.ComboBox(); - this.lblAmazonS3StorageClass = new System.Windows.Forms.Label(); - this.btnAmazonS3StorageClassHelp = new System.Windows.Forms.Button(); + this.btnPaste_eeGetUserKey = new System.Windows.Forms.Button(); this.tpOtherUploaders.SuspendLayout(); this.tcOtherUploaders.SuspendLayout(); this.tpTwitter.SuspendLayout(); @@ -2594,6 +2595,26 @@ private void InitializeComponent() this.tpAmazonS3.Name = "tpAmazonS3"; this.tpAmazonS3.UseVisualStyleBackColor = true; // + // btnAmazonS3StorageClassHelp + // + resources.ApplyResources(this.btnAmazonS3StorageClassHelp, "btnAmazonS3StorageClassHelp"); + this.btnAmazonS3StorageClassHelp.Name = "btnAmazonS3StorageClassHelp"; + this.btnAmazonS3StorageClassHelp.UseVisualStyleBackColor = true; + this.btnAmazonS3StorageClassHelp.Click += new System.EventHandler(this.btnAmazonS3StorageClassHelp_Click); + // + // lblAmazonS3StorageClass + // + resources.ApplyResources(this.lblAmazonS3StorageClass, "lblAmazonS3StorageClass"); + this.lblAmazonS3StorageClass.Name = "lblAmazonS3StorageClass"; + // + // cbAmazonS3StorageClass + // + this.cbAmazonS3StorageClass.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.cbAmazonS3StorageClass.FormattingEnabled = true; + resources.ApplyResources(this.cbAmazonS3StorageClass, "cbAmazonS3StorageClass"); + this.cbAmazonS3StorageClass.Name = "cbAmazonS3StorageClass"; + this.cbAmazonS3StorageClass.SelectedIndexChanged += new System.EventHandler(this.cbAmazonS3StorageClass_SelectedIndexChanged); + // // cbAmazonS3UsePathStyle // resources.ApplyResources(this.cbAmazonS3UsePathStyle, "cbAmazonS3UsePathStyle"); @@ -4478,6 +4499,7 @@ private void InitializeComponent() // // tpPaste_ee // + this.tpPaste_ee.Controls.Add(this.btnPaste_eeGetUserKey); this.tpPaste_ee.Controls.Add(this.lblPaste_eeUserAPIKey); this.tpPaste_ee.Controls.Add(this.txtPaste_eeUserAPIKey); resources.ApplyResources(this.tpPaste_ee, "tpPaste_ee"); @@ -5310,25 +5332,12 @@ private void InitializeComponent() this.actRapidShareAccountType.Name = "actRapidShareAccountType"; this.actRapidShareAccountType.SelectedAccountType = ShareX.UploadersLib.AccountType.Anonymous; // - // cbAmazonS3StorageClass + // btnPaste_eeGetUserKey // - this.cbAmazonS3StorageClass.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.cbAmazonS3StorageClass.FormattingEnabled = true; - resources.ApplyResources(this.cbAmazonS3StorageClass, "cbAmazonS3StorageClass"); - this.cbAmazonS3StorageClass.Name = "cbAmazonS3StorageClass"; - this.cbAmazonS3StorageClass.SelectedIndexChanged += new System.EventHandler(this.cbAmazonS3StorageClass_SelectedIndexChanged); - // - // lblAmazonS3StorageClass - // - resources.ApplyResources(this.lblAmazonS3StorageClass, "lblAmazonS3StorageClass"); - this.lblAmazonS3StorageClass.Name = "lblAmazonS3StorageClass"; - // - // btnAmazonS3StorageClassHelp - // - resources.ApplyResources(this.btnAmazonS3StorageClassHelp, "btnAmazonS3StorageClassHelp"); - this.btnAmazonS3StorageClassHelp.Name = "btnAmazonS3StorageClassHelp"; - this.btnAmazonS3StorageClassHelp.UseVisualStyleBackColor = true; - this.btnAmazonS3StorageClassHelp.Click += new System.EventHandler(this.btnAmazonS3StorageClassHelp_Click); + resources.ApplyResources(this.btnPaste_eeGetUserKey, "btnPaste_eeGetUserKey"); + this.btnPaste_eeGetUserKey.Name = "btnPaste_eeGetUserKey"; + this.btnPaste_eeGetUserKey.UseVisualStyleBackColor = true; + this.btnPaste_eeGetUserKey.Click += new System.EventHandler(this.btnPaste_eeGetUserKey_Click); // // UploadersConfigForm // @@ -6136,5 +6145,6 @@ private void InitializeComponent() private System.Windows.Forms.Label lblAmazonS3StorageClass; private System.Windows.Forms.ComboBox cbAmazonS3StorageClass; private System.Windows.Forms.Button btnAmazonS3StorageClassHelp; + private System.Windows.Forms.Button btnPaste_eeGetUserKey; } } diff --git a/ShareX.UploadersLib/Forms/UploadersConfigForm.cs b/ShareX.UploadersLib/Forms/UploadersConfigForm.cs index 25a5a0f48..92c644bd6 100644 --- a/ShareX.UploadersLib/Forms/UploadersConfigForm.cs +++ b/ShareX.UploadersLib/Forms/UploadersConfigForm.cs @@ -282,7 +282,7 @@ public void LoadSettings() // Paste.ee - txtPaste_eeUserAPIKey.Text = Config.Paste_eeUserAPIKey; + txtPaste_eeUserAPIKey.Text = Config.Paste_eeUserKey; // Gist @@ -1156,9 +1156,14 @@ private void cbPastebinRaw_CheckedChanged(object sender, EventArgs e) #region Paste.ee + private void btnPaste_eeGetUserKey_Click(object sender, EventArgs e) + { + URLHelpers.OpenURL($"https://paste.ee/account/api/authorize/{APIKeys.Paste_eeApplicationKey}"); + } + private void txtPaste_eeUserAPIKey_TextChanged(object sender, EventArgs e) { - Config.Paste_eeUserAPIKey = txtPaste_eeUserAPIKey.Text; + Config.Paste_eeUserKey = txtPaste_eeUserAPIKey.Text; } #endregion Paste.ee diff --git a/ShareX.UploadersLib/Forms/UploadersConfigForm.resx b/ShareX.UploadersLib/Forms/UploadersConfigForm.resx index 5607ca4c8..8aa472202 100644 --- a/ShareX.UploadersLib/Forms/UploadersConfigForm.resx +++ b/ShareX.UploadersLib/Forms/UploadersConfigForm.resx @@ -496,7 +496,7 @@ For example, if your bucket is called bucket.example.com then URL will be http:/ Twitter - @Invariant + tpTwitter @@ -2782,7 +2782,7 @@ store.book[0].title bit.ly - @Invariant + tpBitly @@ -2851,7 +2851,7 @@ store.book[0].title Google - @Invariant + tpGoogleURLShortener @@ -3112,7 +3112,7 @@ store.book[0].title YOURLS - @Invariant + tpYourls @@ -3271,7 +3271,7 @@ store.book[0].title adf.ly - @Invariant + tpAdFly @@ -3346,7 +3346,7 @@ store.book[0].title CoinURL - @Invariant + tpCoinURL @@ -3532,7 +3532,7 @@ store.book[0].title Polr - @Invariant + tpPolr @@ -5056,7 +5056,7 @@ store.book[0].title FTP / FTPS / SFTP - @Invariant + tpFTP @@ -5355,7 +5355,7 @@ store.book[0].title Dropbox - @Invariant + tpDropbox @@ -5487,7 +5487,7 @@ store.book[0].title OneDrive - @Invariant + tpOneDrive @@ -5739,7 +5739,7 @@ store.book[0].title Google Drive - @Invariant + tpGoogleDrive @@ -6003,7 +6003,7 @@ store.book[0].title puush - @Invariant + tpPuush @@ -6198,7 +6198,7 @@ store.book[0].title Box - @Invariant + tpBox @@ -6819,7 +6819,7 @@ store.book[0].title Amazon S3 - @Invariant + tpAmazonS3 @@ -7143,7 +7143,7 @@ store.book[0].title Azure Storage - @Invariant + tpAzureStorage @@ -7242,7 +7242,7 @@ store.book[0].title Gfycat - @Invariant + tpGfycat @@ -7560,7 +7560,7 @@ store.book[0].title Mega - @Invariant + tpMega @@ -7911,7 +7911,7 @@ store.book[0].title ownCloud - @Invariant + tpOwnCloud @@ -8121,7 +8121,7 @@ store.book[0].title MediaFire - @Invariant + tpMediaFire @@ -8283,7 +8283,7 @@ store.book[0].title Pushbullet - @Invariant + tpPushbullet @@ -8460,7 +8460,7 @@ store.book[0].title SendSpace - @Invariant + tpSendSpace @@ -8646,7 +8646,7 @@ store.book[0].title Ge.tt - @Invariant + tpGe_tt @@ -8805,7 +8805,7 @@ store.book[0].title Hostr - @Invariant + tpHostr @@ -9255,7 +9255,7 @@ store.book[0].title Minus - @Invariant + tpMinus @@ -9462,7 +9462,7 @@ store.book[0].title Atlassian Jira - @Invariant + tpJira @@ -9621,7 +9621,7 @@ store.book[0].title Lambda - @Invariant + tpLambda @@ -9831,7 +9831,7 @@ store.book[0].title Pomf - @Invariant + tpPomf @@ -10792,7 +10792,7 @@ Using an encrypted library disables sharing. Seafile - @Invariant + tpSeafile @@ -10993,7 +10993,7 @@ Using an encrypted library disables sharing. Streamable - @Invariant + tpStreamable @@ -11101,7 +11101,7 @@ Using an encrypted library disables sharing. s-ul - @Invariant + tpSul @@ -11206,7 +11206,7 @@ Using an encrypted library disables sharing. Lithiio - @Invariant + tpLithiio @@ -11581,7 +11581,7 @@ Using an encrypted library disables sharing. Uplea - @Invariant + tpUplea @@ -12088,7 +12088,7 @@ Using an encrypted library disables sharing. Plik - @Invariant + tpPlik @@ -13231,7 +13231,7 @@ Using an encrypted library disables sharing. Pastebin - @Invariant + tpPastebin @@ -13244,6 +13244,30 @@ Using an encrypted library disables sharing. 0 + + 16, 16 + + + 296, 24 + + + 2 + + + Get user key... + + + btnPaste_eeGetUserKey + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tpPaste_ee + + + 0 + True @@ -13251,16 +13275,16 @@ Using an encrypted library disables sharing. NoControl - 13, 16 + 13, 48 - 72, 13 + 52, 13 0 - User API key: + User key: lblPaste_eeUserAPIKey @@ -13272,10 +13296,10 @@ Using an encrypted library disables sharing. tpPaste_ee - 0 + 1 - 16, 32 + 16, 64 296, 20 @@ -13293,7 +13317,7 @@ Using an encrypted library disables sharing. tpPaste_ee - 1 + 2 4, 22 @@ -13309,7 +13333,7 @@ Using an encrypted library disables sharing. Paste.ee - @Invariant + tpPaste_ee @@ -13549,7 +13573,7 @@ Using an encrypted library disables sharing. GitHub Gist - @Invariant + tpGist @@ -13657,7 +13681,7 @@ Using an encrypted library disables sharing. uPaste - @Invariant + tpUpaste @@ -13816,7 +13840,7 @@ Using an encrypted library disables sharing. Hastebin - @Invariant + tpHastebin @@ -13945,7 +13969,7 @@ Using an encrypted library disables sharing. OneTimeSecret - @Invariant + tpOneTimeSecret @@ -14002,7 +14026,7 @@ Using an encrypted library disables sharing. Pastie - @Invariant + tpPastie @@ -14359,7 +14383,7 @@ Using an encrypted library disables sharing. Imgur - @Invariant + tpImgur @@ -14599,7 +14623,7 @@ Using an encrypted library disables sharing. ImageShack - @Invariant + tpImageShack @@ -14803,7 +14827,7 @@ Using an encrypted library disables sharing. TinyPic - @Invariant + tpTinyPic @@ -14983,7 +15007,7 @@ Using an encrypted library disables sharing. Flickr - @Invariant + tpFlickr @@ -15475,7 +15499,7 @@ Using an encrypted library disables sharing. Photobucket - @Invariant + tpPhotobucket @@ -15643,7 +15667,7 @@ Using an encrypted library disables sharing. Google Photos - @Invariant + tpGooglePhotos @@ -15913,7 +15937,7 @@ Using an encrypted library disables sharing. Chevereto - @Invariant + tpChevereto @@ -16021,7 +16045,7 @@ Using an encrypted library disables sharing. vgy.me - @Invariant + tpVgyme diff --git a/ShareX.UploadersLib/TextUploaders/Paste_ee.cs b/ShareX.UploadersLib/TextUploaders/Paste_ee.cs index 22372d95e..9ad89762a 100644 --- a/ShareX.UploadersLib/TextUploaders/Paste_ee.cs +++ b/ShareX.UploadersLib/TextUploaders/Paste_ee.cs @@ -23,8 +23,10 @@ You should have received a copy of the GNU General Public License #endregion License Information (GPL v3) +using Newtonsoft.Json; using ShareX.UploadersLib.Properties; -using System.Collections.Generic; +using System; +using System.Collections.Specialized; using System.Drawing; using System.Windows.Forms; @@ -40,7 +42,18 @@ public class Paste_eeTextUploaderService : TextUploaderService public override GenericUploader CreateUploader(UploadersConfig config, TaskReferenceHelper taskInfo) { - return new Paste_ee(config.Paste_eeUserAPIKey); + string apiKey; + + if (!string.IsNullOrEmpty(config.Paste_eeUserKey)) + { + apiKey = config.Paste_eeUserKey; + } + else + { + apiKey = APIKeys.Paste_eeApplicationKey; + } + + return new Paste_ee(apiKey); } public override TabPage GetUploadersConfigTabPage(UploadersConfigForm form) => form.tpPaste_ee; @@ -50,11 +63,6 @@ public sealed class Paste_ee : TextUploader { public string APIKey { get; private set; } - public Paste_ee() - { - APIKey = "public"; - } - public Paste_ee(string apiKey) { APIKey = apiKey; @@ -62,35 +70,66 @@ public Paste_ee(string apiKey) public override UploadResult UploadText(string text, string fileName) { + if (string.IsNullOrEmpty(APIKey)) + { + throw new Exception("API key is missing."); + } + UploadResult ur = new UploadResult(); if (!string.IsNullOrEmpty(text)) { - if (string.IsNullOrEmpty(APIKey)) + Paste_eeSubmitRequestBody requestBody = new Paste_eeSubmitRequestBody() { - APIKey = "public"; - } + encrypted = false, + description = "", + sections = new Paste_eeSubmitRequestBodySection[] + { + new Paste_eeSubmitRequestBodySection() + { + name = "", + //syntax = "autodetect", + contents = text + } + } + }; - Dictionary arguments = new Dictionary(); - arguments.Add("key", APIKey); - arguments.Add("description", ""); - arguments.Add("paste", text); - arguments.Add("format", "simple"); - arguments.Add("return", "link"); + string json = JsonConvert.SerializeObject(requestBody); - ur.Response = SendRequestMultiPart("http://paste.ee/api", arguments); + NameValueCollection headers = new NameValueCollection(); + headers.Add("X-Auth-Token", APIKey); - if (!string.IsNullOrEmpty(ur.Response) && ur.Response.StartsWith("error")) + ur.Response = SendRequest(HttpMethod.POST, "https://api.paste.ee/v1/pastes", json, ContentTypeJSON, null, headers); + + if (!string.IsNullOrEmpty(ur.Response)) { - Errors.Add(ur.Response); - } - else - { - ur.URL = ur.Response; + Paste_eeSubmitResponse response = JsonConvert.DeserializeObject(ur.Response); + + ur.URL = response.link; } } return ur; } } + + public class Paste_eeSubmitRequestBody + { + public bool encrypted { get; set; } + public string description { get; set; } + public Paste_eeSubmitRequestBodySection[] sections { get; set; } + } + + public class Paste_eeSubmitRequestBodySection + { + public string name { get; set; } + //public string syntax { get; set; } + public string contents { get; set; } + } + + public class Paste_eeSubmitResponse + { + public string id { get; set; } + public string link { get; set; } + } } \ No newline at end of file diff --git a/ShareX.UploadersLib/UploadersConfig.cs b/ShareX.UploadersLib/UploadersConfig.cs index 0d9957383..29f688110 100644 --- a/ShareX.UploadersLib/UploadersConfig.cs +++ b/ShareX.UploadersLib/UploadersConfig.cs @@ -94,7 +94,7 @@ public class UploadersConfig : SettingsBase // Paste.ee - public string Paste_eeUserAPIKey = "public"; + public string Paste_eeUserKey = ""; // Gist