when a job dies, delete images associated with it
This commit is contained in:
@@ -125,6 +125,19 @@ func (m *Matrix) Receive() ([]Message, error) {
|
||||
return messages, nil
|
||||
}
|
||||
|
||||
func (m Matrix) Remove(id string) error {
|
||||
if m.mock {
|
||||
logtr.Infof("matrix.Remove(%s)", id)
|
||||
return nil
|
||||
}
|
||||
c, err := m.getclient()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = c.RedactEvent(m.room, id, &gomatrix.ReqRedact{Reason: "stale"})
|
||||
return err
|
||||
}
|
||||
|
||||
func (m Matrix) Update(id, text string) error {
|
||||
if m.mock {
|
||||
logtr.Infof("matrix.Update(%s)", text)
|
||||
@@ -185,36 +198,41 @@ func (m Matrix) SendTracked(text string) (string, error) {
|
||||
}
|
||||
|
||||
func (m Matrix) SendImage(uri string) error {
|
||||
_, err := m.SendImageTracked(uri)
|
||||
return err
|
||||
}
|
||||
|
||||
func (m Matrix) SendImageTracked(uri string) (string, error) {
|
||||
if m.mock {
|
||||
logtr.Infof("matrix.SendImage(%s)", uri)
|
||||
return nil
|
||||
return "", nil
|
||||
}
|
||||
response, err := http.Get(uri)
|
||||
if err != nil {
|
||||
return err
|
||||
return "", err
|
||||
}
|
||||
if response.StatusCode != http.StatusOK {
|
||||
b, _ := ioutil.ReadAll(response.Body)
|
||||
response.Body.Close()
|
||||
return fmt.Errorf("failed to get %s: (%d) %s", uri, response.StatusCode, b)
|
||||
return "", fmt.Errorf("failed to get %s: (%d) %s", uri, response.StatusCode, b)
|
||||
}
|
||||
b, err := ioutil.ReadAll(response.Body)
|
||||
response.Body.Close()
|
||||
if err != nil {
|
||||
return err
|
||||
return "", err
|
||||
}
|
||||
c, err := m.getclient()
|
||||
if err != nil {
|
||||
return err
|
||||
return "", err
|
||||
}
|
||||
mediaUpload, err := c.UploadToContentRepo(bytes.NewReader(b), "image/jpeg", int64(len(b)))
|
||||
if err != nil {
|
||||
return err
|
||||
return "", err
|
||||
}
|
||||
publicURI := mediaUpload.ContentURI
|
||||
resp, err := c.SendImage(m.room, "img", publicURI)
|
||||
logtr.Debugf("sent image %s => %s: %+v", uri, publicURI, resp)
|
||||
return err
|
||||
return resp.EventID, err
|
||||
}
|
||||
|
||||
func SetMatrixContinuation(continuation string) {
|
||||
|
||||
@@ -10,9 +10,11 @@ import (
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
func TestMatrixSend(t *testing.T) {
|
||||
func TestMatrixSendDel(t *testing.T) {
|
||||
sender := testMatrix(t)
|
||||
if err := sender.Send("hello world from unittest"); err != nil {
|
||||
if id, err := sender.SendTracked("hello world from unittest"); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if err := sender.Remove(id); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user