mirror of
https://github.com/ShareX/ShareX.git
synced 2024-06-28 11:10:23 +12:00
Added Kutt URL shortener support
This commit is contained in:
parent
820d5514e2
commit
9dede046d4
|
@ -173,6 +173,8 @@ public enum UrlShortenerType
|
|||
Polr,
|
||||
[Description("Firebase Dynamic Links")]
|
||||
FirebaseDynamicLinks,
|
||||
[Description("Kutt")]
|
||||
Kutt,
|
||||
CustomURLShortener // Localized
|
||||
}
|
||||
|
||||
|
|
BIN
ShareX.UploadersLib/Favicons/Kutt.png
Normal file
BIN
ShareX.UploadersLib/Favicons/Kutt.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 853 B |
2903
ShareX.UploadersLib/Forms/UploadersConfigForm.Designer.cs
generated
2903
ShareX.UploadersLib/Forms/UploadersConfigForm.Designer.cs
generated
File diff suppressed because it is too large
Load diff
|
@ -805,6 +805,15 @@ public void LoadSettings()
|
|||
|
||||
#endregion Firebase Dynamic Links
|
||||
|
||||
#region Kutt
|
||||
|
||||
txtKuttHost.Text = Config.KuttSettings.Host;
|
||||
txtKuttAPIKey.Text = Config.KuttSettings.APIKey;
|
||||
txtKuttPassword.Text = Config.KuttSettings.Password;
|
||||
cbKuttReuse.Checked = Config.KuttSettings.Reuse;
|
||||
|
||||
#endregion Kutt
|
||||
|
||||
#endregion URL shorteners
|
||||
|
||||
#region Other uploaders
|
||||
|
@ -3246,6 +3255,30 @@ private void cbFirebaseIsShort_CheckedChanged(object sender, EventArgs e)
|
|||
|
||||
#endregion Firebase Dynamic Links
|
||||
|
||||
#region Kutt
|
||||
|
||||
private void txtKuttHost_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
Config.KuttSettings.Host = txtKuttHost.Text;
|
||||
}
|
||||
|
||||
private void txtKuttAPIKey_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
Config.KuttSettings.APIKey = txtKuttAPIKey.Text;
|
||||
}
|
||||
|
||||
private void txtKuttPassword_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
Config.KuttSettings.Password = txtKuttPassword.Text;
|
||||
}
|
||||
|
||||
private void cbKuttReuse_CheckedChanged(object sender, EventArgs e)
|
||||
{
|
||||
Config.KuttSettings.Reuse = cbKuttReuse.Checked;
|
||||
}
|
||||
|
||||
#endregion Kutt
|
||||
|
||||
#endregion URL shorteners
|
||||
|
||||
#region Other uploaders
|
||||
|
|
File diff suppressed because it is too large
Load diff
10
ShareX.UploadersLib/Properties/Resources.Designer.cs
generated
10
ShareX.UploadersLib/Properties/Resources.Designer.cs
generated
|
@ -381,6 +381,16 @@ internal class Resources {
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized resource of type System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
internal static System.Drawing.Bitmap Kutt {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("Kutt", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized resource of type System.Drawing.Icon similar to (Icon).
|
||||
/// </summary>
|
||||
|
|
|
@ -410,4 +410,7 @@ Created folders:</value>
|
|||
<data name="BackblazeB2" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Favicons\BackblazeB2.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="Kutt" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Favicons\Kutt.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
</root>
|
|
@ -339,6 +339,7 @@
|
|||
<Compile Include="BaseUploaders\URLShortener.cs" />
|
||||
<Compile Include="BaseServices\URLShortenerService.cs" />
|
||||
<Compile Include="URLShorteners\FirebaseDynamicLinksURLShortener.cs" />
|
||||
<Compile Include="URLShorteners\KuttURLShortener.cs" />
|
||||
<Compile Include="URLShorteners\PolrURLShortener.cs" />
|
||||
<Compile Include="URLShorteners\TwoGPURLShortener.cs" />
|
||||
<Compile Include="URLShorteners\AdFlyURLShortener.cs" />
|
||||
|
@ -1008,6 +1009,9 @@
|
|||
<Version>2016.1.0</Version>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Favicons\Kutt.png" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<PropertyGroup>
|
||||
<PreBuildEvent>
|
||||
|
|
143
ShareX.UploadersLib/URLShorteners/KuttURLShortener.cs
Normal file
143
ShareX.UploadersLib/URLShorteners/KuttURLShortener.cs
Normal file
|
@ -0,0 +1,143 @@
|
|||
#region License Information (GPL v3)
|
||||
|
||||
/*
|
||||
ShareX - A program that allows you to take screenshots and share any file type
|
||||
Copyright (c) 2007-2018 ShareX Team
|
||||
|
||||
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 ShareX.UploadersLib.Properties;
|
||||
using System.Collections.Specialized;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace ShareX.UploadersLib.URLShorteners
|
||||
{
|
||||
public class KuttURLShortenerService : URLShortenerService
|
||||
{
|
||||
public override UrlShortenerType EnumValue { get; } = UrlShortenerType.Kutt;
|
||||
|
||||
public override Image ServiceImage => Resources.Kutt;
|
||||
|
||||
public override bool CheckConfig(UploadersConfig config)
|
||||
{
|
||||
return !string.IsNullOrEmpty(config.KuttSettings.APIKey);
|
||||
}
|
||||
|
||||
public override URLShortener CreateShortener(UploadersConfig config, TaskReferenceHelper taskInfo)
|
||||
{
|
||||
return new KuttURLShortener(config.KuttSettings);
|
||||
}
|
||||
|
||||
public override TabPage GetUploadersConfigTabPage(UploadersConfigForm form) => form.tpKutt;
|
||||
}
|
||||
|
||||
public sealed class KuttURLShortener : URLShortener
|
||||
{
|
||||
public KuttSettings Settings { get; set; }
|
||||
|
||||
public KuttURLShortener(KuttSettings settings)
|
||||
{
|
||||
Settings = settings;
|
||||
}
|
||||
|
||||
public override UploadResult ShortenURL(string url)
|
||||
{
|
||||
UploadResult result = new UploadResult { URL = url };
|
||||
result.ShortenedURL = Submit(url);
|
||||
return result;
|
||||
}
|
||||
|
||||
public string Submit(string url)
|
||||
{
|
||||
if (string.IsNullOrEmpty(Settings.Host))
|
||||
{
|
||||
Settings.Host = "https://kutt.it";
|
||||
}
|
||||
else
|
||||
{
|
||||
Settings.Host = URLHelpers.FixPrefix(Settings.Host);
|
||||
}
|
||||
|
||||
string requestURL = URLHelpers.CombineURL(Settings.Host, "/api/url/submit");
|
||||
|
||||
KuttSubmitRequest body = new KuttSubmitRequest()
|
||||
{
|
||||
target = url,
|
||||
customurl = null,
|
||||
password = Settings.Password,
|
||||
reuse = Settings.Reuse
|
||||
};
|
||||
|
||||
string json = JsonConvert.SerializeObject(body);
|
||||
|
||||
NameValueCollection headers = new NameValueCollection();
|
||||
headers.Add("X-API-Key", Settings.APIKey);
|
||||
|
||||
string response = SendRequest(HttpMethod.POST, requestURL, json, ContentTypeJSON, headers: headers);
|
||||
|
||||
if (!string.IsNullOrEmpty(response))
|
||||
{
|
||||
KuttSubmitResponse submitResponse = JsonConvert.DeserializeObject<KuttSubmitResponse>(response);
|
||||
|
||||
if (submitResponse != null)
|
||||
{
|
||||
return submitResponse.shortUrl;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private class KuttSubmitRequest
|
||||
{
|
||||
/// <summary>Original long URL to be shortened.</summary>
|
||||
public string target { get; set; }
|
||||
|
||||
/// <summary>(optional) Set a custom URL.</summary>
|
||||
public string customurl { get; set; }
|
||||
|
||||
/// <summary>(optional) Set a password.</summary>
|
||||
public string password { get; set; }
|
||||
|
||||
/// <summary>(optional) If a URL with the specified target exists returns it, otherwise will send a new shortened URL.</summary>
|
||||
public bool reuse { get; set; }
|
||||
}
|
||||
|
||||
private class KuttSubmitResponse
|
||||
{
|
||||
/// <summary>Unique ID of the URL</summary>
|
||||
public string id { get; set; }
|
||||
|
||||
/// <summary>The shortened link</summary>
|
||||
public string shortUrl { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
public class KuttSettings
|
||||
{
|
||||
public string APIKey { get; set; }
|
||||
public string Host { get; set; } = "https://kutt.it";
|
||||
public string Password { get; set; }
|
||||
public bool Reuse { get; set; }
|
||||
}
|
||||
}
|
|
@ -28,6 +28,7 @@
|
|||
using ShareX.UploadersLib.FileUploaders;
|
||||
using ShareX.UploadersLib.ImageUploaders;
|
||||
using ShareX.UploadersLib.TextUploaders;
|
||||
using ShareX.UploadersLib.URLShorteners;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ShareX.UploadersLib
|
||||
|
@ -456,6 +457,12 @@ public class UploadersConfig : SettingsBase<UploadersConfig>
|
|||
|
||||
#endregion Firebase Dynamic Links
|
||||
|
||||
#region Kutt
|
||||
|
||||
public KuttSettings KuttSettings = new KuttSettings();
|
||||
|
||||
#endregion Kutt
|
||||
|
||||
#endregion URL shorteners
|
||||
|
||||
#region Other uploaders
|
||||
|
|
Loading…
Reference in a new issue