From 6e2511bee7e3769e6600c66a1302236f0bc712ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Martins?= Date: Fri, 18 Oct 2024 18:52:17 +0200 Subject: [PATCH 1/2] Add endpoint to send test notification --- internal/web/api.go | 9 +++++++++ internal/web/webgui.go | 13 +++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/internal/web/api.go b/internal/web/api.go index 6f0ec6f..b46fbee 100644 --- a/internal/web/api.go +++ b/internal/web/api.go @@ -8,6 +8,7 @@ import ( "github.com/aceberg/WatchYourLAN/internal/db" "github.com/aceberg/WatchYourLAN/internal/models" + "github.com/aceberg/WatchYourLAN/internal/notify" "github.com/aceberg/WatchYourLAN/internal/portscan" ) @@ -88,3 +89,11 @@ func apiEdit(c *gin.Context) { c.IndentedJSON(http.StatusOK, "OK") } + +func testNotifyHandler(c *gin.Context) { + + msg := "Test notification from WatchYourLAN" + notify.Shout(msg, appConfig.ShoutURL) + + c.Status(http.StatusOK) +} diff --git a/internal/web/webgui.go b/internal/web/webgui.go index 49107ce..345ddc5 100644 --- a/internal/web/webgui.go +++ b/internal/web/webgui.go @@ -46,12 +46,13 @@ func Gui(dirPath, nodePath string) { router.StaticFS("/fs/", http.FS(pubFS)) // public - router.GET("/api/all", apiAll) // api.go - router.GET("/api/edit/:id/:name/*known", apiEdit) // api.go - router.GET("/api/history/*mac", apiHistory) // api.go - router.GET("/api/host/:id", apiHost) // api.go - router.GET("/api/host/del/:id", apiHostDel) // api.go - router.GET("/api/port/:addr/:port", apiPort) // api.go + router.GET("/api/all", apiAll) // api.go + router.GET("/api/edit/:id/:name/*known", apiEdit) // api.go + router.GET("/api/history/*mac", apiHistory) // api.go + router.GET("/api/host/:id", apiHost) // api.go + router.GET("/api/host/del/:id", apiHostDel) // api.go + router.GET("/api/port/:addr/:port", apiPort) // api.go + router.POST("/api/test_notify", testNotifyHandler) // api.go router.GET("/", indexHandler) // index.go router.GET("/history/", historyHandler) // index.go From 585ee35c595ebff8a8b81395c277521eb6a5fad0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Martins?= Date: Fri, 18 Oct 2024 18:53:19 +0200 Subject: [PATCH 2/2] Add button to send test notification --- internal/web/public/js/notify.js | 5 +++++ internal/web/templates/config.html | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 internal/web/public/js/notify.js diff --git a/internal/web/public/js/notify.js b/internal/web/public/js/notify.js new file mode 100644 index 0000000..5e9faaf --- /dev/null +++ b/internal/web/public/js/notify.js @@ -0,0 +1,5 @@ +async function testNotifications() { + + const url = '/api/test_notify' + await fetch(url, { method: 'post' }) +} diff --git a/internal/web/templates/config.html b/internal/web/templates/config.html index f32d4ee..6b84498 100644 --- a/internal/web/templates/config.html +++ b/internal/web/templates/config.html @@ -44,6 +44,7 @@ + @@ -199,6 +200,7 @@ + {{ template "footer.html" }} -{{ end }} \ No newline at end of file +{{ end }}