Add Self-Hosted Polr support

This commit is contained in:
Daniel McAssey 2015-08-04 19:49:07 +01:00
parent ef8b070c76
commit 4aa71f9bc7
11 changed files with 6448 additions and 1600 deletions

View file

@ -168,6 +168,8 @@ public enum UrlShortenerType
VURL,
[Description("2.gp")]
TwoGP,
[Description("Polr")]
Polr,
CustomURLShortener // Localized
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

File diff suppressed because it is too large Load diff

View file

@ -116,6 +116,7 @@ private void FormSettings()
AddIconToTab(tpLambda, Resources.Lambda);
AddIconToTab(tpUp1, Resources.Up1);
AddIconToTab(tpOneTimeSecret, Resources.OneTimeSecret);
AddIconToTab(tpPolr, Resources.Polr);
tcFileUploaders.TabPages.Remove(tpHubic);
@ -2190,6 +2191,20 @@ private void txtCoinURLUUID_TextChanged(object sender, EventArgs e)
#endregion CoinURL
#region Polr
private void txtPolrAPIHostname_TextChanged(object sender, EventArgs e)
{
Config.PolrAPIHostname = txtPolrAPIHostname.Text;
}
private void txtPolrAPIKey_TextChanged(object sender, EventArgs e)
{
Config.PolrAPIKey = txtPolrAPIKey.Text;
}
#endregion Polr
#endregion URL Shorteners
#region Other Uploaders

File diff suppressed because it is too large Load diff

View file

@ -846,6 +846,16 @@ internal class Resources {
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Icon similar to (Icon).
/// </summary>
internal static System.Drawing.Icon Polr {
get {
object obj = ResourceManager.GetObject("Polr", resourceCulture);
return ((System.Drawing.Icon)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Icon similar to (Icon).
/// </summary>

View file

@ -470,4 +470,7 @@ Created folders:</value>
<data name="OneTimeSecret" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Favicons\OneTimeSecret.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="Polr" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Favicons\Polr.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>

View file

@ -287,6 +287,7 @@
<Compile Include="TextUploaders\Slexy.cs" />
<Compile Include="Uploader.cs" />
<Compile Include="URLShortener.cs" />
<Compile Include="URLShorteners\PolrURLShortener.cs" />
<Compile Include="URLShorteners\TwoGPURLShortener.cs" />
<Compile Include="URLShorteners\AdFlyURLShortener.cs" />
<Compile Include="URLShorteners\BitlyURLShortener.cs" />
@ -706,6 +707,7 @@
<None Include="Favicons\Mega.ico" />
<None Include="Favicons\Picasa.ico" />
<None Include="Favicons\OneTimeSecret.ico" />
<None Include="Favicons\Polr.ico" />
<None Include="packages.config" />
<None Include="Resources\server-network.png" />
<None Include="Resources\mail.png" />

View file

@ -0,0 +1,62 @@
#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 <http://www.gnu.org/licenses/>.
*/
#endregion License Information (GPL v3)
using Newtonsoft.Json;
using ShareX.HelpersLib;
using System.Collections.Generic;
namespace ShareX.UploadersLib.URLShorteners
{
public sealed class PolrURLShortener : URLShortener
{
public string API_KEY { get; set; }
public string API_HOST { get; set; }
public override UploadResult ShortenURL(string url)
{
UploadResult result = new UploadResult { URL = url };
if (string.IsNullOrEmpty(API_HOST))
{
API_HOST = "https://polr.me";
}
Dictionary<string, string> args = new Dictionary<string, string>();
args.Add("apikey", API_KEY);
args.Add("action", "shorten");
args.Add("url", url);
string response = SendRequest(HttpMethod.GET, URLHelpers.CombineURL(API_HOST, "api.php"), args);
if (!string.IsNullOrEmpty(response))
{
result.ShortenedURL = response;
}
return result;
}
}
}

View file

@ -287,6 +287,10 @@ public class UploadersConfig : SettingsBase<UploadersConfig>
// coinurl.com
public string CoinURLUUID = string.Empty;
// polr
public string PolrAPIHostname = string.Empty;
public string PolrAPIKey = string.Empty;
#endregion URL shorteners
#region URL sharing services
@ -446,6 +450,8 @@ public bool IsValid(UrlShortenerType destination)
return !string.IsNullOrEmpty(LnkUAPIKEY);
case UrlShortenerType.CoinURL:
return !string.IsNullOrEmpty(CoinURLUUID);
case UrlShortenerType.Polr:
return !string.IsNullOrEmpty(PolrAPIKey);
case UrlShortenerType.CustomURLShortener:
return CustomUploadersList != null && CustomUploadersList.IsValidIndex(CustomURLShortenerSelected);
}

View file

@ -1125,6 +1125,13 @@ public UploadResult ShortenURL(string url)
case UrlShortenerType.TwoGP:
urlShortener = new TwoGPURLShortener();
break;
case UrlShortenerType.Polr:
urlShortener = new PolrURLShortener
{
API_HOST = Program.UploadersConfig.PolrAPIHostname,
API_KEY = Program.UploadersConfig.PolrAPIKey
};
break;
case UrlShortenerType.CustomURLShortener:
CustomUploaderItem customUploader = GetCustomUploader(Program.UploadersConfig.CustomURLShortenerSelected);
if (customUploader != null)