Fixes
This commit is contained in:
parent
9f1a1cbd48
commit
d8f2708c3d
24
actor.go
24
actor.go
|
@ -109,7 +109,7 @@ func (a *Actor) save() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (a *Actor) PostArticle(url string) {
|
||||
func (a *Actor) PostArticle(url string) error {
|
||||
create := make(map[string]interface{})
|
||||
note := make(map[string]interface{})
|
||||
create["@context"] = context()
|
||||
|
@ -120,28 +120,26 @@ func (a *Actor) PostArticle(url string) {
|
|||
article := make(map[string]interface{})
|
||||
req, err := http.NewRequest(http.MethodGet, url, nil)
|
||||
if err != nil {
|
||||
return
|
||||
return errors.New("failed to create request to fetch article")
|
||||
}
|
||||
req.Header.Add("User-Agent", fmt.Sprintf("%s %s", libName, version))
|
||||
req.Header.Add("Accept", ContentTypeAs2)
|
||||
resp, err := client.Do(req)
|
||||
if err != nil || isSuccess(resp.StatusCode) {
|
||||
fmt.Println("Failed to fetch article")
|
||||
return
|
||||
resp, err := http.DefaultClient.Do(req)
|
||||
if err != nil || !isSuccess(resp.StatusCode) {
|
||||
return errors.New("failed to fetch article")
|
||||
}
|
||||
respBody, err := ioutil.ReadAll(resp.Body)
|
||||
defer func() { _ = resp.Body.Close() }()
|
||||
if err != nil {
|
||||
fmt.Println("Failed to read response from fetched article")
|
||||
return
|
||||
return errors.New("failed to read response from fetched article")
|
||||
}
|
||||
err = json.Unmarshal(respBody, &article)
|
||||
if err != nil {
|
||||
fmt.Println("Failed to unmarshal fetched article")
|
||||
return
|
||||
return errors.New("failed to unmarshal fetched article")
|
||||
}
|
||||
create["object"] = article
|
||||
go func() { _ = a.sendToFollowers(create) }()
|
||||
go a.sendToFollowers(create)
|
||||
return nil
|
||||
}
|
||||
|
||||
// signedHTTPPost performs an HTTP post on behalf of Actor with the
|
||||
|
@ -174,7 +172,7 @@ func (a *Actor) signedHTTPPost(content map[string]interface{}, to string) (err e
|
|||
if err != nil {
|
||||
return
|
||||
}
|
||||
resp, err := client.Do(req)
|
||||
resp, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
@ -205,7 +203,7 @@ func (a *Actor) batchSend(activity map[string]interface{}, recipients []string)
|
|||
}
|
||||
|
||||
// send to followers sends a batch of http posts to each one of the followers
|
||||
func (a *Actor) sendToFollowers(activity map[string]interface{}) (err error) {
|
||||
func (a *Actor) sendToFollowers(activity map[string]interface{}) {
|
||||
recipients := make([]string, len(a.followers))
|
||||
i := 0
|
||||
for _, inbox := range a.followers {
|
||||
|
|
3
feed.go
3
feed.go
|
@ -4,6 +4,7 @@ import (
|
|||
"encoding/json"
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func allFeedItems(url string) ([]string, error) {
|
||||
|
@ -12,7 +13,7 @@ func allFeedItems(url string) ([]string, error) {
|
|||
Url string `json:"url"`
|
||||
} `json:"items"`
|
||||
}{}
|
||||
resp, err := client.Get(url)
|
||||
resp, err := http.DefaultClient.Get(url)
|
||||
if err != nil {
|
||||
return nil, errors.New("failed to get json feed")
|
||||
}
|
||||
|
|
2
http.go
2
http.go
|
@ -66,7 +66,7 @@ func Serve() {
|
|||
inReplyTo, ok := object["inReplyTo"].(string)
|
||||
id, ok2 := object["id"].(string)
|
||||
if ok && ok2 && len(inReplyTo) > 0 && len(id) > 0 {
|
||||
webmentionClient := webmention.New(&client)
|
||||
webmentionClient := webmention.New(nil)
|
||||
endpoint, err := webmentionClient.DiscoverEndpoint(inReplyTo)
|
||||
if err != nil || len(endpoint) < 1 {
|
||||
return
|
||||
|
|
8
main.go
8
main.go
|
@ -28,9 +28,13 @@ func main() {
|
|||
for _, article := range articles {
|
||||
if oldSentItems[article] == false {
|
||||
fmt.Println("Send", article)
|
||||
go actor.PostArticle(article)
|
||||
err = actor.PostArticle(article)
|
||||
if err == nil {
|
||||
actor.sentItems[article] = true
|
||||
}
|
||||
} else {
|
||||
actor.sentItems[article] = true
|
||||
}
|
||||
actor.sentItems[article] = true
|
||||
}
|
||||
_ = actor.save()
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ func get(iri string) (info map[string]interface{}, err error) {
|
|||
req.Header.Add("Accept", ContentTypeAs2)
|
||||
req.Header.Add("User-Agent", fmt.Sprintf("%s %s", libName, version))
|
||||
req.Header.Add("Accept-Charset", "utf-8")
|
||||
resp, err := client.Do(req)
|
||||
resp, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
|
Reference in New Issue