From 5d81c24b6527a856cd5f80e66f1020ae1e7e7e18 Mon Sep 17 00:00:00 2001 From: ROuGGy Date: Sun, 17 Dec 2023 20:31:40 +0700 Subject: [PATCH] gotify --- DeleteArr.go | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/DeleteArr.go b/DeleteArr.go index e1a4479..ec3e49a 100644 --- a/DeleteArr.go +++ b/DeleteArr.go @@ -1,13 +1,23 @@ package main import ( + "bytes" + "encoding/json" "log" + "net/http" "os" "path/filepath" "slices" "strings" + "time" ) +type GotifyMessage struct { + Title string `json:"title"` + Priority string `json:"priority"` + Message string `json:"message"` +} + type MediaFiles struct { EventType string SourcePath string @@ -17,6 +27,38 @@ type MediaFiles struct { Arr string } +func (m *MediaFiles) SendGotify(message string, arr string) { + url := "https://gotify.rouggy.com/message?token=AKMj5SsZblmpAJ_" + gm := GotifyMessage{ + Title: "Deleting Media from " + arr, + Priority: "10", + Message: message, + } + + marshalled, err := json.Marshal(gm) + if err != nil { + log.Fatalf("impossible to marshall Gotify Message: %s", err) + } + + req, err := http.NewRequest("POST", url, bytes.NewReader(marshalled)) + if err != nil { + log.Fatalf("impossible to build request: %s", err) + } + + req.Header.Set("Content-Type", "application/json") + + // create http client + // do not forget to set timeout; otherwise, no timeout! + client := http.Client{Timeout: 10 * time.Second} + // send the request + res, err := client.Do(req) + if err != nil { + log.Fatalf("impossible to send request: %s", err) + } + log.Printf("status Code: %d", res.StatusCode) + +} + func (m *MediaFiles) IsInFolder() { folderList := []string{"Movies", "4K-Movies", "Series", "4K-Series", "Kids", "Animes"} @@ -122,4 +164,6 @@ func main() { log.Printf("Deleting the file %v", m.SourcePath) } + m.SendGotify("Deleting Source Path"+m.SourcePath, m.Arr) + }