Merge pull request #150 from tesladodger/feat/notify-test

Add button to test notifications
This commit is contained in:
Andrew Erlikh 2024-10-20 16:06:31 +07:00 committed by GitHub
commit 9132401ce0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 24 additions and 7 deletions

View file

@ -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)
}

View file

@ -0,0 +1,5 @@
async function testNotifications() {
const url = '/api/test_notify'
await fetch(url, { method: 'post' })
}

View file

@ -44,6 +44,7 @@
</tr>
<tr>
<td><button type="submit" class="btn btn-primary">Save</button></td>
<td><button type="button" style="float: right;" class="btn btn-success" onclick="testNotifications()">Test notifications</button></td>
<td></td>
</tr>
</form>
@ -199,6 +200,7 @@
</div>
</div>
</div>
<script src="/fs/public/js/notify.js"></script>
{{ template "footer.html" }}
{{ end }}
{{ end }}

View file

@ -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