Pushover Notifications https://github.com/C9Glax/tranga/issues/246
Some checks failed
Docker Image CI / build (push) Has been cancelled

This commit is contained in:
Glax 2025-03-29 20:55:24 +01:00
parent 9350de0ae9
commit 66fcdca7e7
2 changed files with 41 additions and 2 deletions

View File

@ -0,0 +1,13 @@
namespace API.APIEndpointRecords;
public record PushoverRecord(string apptoken, string user)
{
public bool Validate()
{
if (apptoken == string.Empty)
return false;
if (user == string.Empty)
return false;
return true;
}
}

View File

@ -120,7 +120,7 @@ public class NotificationConnectorController(PgsqlContext context) : Controller
string authHeader = "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes($"{ntfyRecord.username}:{ntfyRecord.password}")); string authHeader = "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes($"{ntfyRecord.username}:{ntfyRecord.password}"));
string auth = Convert.ToBase64String(Encoding.UTF8.GetBytes(authHeader)).Replace("=",""); string auth = Convert.ToBase64String(Encoding.UTF8.GetBytes(authHeader)).Replace("=","");
NotificationConnector ntfyConnector = new NotificationConnector(TokenGen.CreateToken("Ntfy"), NotificationConnector ntfyConnector = new (TokenGen.CreateToken("Ntfy"),
$"{ntfyRecord.endpoint}?auth={auth}", $"{ntfyRecord.endpoint}?auth={auth}",
new Dictionary<string, string>() new Dictionary<string, string>()
{ {
@ -150,7 +150,7 @@ public class NotificationConnectorController(PgsqlContext context) : Controller
if(!lunaseaRecord.Validate()) if(!lunaseaRecord.Validate())
return BadRequest(); return BadRequest();
NotificationConnector lunaseaConnector = new NotificationConnector(TokenGen.CreateToken("Lunasea"), NotificationConnector lunaseaConnector = new (TokenGen.CreateToken("Lunasea"),
$"https://notify.lunasea.app/v1/custom/{lunaseaRecord.id}", $"https://notify.lunasea.app/v1/custom/{lunaseaRecord.id}",
new Dictionary<string, string>(), new Dictionary<string, string>(),
"POST", "POST",
@ -158,6 +158,32 @@ public class NotificationConnectorController(PgsqlContext context) : Controller
return CreateConnector(lunaseaConnector); return CreateConnector(lunaseaConnector);
} }
/// <summary>
/// Creates a new Pushover-Notification-Connector
/// </summary>
/// <remarks>https://pushover.net/api</remarks>
/// <response code="201">ID of new connector</response>
/// <response code="400"></response>
/// <response code="409">A NotificationConnector with name already exists</response>
/// <response code="500">Error during Database Operation</response>
[HttpPut("Pushover")]
[ProducesResponseType<string>(Status201Created, "application/json")]
[ProducesResponseType(Status400BadRequest)]
[ProducesResponseType(Status409Conflict)]
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
public IActionResult CreatePushoverConnector([FromBody]PushoverRecord pushoverRecord)
{
if(!pushoverRecord.Validate())
return BadRequest();
NotificationConnector pushoverConnector = new (TokenGen.CreateToken("Pushover"),
$"https://api.pushover.net/1/messages.json",
new Dictionary<string, string>(),
"POST",
$"{{\"token\": \"{pushoverRecord.apptoken}\", \"user\": \"{pushoverRecord.user}\", \"message:\":\"%text\", \"%title\" }}");
return CreateConnector(pushoverConnector);
}
/// <summary> /// <summary>
/// Deletes the Notification-Connector with the requested ID /// Deletes the Notification-Connector with the requested ID
/// </summary> /// </summary>