From 95fea0358eb222388f63f18ffa366c0bb6ea6007 Mon Sep 17 00:00:00 2001 From: Aaron Bieber Date: Tue, 30 Apr 2024 10:12:35 -0600 Subject: [PATCH] got: switch to auth_user.. woops actually save the json as is, not what we parse --- got.go | 30 ++++++++++++------------------ got_test.go | 5 ----- 2 files changed, 12 insertions(+), 23 deletions(-) diff --git a/got.go b/got.go index 142f5ca..a8651a2 100644 --- a/got.go +++ b/got.go @@ -3,6 +3,7 @@ package main import ( "encoding/json" "fmt" + "io" "log" "net/http" "os" @@ -43,7 +44,7 @@ type Notification struct { Type string `json:"type"` Short bool `json:"short"` Repo string `json:"repo"` - AuthorUser string `json:"author_user"` + AuthUser string `json:"auth_user"` ID string `json:"id"` Author Author `json:"author,omitempty"` Committer Committer `json:"committer"` @@ -56,7 +57,7 @@ type Notification struct { func (n *Notification) String() string { // op committed got.git f9e653700..f9e653700^1 (main): fix gotd_parse_url() (https://git.gameoftrees.org/gitweb/?p=got.git;a=commitdiff;h=f9e653700) return fmt.Sprintf("%s committed %s %s: %s (%s)", - n.AuthorUser, + n.AuthUser, n.Repo, n.ID, n.ShortMessage, @@ -71,18 +72,6 @@ type GotNotifications struct { Notifications []Notification `json:"notifications"` } -func (g *GotNotifications) Save() error { - gnJson, err := json.Marshal(g) - if err != nil { - return err - } - err = os.WriteFile("/tmp/mcchunkie-notification.json", gnJson, 0600) - if err != nil { - return err - } - return nil -} - func gotListen(store *FStore, cli *gomatrix.Client) { var gotPort, _ = store.Get("got_listen") if gotPort != "" { @@ -107,16 +96,21 @@ func gotListen(store *FStore, cli *gomatrix.Client) { } gn := GotNotifications{} - dec := json.NewDecoder(r.Body) - err = dec.Decode(&gn) + data, err := io.ReadAll(r.Body) + if err != nil { + http.Error(w, fmt.Sprintf("internal error: %s", err), http.StatusInternalServerError) + return + } + + _ = os.WriteFile("/tmp/mcchunkie-notification.json", data, 0600) + + err = json.Unmarshal(data, &gn) if err != nil { log.Printf("GOT: invalid data sent to server: '%s'\n", err) http.Error(w, fmt.Sprintf("invalid data sent to server: %s", err), http.StatusBadRequest) return } - _ = gn.Save() - for _, line := range gn.Notifications { log.Printf("GOT: sending '%s'\n", line.String()) err = plugins.SendUnescNotice(cli, gotRoom, line.String()) diff --git a/got_test.go b/got_test.go index cf7f34d..1bd28ca 100644 --- a/got_test.go +++ b/got_test.go @@ -21,11 +21,6 @@ func TestGotNotification(t *testing.T) { t.Fatal(err) } - err = nots.Save() - if err != nil { - t.Fatal(err) - } - for _, n := range nots.Notifications { fmt.Println(n.String()) }