Compare commits
No commits in common. "4f14903538d0796db37e3a4bf13425b8eaac5b3d" and "6ae3918679b5eb7886890accd3def9a84a455da5" have entirely different histories.
4f14903538
...
6ae3918679
@ -9,9 +9,10 @@ public class Ntfy : NotificationConnector
|
||||
// ReSharper disable twice MemberCanBePrivate.Global
|
||||
public string endpoint { get; init; }
|
||||
public string auth { get; init; }
|
||||
public string topic { get; init; }
|
||||
private readonly string _topic = "tranga";
|
||||
private readonly HttpClient _client = new();
|
||||
|
||||
[JsonConstructor]
|
||||
public Ntfy(GlobalBase clone, string endpoint, string auth) : base(clone, NotificationConnectorType.Ntfy)
|
||||
{
|
||||
if (!baseUrlRex.IsMatch(endpoint))
|
||||
@ -22,29 +23,19 @@ public class Ntfy : NotificationConnector
|
||||
Log($"Error getting URI from provided endpoint-URI: {endpoint}");
|
||||
this.endpoint = match.Groups[1].Value;
|
||||
if (match.Groups[2].Success)
|
||||
topic = match.Groups[2].Value;
|
||||
else
|
||||
topic = "tranga";
|
||||
this.auth = auth;
|
||||
}
|
||||
|
||||
[JsonConstructor]
|
||||
public Ntfy(GlobalBase clone, string endpoint, string auth, string topic) : base(clone, NotificationConnectorType.Ntfy)
|
||||
{
|
||||
this.endpoint = endpoint;
|
||||
this.topic = topic.Length > 0 ? topic : "tranga";
|
||||
_topic = match.Groups[2].Value;
|
||||
this.auth = auth;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"Ntfy {endpoint} {topic}";
|
||||
return $"Ntfy {endpoint} {_topic}";
|
||||
}
|
||||
|
||||
public override void SendNotification(string title, string notificationText)
|
||||
{
|
||||
Log($"Sending notification: {title} - {notificationText}");
|
||||
MessageData message = new(title, topic, notificationText);
|
||||
MessageData message = new(title, _topic, notificationText);
|
||||
HttpRequestMessage request = new(HttpMethod.Post, $"{this.endpoint}?auth={this.auth}");
|
||||
request.Content = new StringContent(JsonConvert.SerializeObject(message, Formatting.None), Encoding.UTF8, "application/json");
|
||||
HttpResponseMessage response = _client.Send(request);
|
||||
|
Loading…
Reference in New Issue
Block a user