1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
package webfinger
import (
"encoding/json"
"errors"
"io/ioutil"
"net/http"
"regexp"
"github.com/FChannel0/FChannel-Server/activitypub"
"github.com/FChannel0/FChannel-Server/config"
"github.com/FChannel0/FChannel-Server/util"
)
// TODO: All of these functions in this file I don't know where to place so they'll remain here until I find a better place for them.
func GetActorCollection(collection string) (activitypub.Collection, error) {
var nCollection activitypub.Collection
if collection == "" {
return nCollection, errors.New("invalid collection")
}
req, err := http.NewRequest("GET", collection, nil)
if err != nil {
return nCollection, err
}
req.Header.Set("Accept", config.ActivityStreams)
resp, err := util.RouteProxy(req)
if err != nil {
return nCollection, err
}
defer resp.Body.Close()
if resp.StatusCode == 200 {
body, _ := ioutil.ReadAll(resp.Body)
if len(body) > 0 {
if err := json.Unmarshal(body, &nCollection); err != nil {
return nCollection, err
}
}
}
return nCollection, nil
}
func GetCollectionFromReq(path string) (activitypub.Collection, error) {
var respCollection activitypub.Collection
req, err := http.NewRequest("GET", path, nil)
if err != nil {
return respCollection, err
}
req.Header.Set("Accept", config.ActivityStreams)
resp, err := util.RouteProxy(req)
if err != nil {
return respCollection, err
}
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
err = json.Unmarshal(body, &respCollection)
return respCollection, err
}
func GetActorsFollowFromName(actor activitypub.Actor, name string) ([]string, error) {
var followingActors []string
follow, err := GetActorCollection(actor.Following)
if err != nil {
return followingActors, err
}
re := regexp.MustCompile("\\w+?$")
for _, e := range follow.Items {
if re.FindString(e.Id) == name {
followingActors = append(followingActors, e.Id)
}
}
return followingActors, nil
}
|