added Gotify, renamed "Nodes" suffix from Email and Discord

This commit is contained in:
John Andrews
2022-04-20 11:04:33 +12:00
parent 4694de6e81
commit 342c53c3ba
28 changed files with 249 additions and 8 deletions

1
.gitignore vendored
View File

@@ -11,3 +11,4 @@ TestStore/
deploy/**
*.ffplugin
DiscordNodes/settings.json
Gotify/settings.json

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -2,7 +2,7 @@ namespace FileFlows.DiscordNodes;
public class Plugin : FileFlows.Plugin.IPlugin
{
public string Name => "Discord Nodes";
public string Name => "Discord";
public string MinimumVersion => "0.5.2.690";
public void Init()

Binary file not shown.

View File

@@ -2,7 +2,7 @@
{
public class Plugin : IPlugin
{
public string Name => "Email Nodes";
public string Name => "Email";
public string MinimumVersion => "0.5.2.690";
public void Init()

View File

@@ -17,7 +17,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MusicNodes", "MusicNodes\Mu
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EmailNodes", "EmailNodes\EmailNodes.csproj", "{8F2739B8-2BD6-4AAC-A54B-2EE1B4AAF559}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DiscordNodes", "DiscordNodes\DiscordNodes.csproj", "{3A74B188-79DB-4A70-B9F1-AF6F767173B6}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Gotify", "Gotify\Gotify.csproj", "{18E7013A-BF85-47FA-806C-934267C7BCA5}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DiscordNodes", "DiscordNodes\DiscordNodes.csproj", "{27721E6D-1FBF-4950-824E-5231CACDE64C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -53,10 +55,14 @@ Global
{8F2739B8-2BD6-4AAC-A54B-2EE1B4AAF559}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8F2739B8-2BD6-4AAC-A54B-2EE1B4AAF559}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8F2739B8-2BD6-4AAC-A54B-2EE1B4AAF559}.Release|Any CPU.Build.0 = Release|Any CPU
{3A74B188-79DB-4A70-B9F1-AF6F767173B6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3A74B188-79DB-4A70-B9F1-AF6F767173B6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3A74B188-79DB-4A70-B9F1-AF6F767173B6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3A74B188-79DB-4A70-B9F1-AF6F767173B6}.Release|Any CPU.Build.0 = Release|Any CPU
{18E7013A-BF85-47FA-806C-934267C7BCA5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{18E7013A-BF85-47FA-806C-934267C7BCA5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{18E7013A-BF85-47FA-806C-934267C7BCA5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{18E7013A-BF85-47FA-806C-934267C7BCA5}.Release|Any CPU.Build.0 = Release|Any CPU
{27721E6D-1FBF-4950-824E-5231CACDE64C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{27721E6D-1FBF-4950-824E-5231CACDE64C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{27721E6D-1FBF-4950-824E-5231CACDE64C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{27721E6D-1FBF-4950-824E-5231CACDE64C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@@ -0,0 +1,73 @@
using System.ComponentModel;
using System.Text.Json;
namespace FileFlows.Gotify.Communication;
public class Gotify: Node
{
public override int Inputs => 1;
public override int Outputs => 2;
public override FlowElementType Type => FlowElementType.Communication;
public override string Icon => "fas fa-bell";
public override bool FailureNode => true;
[Required]
[TextVariable(1)]
public string Message { get; set; }
[TextVariable(2)]
public string Title { get; set; }
[NumberInt(3)]
[Range(1, 100)]
[DefaultValue(2)]
public int Priority { get; set; } = 2;
public override int Execute(NodeParameters args)
{
var settings = args.GetPluginSettings<PluginSettings>();
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;
}
}

View File

@@ -0,0 +1,6 @@
namespace FileFlows.Gotify;
internal static class ExtensionMethods
{
public static string? EmptyAsNull(this string str) => str == string.Empty ? null : str;
}

5
Gotify/GlobalUsings.cs Normal file
View File

@@ -0,0 +1,5 @@
global using System;
global using System.Text;
global using System.ComponentModel.DataAnnotations;
global using FileFlows.Plugin;
global using FileFlows.Plugin.Attributes;

BIN
Gotify/Gotify.csproj Normal file

Binary file not shown.

33
Gotify/Gotify.en.json Normal file
View File

@@ -0,0 +1,33 @@
{
"Plugins": {
"Gotify": {
"Description": "A plugin that allows you to send messages to a Gotify server.",
"Fields": {
"ServerUrl": "Server",
"ServerUrl-Placeholder":"http://gotify.lan",
"ServerUrl-Help":"The URL of the Gotify server",
"AccessToken": "Access Token",
"AccessToken-Help":"The access token used to communicate with the Gotify server."
}
}
},
"Flow": {
"Parts": {
"Gotify": {
"Outputs": {
"1": "Gotify message sent",
"2": "Gotify message failed to send"
},
"Description": "Sends a message to a Gotify server.",
"Fields": {
"Message": "Message",
"Message-Help": "The message to send to the Gotify server",
"Title": "Title",
"Title-Help": "An optional title to send.",
"Priority": "Priority",
"Priority-Help": "The priority of the message being sent"
}
}
}
}
}

11
Gotify/Plugin.cs Normal file
View File

@@ -0,0 +1,11 @@
namespace FileFlows.Gotify;
public class Plugin : FileFlows.Plugin.IPlugin
{
public string Name => "Gotify Nodes";
public string MinimumVersion => "0.5.2.690";
public void Init()
{
}
}

18
Gotify/PluginSettings.cs Normal file
View File

@@ -0,0 +1,18 @@
namespace FileFlows.Gotify
{
using FileFlows.Plugin;
using FileFlows.Plugin.Attributes;
using System;
using System.ComponentModel.DataAnnotations;
public class PluginSettings:IPluginSettings
{
[Text(1)]
[Required]
public string ServerUrl { get; set; }
[Text(2)]
[Required]
public string AccessToken { get; set; }
}
}

View File

@@ -0,0 +1,26 @@
#if(DEBUG)
using FileFlows.Gotify.Communication;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace FileFlows.Gotify.Tests;
[TestClass]
public class GotifyTests
{
[TestMethod]
public void Gotify_Basic_Message()
{
var args = new NodeParameters("test.file", new TestLogger(), false, string.Empty);
args.GetPluginSettingsJson = (string input) =>
{
return File.ReadAllText("../../../settings.json");
};
var node = new FileFlows.Gotify.Communication.Gotify();
node.Message = "a message";
Assert.AreEqual(1, node.Execute(args));
}
}
#endif

View File

@@ -0,0 +1,59 @@
#if(DEBUG)
namespace FileFlows.Gotify.Tests;
using FileFlows.Plugin;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
internal class TestLogger : ILogger
{
private List<string> Messages = new List<string>();
public void DLog(params object[] args) => Log("DBUG", args);
public void ELog(params object[] args) => Log("ERRR", args);
public void ILog(params object[] args) => Log("INFO", args);
public void WLog(params object[] args) => Log("WARN", args);
private void Log(string type, object[] args)
{
if (args == null || args.Length == 0)
return;
string message = type + " -> " +
string.Join(", ", args.Select(x =>
x == null ? "null" :
x.GetType().IsPrimitive || x is string ? x.ToString() :
System.Text.Json.JsonSerializer.Serialize(x)));
Messages.Add(message);
}
public bool Contains(string message)
{
if (string.IsNullOrWhiteSpace(message))
return false;
string log = string.Join(Environment.NewLine, Messages);
return log.Contains(message);
}
public override string ToString()
{
return String.Join(Environment.NewLine, this.Messages.ToArray());
}
public string GetTail(int length = 50)
{
if (length <= 0)
length = 50;
if (Messages.Count <= length)
return string.Join(Environment.NewLine, Messages);
return string.Join(Environment.NewLine, Messages.TakeLast(length));
}
}
#endif

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -73,4 +73,7 @@ webhook
api
webhooks
[webhookid]
[webhooktoken]
[webhooktoken]
Gotify
gotify
lan