forked from davecheney/pub
/
synchronisefollowers.go
59 lines (51 loc) · 1.28 KB
/
synchronisefollowers.go
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
package main
import (
"context"
"fmt"
"github.com/carlmjohnson/requests"
)
type SynchroniseFollowersCmd struct {
Source string `required:"" help:"source actor"`
Dest string `required:"" help:"destination actor"`
}
type OrderedCollection struct {
Type string `json:"type"`
TotalItems int `json:"totalItems"`
First string `json:"first"`
}
type OrderedCollectionPage struct {
Type string `json:"type"`
TotalItems int `json:"totalItems"`
Next string `json:"next"`
Prev string `json:"prev"`
OrderedItems []string `json:"orderedItems"`
}
func (s *SynchroniseFollowersCmd) Run(_ *Context) error {
var col OrderedCollection
err := requests.URL(s.Source+"/following").
Header("Accept", `application/ld+json; profile="https://www.w3.org/ns/activitystreams"`).
ToJSON(&col).
Fetch(context.Background())
if err != nil {
return err
}
url := col.First
for {
var page OrderedCollectionPage
err := requests.URL(url).
Header("Accept", `application/ld+json; profile="https://www.w3.org/ns/activitystreams"`).
ToJSON(&page).
Fetch(context.Background())
if err != nil {
return err
}
for _, item := range page.OrderedItems {
fmt.Println(item)
}
if page.Next == "" {
break
}
url = page.Next
}
return nil
}