This commit is contained in:
Gregory Salaun 2023-12-17 20:31:40 +07:00
parent 5d39dbcea8
commit 5d81c24b65

View File

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