feat(app): federated collections proxy

master
Xeronith 2022-09-16 21:09:52 +04:30
rodzic 1c2528ec80
commit 17606adf7a
4 zmienionych plików z 84 dodań i 34 usunięć

Wyświetl plik

@ -8,6 +8,7 @@ type OrderedCollection struct {
Type string `json:"type,omitempty"`
TotalItems int `json:"totalItems"`
OrderedItems interface{} `json:"orderedItems,omitempty"`
First string `json:"first,omitempty"`
}
func NewOrderedCollection(id string, items interface{}, length int) *OrderedCollection {

Wyświetl plik

@ -20,6 +20,7 @@ var All = []contracts.IRoute{
OutboxPost,
OutboxGet,
Followers,
Following,
Follow,
Authorize,
}

Wyświetl plik

@ -2,6 +2,7 @@ package routes
import (
"activitypub"
"app/models/domain"
"app/models/repos"
"app/models/types"
"config"
@ -15,7 +16,29 @@ import (
)
var Followers = route.New(HttpGet, "/u/:username/followers", func(x IContext) error {
username := x.Request().Params("username")
username := domain.Username(x.Request().Params("username"))
if username.IsEmpty() {
return x.BadRequest("username required.")
}
if username.IsFederated() {
webfinger := activitypub.Webfinger{}
if err := x.GetActivityStream(username.Webfinger(), nil, &webfinger); err != nil {
return x.InternalServerError(err)
}
actor := activitypub.Actor{}
if err := x.GetActivityStream(webfinger.Self(), nil, &actor); err != nil {
return x.InternalServerError(err)
}
followers := activitypub.OrderedCollection{}
if err := x.GetActivityStream(actor.Followers, nil, &followers); err != nil {
return x.InternalServerError(err)
}
return x.Activity(followers)
} else {
actor := x.StringUtil().Format("%s://%s/u/%s", config.PROTOCOL, config.DOMAIN, username)
id := x.StringUtil().Format("%s://%s/u/%s/followers", config.PROTOCOL, config.DOMAIN, username)
@ -39,6 +62,7 @@ var Followers = route.New(HttpGet, "/u/:username/followers", func(x IContext) er
}
return x.Activity(result)
}
})
var AcceptFollowRequest = route.New(HttpPut, "/u/:username/followers/:id/accept", func(x IContext) error {

Wyświetl plik

@ -2,6 +2,7 @@ package routes
import (
"activitypub"
"app/models/domain"
"app/models/repos"
"app/models/types"
"config"
@ -10,7 +11,29 @@ import (
)
var Following = route.New(HttpGet, "/u/:username/following", func(x IContext) error {
username := x.Request().Params("username")
username := domain.Username(x.Request().Params("username"))
if username.IsEmpty() {
return x.BadRequest("username required.")
}
if username.IsFederated() {
webfinger := activitypub.Webfinger{}
if err := x.GetActivityStream(username.Webfinger(), nil, &webfinger); err != nil {
return x.InternalServerError(err)
}
actor := activitypub.Actor{}
if err := x.GetActivityStream(webfinger.Self(), nil, &actor); err != nil {
return x.InternalServerError(err)
}
following := activitypub.OrderedCollection{}
if err := x.GetActivityStream(actor.Following, nil, &following); err != nil {
return x.InternalServerError(err)
}
return x.Activity(following)
} else {
actor := x.StringUtil().Format("%s://%s/u/%s", config.PROTOCOL, config.DOMAIN, username)
id := x.StringUtil().Format("%s://%s/u/%s/following", config.PROTOCOL, config.DOMAIN, username)
@ -27,4 +50,5 @@ var Following = route.New(HttpGet, "/u/:username/following", func(x IContext) er
result := activitypub.NewOrderedCollection(id, items, len(items))
return x.Activity(result)
}
})