mirror of
https://github.com/ShareX/ShareX.git
synced 2024-09-29 17:02:05 +13:00
fixed #2171: Added Polr API v2 support
This commit is contained in:
parent
9f3f1af6d9
commit
8aa7f4ea6d
5 changed files with 148 additions and 42 deletions
|
@ -159,6 +159,8 @@ private void InitializeComponent()
|
|||
this.txtCoinURLUUID = new System.Windows.Forms.TextBox();
|
||||
this.lblCoinURLUUID = new System.Windows.Forms.Label();
|
||||
this.tpPolr = new System.Windows.Forms.TabPage();
|
||||
this.cbPolrUseAPIv1 = new System.Windows.Forms.CheckBox();
|
||||
this.cbPolrIsSecret = new System.Windows.Forms.CheckBox();
|
||||
this.txtPolrAPIKey = new System.Windows.Forms.TextBox();
|
||||
this.lblPolrAPIKey = new System.Windows.Forms.Label();
|
||||
this.txtPolrAPIHostname = new System.Windows.Forms.TextBox();
|
||||
|
@ -472,6 +474,7 @@ private void InitializeComponent()
|
|||
this.tpImageUploaders = new System.Windows.Forms.TabPage();
|
||||
this.tcImageUploaders = new System.Windows.Forms.TabControl();
|
||||
this.tpImgur = new System.Windows.Forms.TabPage();
|
||||
this.cbImgurUseHTTPS = new System.Windows.Forms.CheckBox();
|
||||
this.cbImgurUseGIFV = new System.Windows.Forms.CheckBox();
|
||||
this.cbImgurUploadSelectedAlbum = new System.Windows.Forms.CheckBox();
|
||||
this.cbImgurDirectLink = new System.Windows.Forms.CheckBox();
|
||||
|
@ -559,7 +562,6 @@ private void InitializeComponent()
|
|||
this.lblWidthHint = new System.Windows.Forms.Label();
|
||||
this.ttlvMain = new ShareX.HelpersLib.TabToListView();
|
||||
this.actRapidShareAccountType = new ShareX.UploadersLib.AccountTypeControl();
|
||||
this.cbImgurUseHTTPS = new System.Windows.Forms.CheckBox();
|
||||
this.tpOtherUploaders.SuspendLayout();
|
||||
this.tcOtherUploaders.SuspendLayout();
|
||||
this.tpTwitter.SuspendLayout();
|
||||
|
@ -1595,6 +1597,8 @@ private void InitializeComponent()
|
|||
//
|
||||
// tpPolr
|
||||
//
|
||||
this.tpPolr.Controls.Add(this.cbPolrUseAPIv1);
|
||||
this.tpPolr.Controls.Add(this.cbPolrIsSecret);
|
||||
this.tpPolr.Controls.Add(this.txtPolrAPIKey);
|
||||
this.tpPolr.Controls.Add(this.lblPolrAPIKey);
|
||||
this.tpPolr.Controls.Add(this.txtPolrAPIHostname);
|
||||
|
@ -1603,6 +1607,20 @@ private void InitializeComponent()
|
|||
this.tpPolr.Name = "tpPolr";
|
||||
this.tpPolr.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// cbPolrUseAPIv1
|
||||
//
|
||||
resources.ApplyResources(this.cbPolrUseAPIv1, "cbPolrUseAPIv1");
|
||||
this.cbPolrUseAPIv1.Name = "cbPolrUseAPIv1";
|
||||
this.cbPolrUseAPIv1.UseVisualStyleBackColor = true;
|
||||
this.cbPolrUseAPIv1.CheckedChanged += new System.EventHandler(this.cbPolrUseAPIv1_CheckedChanged);
|
||||
//
|
||||
// cbPolrIsSecret
|
||||
//
|
||||
resources.ApplyResources(this.cbPolrIsSecret, "cbPolrIsSecret");
|
||||
this.cbPolrIsSecret.Name = "cbPolrIsSecret";
|
||||
this.cbPolrIsSecret.UseVisualStyleBackColor = true;
|
||||
this.cbPolrIsSecret.CheckedChanged += new System.EventHandler(this.cbPolrIsSecret_CheckedChanged);
|
||||
//
|
||||
// txtPolrAPIKey
|
||||
//
|
||||
resources.ApplyResources(this.txtPolrAPIKey, "txtPolrAPIKey");
|
||||
|
@ -3734,13 +3752,6 @@ private void InitializeComponent()
|
|||
this.cbUpasteIsPublic.UseVisualStyleBackColor = true;
|
||||
this.cbUpasteIsPublic.CheckedChanged += new System.EventHandler(this.cbUpasteIsPublic_CheckedChanged);
|
||||
//
|
||||
// cbPastieIsPublic
|
||||
//
|
||||
resources.ApplyResources(this.cbPastieIsPublic, "cbPastieIsPublic");
|
||||
this.cbPastieIsPublic.Name = "cbPastieIsPublic";
|
||||
this.cbPastieIsPublic.UseVisualStyleBackColor = true;
|
||||
this.cbPastieIsPublic.CheckedChanged += new System.EventHandler(this.cbPastieIsPublic_CheckedChanged);
|
||||
//
|
||||
// lblUpasteUserKey
|
||||
//
|
||||
resources.ApplyResources(this.lblUpasteUserKey, "lblUpasteUserKey");
|
||||
|
@ -3838,6 +3849,7 @@ private void InitializeComponent()
|
|||
resources.ApplyResources(this.cbPastieIsPublic, "cbPastieIsPublic");
|
||||
this.cbPastieIsPublic.Name = "cbPastieIsPublic";
|
||||
this.cbPastieIsPublic.UseVisualStyleBackColor = true;
|
||||
this.cbPastieIsPublic.CheckedChanged += new System.EventHandler(this.cbPastieIsPublic_CheckedChanged);
|
||||
//
|
||||
// tpImageUploaders
|
||||
//
|
||||
|
@ -3877,6 +3889,13 @@ private void InitializeComponent()
|
|||
this.tpImgur.Name = "tpImgur";
|
||||
this.tpImgur.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// cbImgurUseHTTPS
|
||||
//
|
||||
resources.ApplyResources(this.cbImgurUseHTTPS, "cbImgurUseHTTPS");
|
||||
this.cbImgurUseHTTPS.Name = "cbImgurUseHTTPS";
|
||||
this.cbImgurUseHTTPS.UseVisualStyleBackColor = true;
|
||||
this.cbImgurUseHTTPS.CheckedChanged += new System.EventHandler(this.cbImgurUseHTTPS_CheckedChanged);
|
||||
//
|
||||
// cbImgurUseGIFV
|
||||
//
|
||||
resources.ApplyResources(this.cbImgurUseGIFV, "cbImgurUseGIFV");
|
||||
|
@ -4498,13 +4517,6 @@ private void InitializeComponent()
|
|||
this.actRapidShareAccountType.Name = "actRapidShareAccountType";
|
||||
this.actRapidShareAccountType.SelectedAccountType = ShareX.UploadersLib.AccountType.Anonymous;
|
||||
//
|
||||
// cbImgurUseHTTPS
|
||||
//
|
||||
resources.ApplyResources(this.cbImgurUseHTTPS, "cbImgurUseHTTPS");
|
||||
this.cbImgurUseHTTPS.Name = "cbImgurUseHTTPS";
|
||||
this.cbImgurUseHTTPS.UseVisualStyleBackColor = true;
|
||||
this.cbImgurUseHTTPS.CheckedChanged += new System.EventHandler(this.cbImgurUseHTTPS_CheckedChanged);
|
||||
//
|
||||
// UploadersConfigForm
|
||||
//
|
||||
resources.ApplyResources(this, "$this");
|
||||
|
@ -5198,5 +5210,7 @@ private void InitializeComponent()
|
|||
private System.Windows.Forms.CheckBox cbImgurUseHTTPS;
|
||||
public System.Windows.Forms.TabPage tpPastie;
|
||||
private System.Windows.Forms.CheckBox cbPastieIsPublic;
|
||||
private System.Windows.Forms.CheckBox cbPolrUseAPIv1;
|
||||
private System.Windows.Forms.CheckBox cbPolrIsSecret;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -631,6 +631,8 @@ public void LoadSettings()
|
|||
|
||||
txtPolrAPIHostname.Text = Config.PolrAPIHostname;
|
||||
txtPolrAPIKey.Text = Config.PolrAPIKey;
|
||||
cbPolrIsSecret.Checked = Config.PolrIsSecret;
|
||||
cbPolrUseAPIv1.Checked = Config.PolrUseAPIv1;
|
||||
|
||||
#endregion URL shorteners
|
||||
|
||||
|
@ -2744,6 +2746,16 @@ private void txtPolrAPIKey_TextChanged(object sender, EventArgs e)
|
|||
Config.PolrAPIKey = txtPolrAPIKey.Text;
|
||||
}
|
||||
|
||||
private void cbPolrIsSecret_CheckedChanged(object sender, EventArgs e)
|
||||
{
|
||||
Config.PolrIsSecret = cbPolrIsSecret.Checked;
|
||||
}
|
||||
|
||||
private void cbPolrUseAPIv1_CheckedChanged(object sender, EventArgs e)
|
||||
{
|
||||
Config.PolrUseAPIv1 = cbPolrUseAPIv1.Checked;
|
||||
}
|
||||
|
||||
#endregion Polr
|
||||
|
||||
#endregion URL Shorteners
|
||||
|
|
|
@ -3256,11 +3256,71 @@ store.book[0].title</value>
|
|||
<data name=">>tpCoinURL.ZOrder" xml:space="preserve">
|
||||
<value>4</value>
|
||||
</data>
|
||||
<data name="cbPolrUseAPIv1.AutoSize" type="System.Boolean, mscorlib">
|
||||
<value>True</value>
|
||||
</data>
|
||||
<data name="cbPolrUseAPIv1.ImeMode" type="System.Windows.Forms.ImeMode, System.Windows.Forms">
|
||||
<value>NoControl</value>
|
||||
</data>
|
||||
<data name="cbPolrUseAPIv1.Location" type="System.Drawing.Point, System.Drawing">
|
||||
<value>16, 128</value>
|
||||
</data>
|
||||
<data name="cbPolrUseAPIv1.Size" type="System.Drawing.Size, System.Drawing">
|
||||
<value>137, 17</value>
|
||||
</data>
|
||||
<data name="cbPolrUseAPIv1.TabIndex" type="System.Int32, mscorlib">
|
||||
<value>15</value>
|
||||
</data>
|
||||
<data name="cbPolrUseAPIv1.Text" xml:space="preserve">
|
||||
<value>Use deprecated API v1</value>
|
||||
</data>
|
||||
<data name=">>cbPolrUseAPIv1.Name" xml:space="preserve">
|
||||
<value>cbPolrUseAPIv1</value>
|
||||
</data>
|
||||
<data name=">>cbPolrUseAPIv1.Type" xml:space="preserve">
|
||||
<value>System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</data>
|
||||
<data name=">>cbPolrUseAPIv1.Parent" xml:space="preserve">
|
||||
<value>tpPolr</value>
|
||||
</data>
|
||||
<data name=">>cbPolrUseAPIv1.ZOrder" xml:space="preserve">
|
||||
<value>0</value>
|
||||
</data>
|
||||
<data name="cbPolrIsSecret.AutoSize" type="System.Boolean, mscorlib">
|
||||
<value>True</value>
|
||||
</data>
|
||||
<data name="cbPolrIsSecret.ImeMode" type="System.Windows.Forms.ImeMode, System.Windows.Forms">
|
||||
<value>NoControl</value>
|
||||
</data>
|
||||
<data name="cbPolrIsSecret.Location" type="System.Drawing.Point, System.Drawing">
|
||||
<value>16, 104</value>
|
||||
</data>
|
||||
<data name="cbPolrIsSecret.Size" type="System.Drawing.Size, System.Drawing">
|
||||
<value>91, 17</value>
|
||||
</data>
|
||||
<data name="cbPolrIsSecret.TabIndex" type="System.Int32, mscorlib">
|
||||
<value>14</value>
|
||||
</data>
|
||||
<data name="cbPolrIsSecret.Text" xml:space="preserve">
|
||||
<value>Is secret URL</value>
|
||||
</data>
|
||||
<data name=">>cbPolrIsSecret.Name" xml:space="preserve">
|
||||
<value>cbPolrIsSecret</value>
|
||||
</data>
|
||||
<data name=">>cbPolrIsSecret.Type" xml:space="preserve">
|
||||
<value>System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</data>
|
||||
<data name=">>cbPolrIsSecret.Parent" xml:space="preserve">
|
||||
<value>tpPolr</value>
|
||||
</data>
|
||||
<data name=">>cbPolrIsSecret.ZOrder" xml:space="preserve">
|
||||
<value>1</value>
|
||||
</data>
|
||||
<data name="txtPolrAPIKey.Location" type="System.Drawing.Point, System.Drawing">
|
||||
<value>16, 72</value>
|
||||
</data>
|
||||
<data name="txtPolrAPIKey.Size" type="System.Drawing.Size, System.Drawing">
|
||||
<value>224, 20</value>
|
||||
<value>296, 20</value>
|
||||
</data>
|
||||
<data name="txtPolrAPIKey.TabIndex" type="System.Int32, mscorlib">
|
||||
<value>13</value>
|
||||
|
@ -3275,7 +3335,7 @@ store.book[0].title</value>
|
|||
<value>tpPolr</value>
|
||||
</data>
|
||||
<data name=">>txtPolrAPIKey.ZOrder" xml:space="preserve">
|
||||
<value>0</value>
|
||||
<value>2</value>
|
||||
</data>
|
||||
<data name="lblPolrAPIKey.AutoSize" type="System.Boolean, mscorlib">
|
||||
<value>True</value>
|
||||
|
@ -3305,13 +3365,13 @@ store.book[0].title</value>
|
|||
<value>tpPolr</value>
|
||||
</data>
|
||||
<data name=">>lblPolrAPIKey.ZOrder" xml:space="preserve">
|
||||
<value>1</value>
|
||||
<value>3</value>
|
||||
</data>
|
||||
<data name="txtPolrAPIHostname.Location" type="System.Drawing.Point, System.Drawing">
|
||||
<value>16, 32</value>
|
||||
</data>
|
||||
<data name="txtPolrAPIHostname.Size" type="System.Drawing.Size, System.Drawing">
|
||||
<value>224, 20</value>
|
||||
<value>296, 20</value>
|
||||
</data>
|
||||
<data name="txtPolrAPIHostname.TabIndex" type="System.Int32, mscorlib">
|
||||
<value>11</value>
|
||||
|
@ -3326,7 +3386,7 @@ store.book[0].title</value>
|
|||
<value>tpPolr</value>
|
||||
</data>
|
||||
<data name=">>txtPolrAPIHostname.ZOrder" xml:space="preserve">
|
||||
<value>2</value>
|
||||
<value>4</value>
|
||||
</data>
|
||||
<data name="lblPolrAPIHostname.AutoSize" type="System.Boolean, mscorlib">
|
||||
<value>True</value>
|
||||
|
@ -3338,13 +3398,13 @@ store.book[0].title</value>
|
|||
<value>13, 16</value>
|
||||
</data>
|
||||
<data name="lblPolrAPIHostname.Size" type="System.Drawing.Size, System.Drawing">
|
||||
<value>373, 13</value>
|
||||
<value>286, 13</value>
|
||||
</data>
|
||||
<data name="lblPolrAPIHostname.TabIndex" type="System.Int32, mscorlib">
|
||||
<value>10</value>
|
||||
</data>
|
||||
<data name="lblPolrAPIHostname.Text" xml:space="preserve">
|
||||
<value>API hostname: (e.g. http://example.com/api.php, Leave blank to use polr.me)</value>
|
||||
<value>API URL: (e.g. http://demo.polr.me/api/v2/action/shorten)</value>
|
||||
</data>
|
||||
<data name=">>lblPolrAPIHostname.Name" xml:space="preserve">
|
||||
<value>lblPolrAPIHostname</value>
|
||||
|
@ -3356,7 +3416,7 @@ store.book[0].title</value>
|
|||
<value>tpPolr</value>
|
||||
</data>
|
||||
<data name=">>lblPolrAPIHostname.ZOrder" xml:space="preserve">
|
||||
<value>3</value>
|
||||
<value>5</value>
|
||||
</data>
|
||||
<data name="tpPolr.Location" type="System.Drawing.Point, System.Drawing">
|
||||
<value>4, 22</value>
|
||||
|
@ -3644,7 +3704,7 @@ store.book[0].title</value>
|
|||
<value>4, 4, 4, 4</value>
|
||||
</data>
|
||||
<data name="ucFTPAccounts.Size" type="System.Drawing.Size, System.Drawing">
|
||||
<value>792, 432</value>
|
||||
<value>792, 414</value>
|
||||
</data>
|
||||
<data name="ucFTPAccounts.TabIndex" type="System.Int32, mscorlib">
|
||||
<value>6</value>
|
||||
|
@ -11395,6 +11455,9 @@ Using an encrypted library disables sharing.</value>
|
|||
<data name="cbPastieIsPublic.AutoSize" type="System.Boolean, mscorlib">
|
||||
<value>True</value>
|
||||
</data>
|
||||
<data name="cbPastieIsPublic.ImeMode" type="System.Windows.Forms.ImeMode, System.Windows.Forms">
|
||||
<value>NoControl</value>
|
||||
</data>
|
||||
<data name="cbPastieIsPublic.Location" type="System.Drawing.Point, System.Drawing">
|
||||
<value>17, 22</value>
|
||||
</data>
|
||||
|
@ -11500,6 +11563,9 @@ Using an encrypted library disables sharing.</value>
|
|||
<data name="cbImgurUseHTTPS.AutoSize" type="System.Boolean, mscorlib">
|
||||
<value>True</value>
|
||||
</data>
|
||||
<data name="cbImgurUseHTTPS.ImeMode" type="System.Windows.Forms.ImeMode, System.Windows.Forms">
|
||||
<value>NoControl</value>
|
||||
</data>
|
||||
<data name="cbImgurUseHTTPS.Location" type="System.Drawing.Point, System.Drawing">
|
||||
<value>16, 376</value>
|
||||
</data>
|
||||
|
|
|
@ -41,15 +41,17 @@ public class PolrURLShortenerService : URLShortenerService
|
|||
|
||||
public override bool CheckConfig(UploadersConfig config)
|
||||
{
|
||||
return !string.IsNullOrEmpty(config.PolrAPIKey);
|
||||
return !string.IsNullOrEmpty(config.PolrAPIHostname) && !string.IsNullOrEmpty(config.PolrAPIKey);
|
||||
}
|
||||
|
||||
public override URLShortener CreateShortener(UploadersConfig config, TaskReferenceHelper taskInfo)
|
||||
{
|
||||
return new PolrURLShortener
|
||||
{
|
||||
API_HOST = config.PolrAPIHostname,
|
||||
API_KEY = config.PolrAPIKey
|
||||
Host = config.PolrAPIHostname,
|
||||
Key = config.PolrAPIKey,
|
||||
IsSecret = config.PolrIsSecret,
|
||||
UseAPIv1 = config.PolrUseAPIv1
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -58,34 +60,44 @@ public override URLShortener CreateShortener(UploadersConfig config, TaskReferen
|
|||
|
||||
public sealed class PolrURLShortener : URLShortener
|
||||
{
|
||||
public string API_HOST { get; set; }
|
||||
public string API_KEY { get; set; }
|
||||
public string Host { get; set; }
|
||||
public string Key { get; set; }
|
||||
public bool IsSecret { get; set; }
|
||||
public bool UseAPIv1 { get; set; }
|
||||
|
||||
public override UploadResult ShortenURL(string url)
|
||||
{
|
||||
UploadResult result = new UploadResult { URL = url };
|
||||
|
||||
if (string.IsNullOrEmpty(API_HOST))
|
||||
{
|
||||
API_HOST = "https://polr.me/publicapi.php";
|
||||
API_KEY = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
API_HOST = URLHelpers.FixPrefix(API_HOST);
|
||||
}
|
||||
Host = URLHelpers.FixPrefix(Host);
|
||||
|
||||
Dictionary<string, string> args = new Dictionary<string, string>();
|
||||
|
||||
if (!string.IsNullOrEmpty(API_KEY))
|
||||
if (!string.IsNullOrEmpty(Key))
|
||||
{
|
||||
args.Add("apikey", API_KEY);
|
||||
if (UseAPIv1)
|
||||
{
|
||||
args.Add("apikey", Key);
|
||||
}
|
||||
else
|
||||
{
|
||||
args.Add("key", Key);
|
||||
}
|
||||
}
|
||||
|
||||
if (UseAPIv1)
|
||||
{
|
||||
args.Add("action", "shorten");
|
||||
}
|
||||
|
||||
args.Add("action", "shorten");
|
||||
args.Add("url", url);
|
||||
|
||||
string response = SendRequest(HttpMethod.GET, API_HOST, args);
|
||||
if (IsSecret && !UseAPIv1)
|
||||
{
|
||||
args.Add("is_secret", "true");
|
||||
}
|
||||
|
||||
string response = SendRequest(HttpMethod.GET, Host, args);
|
||||
|
||||
if (!string.IsNullOrEmpty(response))
|
||||
{
|
||||
|
|
|
@ -329,6 +329,8 @@ public class UploadersConfig : SettingsBase<UploadersConfig>
|
|||
// polr
|
||||
public string PolrAPIHostname = "";
|
||||
public string PolrAPIKey = "";
|
||||
public bool PolrIsSecret = false;
|
||||
public bool PolrUseAPIv1 = false;
|
||||
|
||||
#endregion URL shorteners
|
||||
|
||||
|
|
Loading…
Reference in a new issue