diff --git a/Core/Resgrid.Config/LinksConfig.cs b/Core/Resgrid.Config/LinksConfig.cs index a2cddec9..4a0bd2dc 100644 --- a/Core/Resgrid.Config/LinksConfig.cs +++ b/Core/Resgrid.Config/LinksConfig.cs @@ -7,6 +7,9 @@ public static class LinksConfig public static string PolrAccessToken = ""; public static string PolrApi = @""; + + public static string KuttAccessToken = ""; + public static string KuttApi = @""; } /// @@ -15,6 +18,7 @@ public static class LinksConfig public enum LinksProviderTypes { Bitly = 0, - Polr = 1 + Polr = 1, + Kutt = 2 } } diff --git a/Providers/Resgrid.Providers.Marketing/ShortenUrlProvider.cs b/Providers/Resgrid.Providers.Marketing/ShortenUrlProvider.cs index 5dba50ba..b7801969 100644 --- a/Providers/Resgrid.Providers.Marketing/ShortenUrlProvider.cs +++ b/Providers/Resgrid.Providers.Marketing/ShortenUrlProvider.cs @@ -1,9 +1,12 @@ //https://github.com/sonnd9x/Bitly.Net/blob/master/Bitly.Net/BitlyAPI.cs +using System; using System.Net; using System.Net.Http; using System.Threading.Tasks; +using MongoDB.Driver; using Newtonsoft.Json; +using Resgrid.Framework; using Resgrid.Model.Providers; namespace Resgrid.Providers.Marketing @@ -96,6 +99,47 @@ public async Task Shorten(string long_url) } } } + else if (Config.SystemBehaviorConfig.LinkProviderType == Config.LinksProviderTypes.Kutt) + { + try + { + using (HttpClient client = new HttpClient()) + { + client.DefaultRequestHeaders.Add("X-API-KEY", Config.LinksConfig.KuttAccessToken); + client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + + var requestBody = new + { + target = long_url, + reuse = true, // resuse the same short url for the same target + //customSlug = customSlug, + //domain = domain + }; + + var jsonContent = JsonConvert.SerializeObject(requestBody); + var content = new StringContent(jsonContent, System.Text.Encoding.UTF8, "application/json"); + + // Make POST request to the Kutt API + var response = await client.PostAsync(Config.LinksConfig.KuttApi + "/api/v2/links", content); + + if (response.IsSuccessStatusCode) + { + var responseContent = await response.Content.ReadAsStringAsync(); + dynamic result = JsonConvert.DeserializeObject(responseContent); + return result.link; // Assuming the API returns the short URL in a 'link' property + } + else + { + var error = await response.Content.ReadAsStringAsync(); + Logging.LogError($"Failed to create Kutt short URL: {error}"); + } + } + } + catch (Exception ex) + { + Logging.LogException(ex); + } + } return "Can not short URL"; } diff --git a/Web/Resgrid.Web/Views/Shared/_Layout.cshtml b/Web/Resgrid.Web/Views/Shared/_Layout.cshtml index 56e296e0..ebf32c55 100644 --- a/Web/Resgrid.Web/Views/Shared/_Layout.cshtml +++ b/Web/Resgrid.Web/Views/Shared/_Layout.cshtml @@ -23,17 +23,6 @@ { @RenderSection("Styles", required: false) } - - @if (!String.IsNullOrWhiteSpace(Resgrid.Config.TelemetryConfig.PostHogUrl) && !String.IsNullOrWhiteSpace(Resgrid.Config.TelemetryConfig.PostHogApiKey)) - { - - } diff --git a/Web/Resgrid.Web/wwwroot/js/app/internal/contacts/resgrid.contacts.index.js b/Web/Resgrid.Web/wwwroot/js/app/internal/contacts/resgrid.contacts.index.js index 21a84770..57101bfc 100644 --- a/Web/Resgrid.Web/wwwroot/js/app/internal/contacts/resgrid.contacts.index.js +++ b/Web/Resgrid.Web/wwwroot/js/app/internal/contacts/resgrid.contacts.index.js @@ -10,7 +10,6 @@ var resgrid; $('.table').DataTable(); $('#tree').bstreeview({ data: treeData }); - $('input[type="checkbox"]').click(evaluate); $('#TreeGroup_-1').css("font-weight", "bold"); $(document).on('click', '.list-group-item', function (e) {