Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
373e9ff3c3 | ||
|
|
d3fff1519b | ||
|
|
2b6acc51fb | ||
|
|
fade4467d6 | ||
|
|
c8800c010e |
@@ -12,7 +12,7 @@
|
|||||||
"RefreshURI": "https://api.imgur.com/oauth2/token",
|
"RefreshURI": "https://api.imgur.com/oauth2/token",
|
||||||
"RefreshFormat": "refresh_token=%s\u0026client_id=%s\u0026client_secret=%s\u0026grant_type=refresh_token",
|
"RefreshFormat": "refresh_token=%s\u0026client_id=%s\u0026client_secret=%s\u0026grant_type=refresh_token",
|
||||||
"RefreshMethod": "POST",
|
"RefreshMethod": "POST",
|
||||||
"UploadURI": "https://api.imgur.com/3/image",
|
"UploadURI": "https://api.imgur.com/3/image?name=something.jpeg",
|
||||||
"UploadMethod": "POST"
|
"UploadMethod": "POST"
|
||||||
},
|
},
|
||||||
"Maps": {
|
"Maps": {
|
||||||
@@ -74,7 +74,7 @@
|
|||||||
"Room": "!WbawbZxHqnxxfhvcSj:synapse.home.blapointe.com"
|
"Room": "!WbawbZxHqnxxfhvcSj:synapse.home.blapointe.com"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"Once": false,
|
"Once": true,
|
||||||
"Brokers": {
|
"Brokers": {
|
||||||
"NTG": {
|
"NTG": {
|
||||||
"Mock": true,
|
"Mock": true,
|
||||||
|
|||||||
@@ -7,8 +7,10 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"local/truckstop/config"
|
"local/truckstop/config"
|
||||||
|
"log"
|
||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -30,9 +32,17 @@ func refreshToken() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func uploadImage(b []byte) (string, error) {
|
func uploadImage(b []byte) (string, error) {
|
||||||
|
images := config.Get().Images
|
||||||
buff := bytes.NewBuffer(nil)
|
buff := bytes.NewBuffer(nil)
|
||||||
writer := multipart.NewWriter(buff)
|
writer := multipart.NewWriter(buff)
|
||||||
part, err := writer.CreateFormFile("image", "name")
|
name := "name"
|
||||||
|
if u, err := url.Parse(images.UploadURI); err != nil {
|
||||||
|
} else if s, ok := u.Query()["name"]; !ok {
|
||||||
|
} else {
|
||||||
|
name = s[0]
|
||||||
|
log.Printf("found name in upload uri: %s", name)
|
||||||
|
}
|
||||||
|
part, err := writer.CreateFormFile("image", name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
@@ -43,7 +53,6 @@ func uploadImage(b []byte) (string, error) {
|
|||||||
}
|
}
|
||||||
writer.Close()
|
writer.Close()
|
||||||
|
|
||||||
images := config.Get().Images
|
|
||||||
request, err := http.NewRequest(
|
request, err := http.NewRequest(
|
||||||
images.UploadMethod,
|
images.UploadMethod,
|
||||||
images.UploadURI,
|
images.UploadURI,
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package message
|
package message
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"local/truckstop/config"
|
"local/truckstop/config"
|
||||||
@@ -129,14 +130,15 @@ func (m Matrix) SendImage(uri string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
publicURI, err := UploadImage(b)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
c, err := m.getclient()
|
c, err := m.getclient()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
mediaUpload, err := c.UploadToContentRepo(bytes.NewReader(b), "image/jpeg", int64(len(b)))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
publicURI := mediaUpload.ContentURI
|
||||||
resp, err := c.SendImage(m.room, "img", publicURI)
|
resp, err := c.SendImage(m.room, "img", publicURI)
|
||||||
log.Printf("sent image %s => %s: %+v", uri, publicURI, resp)
|
log.Printf("sent image %s => %s: %+v", uri, publicURI, resp)
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -1,4 +1,9 @@
|
|||||||
todo:
|
todo:
|
||||||
|
- no hard code jpeg or have it in multiple places
|
||||||
|
- todo: switch house to selfhosted for rate limit
|
||||||
|
tags: now
|
||||||
|
- mark consumed;; save scroll id for matrix
|
||||||
|
- TEST its falling apart
|
||||||
- test each !command callbacks to matrix
|
- test each !command callbacks to matrix
|
||||||
- change matrix so I test my custom logic even if I dont fetch remote
|
- change matrix so I test my custom logic even if I dont fetch remote
|
||||||
- warn/err/etc. on clobbering ids.matrix since clients can mess with one another
|
- warn/err/etc. on clobbering ids.matrix since clients can mess with one another
|
||||||
|
|||||||
Reference in New Issue
Block a user