diff --git a/Apprise/Communication/Apprise.cs b/Apprise/Communication/Apprise.cs index 2a6ac4db..03e2a2f2 100644 --- a/Apprise/Communication/Apprise.cs +++ b/Apprise/Communication/Apprise.cs @@ -44,54 +44,64 @@ public class Apprise: Node public override int Execute(NodeParameters args) { - var settings = args.GetPluginSettings(); - - if (string.IsNullOrWhiteSpace(settings?.Endpoint)) + try { - args.Logger?.WLog("No endpoint set"); - return 2; - } - if (string.IsNullOrWhiteSpace(settings?.ServerUrl)) - { - args.Logger?.WLog("No server URL set"); - return 2; - } + var settings = args.GetPluginSettings(); - string url = settings.ServerUrl; - if (url.EndsWith("/") == false) - url += "/"; - if (settings.Endpoint.EndsWith("/")) - url += settings.Endpoint[1..]; - else - url += settings.Endpoint; + if (string.IsNullOrWhiteSpace(settings?.Endpoint)) + { + args.Logger?.WLog("No endpoint set"); + return 2; + } - string message = args.ReplaceVariables(this.Message); - if (string.IsNullOrWhiteSpace(message)) - { - args.Logger?.WLog("No message to send"); - return 2; - } + if (string.IsNullOrWhiteSpace(settings?.ServerUrl)) + { + args.Logger?.WLog("No server URL set"); + return 2; + } - object data = new - { - body = message, - tag = Tag?.Any() != true ? "all" : String.Join(";", this.Tag), - type = this.MessageType?.EmptyAsNull() ?? "info" - }; + string url = settings.ServerUrl; + if (url.EndsWith("/") == false) + url += "/"; + if (settings.Endpoint.EndsWith("/")) + url += settings.Endpoint[1..]; + else + url += settings.Endpoint; + + string message = args.ReplaceVariables(this.Message); + if (string.IsNullOrWhiteSpace(message)) + { + args.Logger?.WLog("No message to send"); + return 2; + } + + object data = new + { + body = message, + tag = Tag?.Any() != true ? "all" : String.Join(";", this.Tag), + type = this.MessageType?.EmptyAsNull() ?? "info" + }; #pragma warning disable IL2026 // Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code - var json = JsonSerializer.Serialize(data); + var json = JsonSerializer.Serialize(data); #pragma warning restore IL2026 // Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code - var content = new StringContent(json, Encoding.UTF8, "application/json"); + var content = new StringContent(json, Encoding.UTF8, "application/json"); - using var httpClient = new HttpClient(); - var response = httpClient.PostAsync(url, content).Result; - if (response.IsSuccessStatusCode) - return 1; + using var httpClient = new HttpClient(); + var response = httpClient.PostAsync(url, content).Result; + if (response.IsSuccessStatusCode) + return 1; - string error = response.Content.ReadAsStringAsync().Result; - args.Logger?.WLog("Error from Apprise: " + error); - return 2; + string error = response.Content.ReadAsStringAsync().Result; + args.Logger?.WLog("Error from Apprise: " + error); + return 2; + + } + catch (Exception ex) + { + args.Logger?.WLog("Error sending message: " + ex.Message); + return 2; + } } } diff --git a/BasicNodes/Conditions/IfString.cs b/BasicNodes/Conditions/IfString.cs index bcd10a80..2284228c 100644 --- a/BasicNodes/Conditions/IfString.cs +++ b/BasicNodes/Conditions/IfString.cs @@ -12,7 +12,7 @@ public class IfString: IfBase /// /// Gets or sets the URL to the help page /// - public override string HelpUrl => "https://fileflows.com/docs/plugins/basic-nodes/conditions/if-boolean"; + public override string HelpUrl => "https://fileflows.com/docs/plugins/basic-nodes/conditions/if-string"; /// /// Gets the number of outputs diff --git a/BasicNodes/Templating/OutputPath.cs b/BasicNodes/Templating/OutputPath.cs new file mode 100644 index 00000000..388bd78e --- /dev/null +++ b/BasicNodes/Templating/OutputPath.cs @@ -0,0 +1,40 @@ +using FileFlows.Plugin; + +namespace FileFlows.BasicNodes.Templating; + +/// +/// Special templating node for the output path +/// +public class OutputPath : TemplatingNode +{ + /// + /// Gets the number of inputs + /// + public override int Inputs => 1; + + /// + /// Gets the icon + /// + public override string Icon => "fas fa-folder"; + + /// + /// Gets or sets the URL to the help page + /// + public override string HelpUrl => "https://fileflows.com/docs/plugins/basic-nodes/templating/output-path"; + + /// + /// Gets or sets the flow element type + /// + public override FlowElementType Type => FlowElementType.Logic; + + /// + /// Executes the flow element + /// + /// the node paramters + /// the output + public override int Execute(NodeParameters args) + { + args.Logger?.ELog("This templating node cannot be used in an executed flow"); + return -1; + } +} \ No newline at end of file diff --git a/BasicNodes/Templating/TemplatingNode.cs b/BasicNodes/Templating/TemplatingNode.cs new file mode 100644 index 00000000..6de4c590 --- /dev/null +++ b/BasicNodes/Templating/TemplatingNode.cs @@ -0,0 +1,11 @@ +using FileFlows.Plugin; + +namespace FileFlows.BasicNodes.Templating; + +/// +/// Flow element used for templating +/// +public abstract class TemplatingNode : Node +{ + +} \ No newline at end of file diff --git a/DiscordNodes/Communication/Discord.cs b/DiscordNodes/Communication/Discord.cs index 7bc7eae3..81f8067b 100644 --- a/DiscordNodes/Communication/Discord.cs +++ b/DiscordNodes/Communication/Discord.cs @@ -32,12 +32,12 @@ public class Discord: Node { _MessageTypeOptions = new List { - new ListOption { Label = "Information", Value = "Information"}, - new ListOption { Label = "Success", Value = "Success"}, - new ListOption { Label = "Warning", Value = "Warning" }, - new ListOption { Label = "Error", Value = "Error"}, - new ListOption { Label = "Failure", Value = "Failure"}, - new ListOption { Label = "Basic", Value = "Basic"}, + new () { Label = "Information", Value = "Information"}, + new () { Label = "Success", Value = "Success"}, + new () { Label = "Warning", Value = "Warning" }, + new () { Label = "Error", Value = "Error"}, + new () { Label = "Failure", Value = "Failure"}, + new () { Label = "Basic", Value = "Basic"}, }; } return _MessageTypeOptions; @@ -52,74 +52,86 @@ public class Discord: Node public override int Execute(NodeParameters args) { - var settings = args.GetPluginSettings(); + try + { + var settings = args.GetPluginSettings(); - if (string.IsNullOrWhiteSpace(settings?.WebhookId)) - { - args.Logger?.WLog("No webhook id set"); - return 2; - } - if (string.IsNullOrWhiteSpace(settings?.WebhookToken)) - { - args.Logger?.WLog("No webhook token set"); - return 2; - } - - string message = args.ReplaceVariables(this.Message); - if (string.IsNullOrWhiteSpace(message)) - { - args.Logger?.WLog("No message to send"); - return 2; - } - string title = args.ReplaceVariables(this.Title)?.EmptyAsNull() ?? this.MessageType?.EmptyAsNull() ?? "Information"; - - object webhook; - if (this.MessageType == "Basic") - { - webhook = new + if (string.IsNullOrWhiteSpace(settings?.WebhookId)) { - username = "FileFlows", - content = message, - avatar_url = "https://fileflows.com/icon.png", - }; + args.Logger?.WLog("No webhook id set"); + return 2; + } - } - else - { - webhook = new + if (string.IsNullOrWhiteSpace(settings?.WebhookToken)) { - username = "FileFlows", - avatar_url = "https://fileflows.com/icon.png", - embeds = new[] + args.Logger?.WLog("No webhook token set"); + return 2; + } + + string message = args.ReplaceVariables(this.Message); + if (string.IsNullOrWhiteSpace(message)) + { + args.Logger?.WLog("No message to send"); + return 2; + } + + string title = args.ReplaceVariables(this.Title)?.EmptyAsNull() ?? + this.MessageType?.EmptyAsNull() ?? "Information"; + + object webhook; + if (this.MessageType == "Basic") + { + webhook = new { - new { - description = message, - title = title, - color = this.MessageType switch + username = "FileFlows", + content = message, + avatar_url = "https://fileflows.com/icon.png", + }; + + } + else + { + webhook = new + { + username = "FileFlows", + avatar_url = "https://fileflows.com/icon.png", + embeds = new[] + { + new { - "Success" => colorSuccess, - "Warning" => colorWarning, - "Error" => colorError, - "Failure" => colorFailure, - _ => colorInfo, + description = message, + title, + color = MessageType switch + { + "Success" => colorSuccess, + "Warning" => colorWarning, + "Error" => colorError, + "Failure" => colorFailure, + _ => colorInfo, + } } } - } - }; + }; + } + + + string url = $"https://discordapp.com/api/webhooks/{settings.WebhookId}/{settings.WebhookToken}"; + + var content = new StringContent(JsonSerializer.Serialize(webhook), Encoding.UTF8, "application/json"); + + using var httpClient = new HttpClient(); + var response = httpClient.PostAsync(url, content).Result; + if (response.IsSuccessStatusCode) + return 1; + + string error = response.Content.ReadAsStringAsync().Result; + args.Logger?.WLog("Error from discord: " + error); + return 2; + } + catch (Exception ex) + { + args.Logger?.WLog("Error sending discord message: " + ex.Message); + return 2; } - - - string url = $"https://discordapp.com/api/webhooks/{settings.WebhookId}/{settings.WebhookToken}"; - - var content = new StringContent(JsonSerializer.Serialize(webhook), Encoding.UTF8, "application/json"); - - using var httpClient = new HttpClient(); - var response = httpClient.PostAsync(url, content).Result; - if (response.IsSuccessStatusCode) - return 1; - - string error = response.Content.ReadAsStringAsync().Result; - args.Logger?.WLog("Error from discord: " + error); - return 2; } } diff --git a/EmailNodes/Communication/SendEmail.cs b/EmailNodes/Communication/SendEmail.cs index 3a21e7d1..62e15feb 100644 --- a/EmailNodes/Communication/SendEmail.cs +++ b/EmailNodes/Communication/SendEmail.cs @@ -8,7 +8,7 @@ namespace FileFlows.Communication public class SendEmail:Node { public override int Inputs => 1; - public override int Outputs => 1; + public override int Outputs => 2; public override string Icon => "fas fa-envelope"; public override FlowElementType Type => FlowElementType.Communication; @@ -25,27 +25,36 @@ namespace FileFlows.Communication public override int Execute(NodeParameters args) { - var settings = args.GetPluginSettings(); - - if (string.IsNullOrEmpty(settings?.SmtpServer)) + try { - args.Logger?.ELog("No SMTP Server configured, configure this under the 'Plugins > Email Nodes > Edit' page."); - return -1; + var settings = args.GetPluginSettings(); + + if (string.IsNullOrEmpty(settings?.SmtpServer)) + { + args.Logger?.ELog( + "No SMTP Server configured, configure this under the 'Plugins > Email Nodes > Edit' page."); + return -1; + } + + args.Logger?.ILog($"Got SMTP Server: {settings.SmtpServer} [{settings.SmtpPort}]"); + + string body = RenderBody(args); + + string sender = settings.Sender ?? "fileflows@" + Environment.MachineName; + string subject = args.ReplaceVariables(this.Subject ?? String.Empty)?.EmptyAsNull() ?? + "Email from FileFlows"; + + SendMailKit(args, settings, sender, subject, body); + + //SendDotNet(args, settings, sender, subject, body); + + return 1; + } + catch (Exception ex) + { + args.Logger?.WLog("Error sending message: " + ex.Message); + return 2; } - - args.Logger?.ILog($"Got SMTP Server: {settings.SmtpServer} [{settings.SmtpPort}]"); - - string body = RenderBody(args); - - string sender = settings.Sender ?? "fileflows@" + Environment.MachineName; - string subject = args.ReplaceVariables(this.Subject ?? String.Empty)?.EmptyAsNull() ?? "Email from FileFlows"; - - - SendMailKit(args, settings, sender, subject, body); - - //SendDotNet(args, settings, sender, subject, body); - - return 1; } internal string RenderBody(NodeParameters args) diff --git a/EmailNodes/EmailNodes.en.json b/EmailNodes/EmailNodes.en.json index ec98574f..cea5ba1a 100644 --- a/EmailNodes/EmailNodes.en.json +++ b/EmailNodes/EmailNodes.en.json @@ -19,7 +19,8 @@ "Parts": { "SendEmail": { "Outputs": { - "1": "Email ''{Subject}'' was sent" + "1": "Email ''{Subject}'' was sent", + "2": "Email failed to send" }, "Description": "Sends an email using the configured SMTP Server", "Fields": { diff --git a/Gotify/Communication/Gotify.cs b/Gotify/Communication/Gotify.cs index dca33b47..3facebb6 100644 --- a/Gotify/Communication/Gotify.cs +++ b/Gotify/Communication/Gotify.cs @@ -25,49 +25,59 @@ public class Gotify: Node public override int Execute(NodeParameters args) { - var settings = args.GetPluginSettings(); - - if (string.IsNullOrWhiteSpace(settings?.AccessToken)) + try { - args.Logger?.WLog("No access token set"); + var settings = args.GetPluginSettings(); + + if (string.IsNullOrWhiteSpace(settings?.AccessToken)) + { + args.Logger?.WLog("No access token set"); + return 2; + } + + if (string.IsNullOrWhiteSpace(settings?.ServerUrl)) + { + args.Logger?.WLog("No server URL set"); + return 2; + } + + string message = args.ReplaceVariables(this.Message); + if (string.IsNullOrWhiteSpace(message)) + { + args.Logger?.WLog("No message to send"); + return 2; + } + + string title = args.ReplaceVariables(this.Title)?.EmptyAsNull() ?? "FileFlows"; + + object data = new + { + title = title, + message = message, + priority = this.Priority < 0 ? 2 : this.Priority, + }; + + var content = new StringContent(JsonSerializer.Serialize(data), Encoding.UTF8, "application/json"); + + string url = settings.ServerUrl; + if (url.EndsWith("/") == false) + url += "/"; + url += "message"; + + using var httpClient = new HttpClient(); + httpClient.DefaultRequestHeaders.Add("X-Gotify-Key", settings.AccessToken); + var response = httpClient.PostAsync(url, content).Result; + if (response.IsSuccessStatusCode) + return 1; + + string error = response.Content.ReadAsStringAsync().Result; + args.Logger?.WLog("Error from Gotify: " + error); return 2; } - if (string.IsNullOrWhiteSpace(settings?.ServerUrl)) + catch (Exception ex) { - args.Logger?.WLog("No server URL set"); + args.Logger?.WLog("Error sending message: " + ex.Message); return 2; - } - - string message = args.ReplaceVariables(this.Message); - if (string.IsNullOrWhiteSpace(message)) - { - args.Logger?.WLog("No message to send"); - return 2; - } - string title = args.ReplaceVariables(this.Title)?.EmptyAsNull() ?? "FileFlows"; - - object data = new - { - title = title, - message = message, - priority = this.Priority < 0 ? 2 : this.Priority, - }; - - var content = new StringContent(JsonSerializer.Serialize(data), Encoding.UTF8, "application/json"); - - string url = settings.ServerUrl; - if(url.EndsWith("/") == false) - url += "/"; - url += "message"; - - using var httpClient = new HttpClient(); - httpClient.DefaultRequestHeaders.Add("X-Gotify-Key", settings.AccessToken); - var response = httpClient.PostAsync(url, content).Result; - if (response.IsSuccessStatusCode) - return 1; - - string error = response.Content.ReadAsStringAsync().Result; - args.Logger?.WLog("Error from Gotify: " + error); - return 2; + } } }