Send a remote follow in PersonInboxGet
This commit is contained in:
parent
cb0a9de330
commit
046d363305
2 changed files with 57 additions and 8 deletions
|
@ -9,8 +9,10 @@ import (
|
|||
"net/url"
|
||||
"strings"
|
||||
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/activitypub"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/json"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/routers/api/v1/user"
|
||||
|
||||
|
@ -48,10 +50,18 @@ func Person(ctx *context.APIContext) {
|
|||
id.SetIRI(idIRI)
|
||||
person.SetJSONLDId(id)
|
||||
|
||||
tp := streams.NewJSONLDTypeProperty()
|
||||
tp.AppendXMLSchemaString("Person")
|
||||
person.SetJSONLDType(tp)
|
||||
|
||||
name := streams.NewActivityStreamsNameProperty()
|
||||
name.AppendXMLSchemaString(username)
|
||||
person.SetActivityStreamsName(name)
|
||||
|
||||
preferredUsername := streams.NewActivityStreamsPreferredUsernameProperty()
|
||||
preferredUsername.SetXMLSchemaString(username)
|
||||
person.SetActivityStreamsPreferredUsername(preferredUsername)
|
||||
|
||||
ibox := streams.NewActivityStreamsInboxProperty()
|
||||
urlObject, _ := url.Parse(link + "/inbox")
|
||||
ibox.SetIRI(urlObject)
|
||||
|
@ -67,7 +77,7 @@ func Person(ctx *context.APIContext) {
|
|||
publicKeyType := streams.NewW3IDSecurityV1PublicKey()
|
||||
|
||||
pubKeyIDProp := streams.NewJSONLDIdProperty()
|
||||
pubKeyIRI, _ := url.Parse(link + "/#main-key")
|
||||
pubKeyIRI, _ := url.Parse(link + "#main-key")
|
||||
pubKeyIDProp.SetIRI(pubKeyIRI)
|
||||
publicKeyType.SetJSONLDId(pubKeyIDProp)
|
||||
|
||||
|
@ -96,7 +106,7 @@ func Person(ctx *context.APIContext) {
|
|||
|
||||
// PersonInboxGet function
|
||||
func PersonInboxGet(ctx *context.APIContext) {
|
||||
// swagger:operation GET /activitypub/user/{username}/outbox activitypub activitypubPersonInbox
|
||||
// swagger:operation GET /activitypub/user/{username}/inbox activitypub activitypubPersonInbox
|
||||
// ---
|
||||
// summary: Returns the inbox
|
||||
// produces:
|
||||
|
@ -112,8 +122,47 @@ func PersonInboxGet(ctx *context.APIContext) {
|
|||
// "200":
|
||||
// "$ref": "#/responses/ActivityPub"
|
||||
|
||||
follow := streams.NewActivityStreamsFollow()
|
||||
|
||||
myIRI, _ := url.Parse("https://git.exozy.me/api/v1/activitypub/user/ta180m/inbox")
|
||||
followIRI, _ := url.Parse("https://social.exozy.me/users/ta180m")
|
||||
|
||||
id, _ := url.Parse("https://git.exozy.me/Ta180m")
|
||||
idProperty := streams.NewJSONLDIdProperty()
|
||||
idProperty.Set(id)
|
||||
|
||||
me := streams.NewActivityStreamsActorProperty()
|
||||
me.AppendIRI(myIRI)
|
||||
follow.SetActivityStreamsActor(me)
|
||||
|
||||
op := streams.NewActivityStreamsObjectProperty()
|
||||
op.AppendIRI(followIRI)
|
||||
follow.SetActivityStreamsObject(op)
|
||||
|
||||
user, err := user_model.GetUserByName("ta180m")
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "debug", err)
|
||||
}
|
||||
c, err := activitypub.NewClient(user, "https://git.exozy.me/api/v1/activitypub/user/ta180m#main-key")
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "debug", err)
|
||||
}
|
||||
|
||||
jsonmap, err := streams.Serialize(follow)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "debug", err)
|
||||
}
|
||||
body, err := json.Marshal(jsonmap)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "debug", err)
|
||||
}
|
||||
resp, err := c.Post(body, "https://social.exozy.me/inbox")
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "debug", err)
|
||||
}
|
||||
ctx.Error(http.StatusInternalServerError, "debug", resp)
|
||||
|
||||
ctx.Status(http.StatusOK)
|
||||
activitypub.GetUserActor().GetInbox(ctx, ctx.Resp, ctx.Req)
|
||||
}
|
||||
|
||||
// PersonInboxPost function
|
||||
|
@ -134,8 +183,8 @@ func PersonInboxPost(ctx *context.APIContext) {
|
|||
// "200":
|
||||
// "$ref": "#/responses/ActivityPub"
|
||||
|
||||
ctx.Error(http.StatusInternalServerError, "inboxpost", ctx.Req.Body)
|
||||
ctx.Status(http.StatusOK)
|
||||
activitypub.GetUserActor().PostInbox(ctx, ctx.Resp, ctx.Req)
|
||||
}
|
||||
|
||||
// PersonOutboxGet function
|
||||
|
@ -156,8 +205,8 @@ func PersonOutboxGet(ctx *context.APIContext) {
|
|||
// "200":
|
||||
// "$ref": "#/responses/ActivityPub"
|
||||
|
||||
ctx.Error(http.StatusInternalServerError, "outboxget", ctx.Req.Body)
|
||||
ctx.Status(http.StatusOK)
|
||||
activitypub.GetUserActor().GetOutbox(ctx, ctx.Resp, ctx.Req)
|
||||
}
|
||||
|
||||
// PersonOutboxPost function
|
||||
|
@ -178,6 +227,6 @@ func PersonOutboxPost(ctx *context.APIContext) {
|
|||
// "200":
|
||||
// "$ref": "#/responses/ActivityPub"
|
||||
|
||||
ctx.Error(http.StatusInternalServerError, "outboxpost", ctx.Req.Body)
|
||||
ctx.Status(http.StatusOK)
|
||||
activitypub.GetUserActor().PostOutbox(ctx, ctx.Resp, ctx.Req)
|
||||
}
|
|
@ -600,9 +600,9 @@ func Routes(sessioner func(http.Handler) http.Handler) *web.Route {
|
|||
m.Get("/nodeinfo", misc.NodeInfo)
|
||||
m.Group("/activitypub", func() {
|
||||
m.Get("/user/{username}", activitypub.Person)
|
||||
m.Get("/user/{username}/inbox", activitypub.ReqSignature(), activitypub.PersonInboxGet)
|
||||
m.Get("/user/{username}/inbox", activitypub.PersonInboxGet)
|
||||
m.Post("/user/{username}/inbox", activitypub.ReqSignature(), activitypub.PersonInboxPost)
|
||||
m.Get("/user/{username}/outbox", activitypub.ReqSignature(), activitypub.PersonOutboxGet)
|
||||
m.Get("/user/{username}/outbox", activitypub.PersonOutboxGet)
|
||||
m.Post("/user/{username}/outbox", activitypub.ReqSignature(), activitypub.PersonOutboxPost)
|
||||
})
|
||||
}
|
||||
|
|
Reference in a new issue