kopia lustrzana https://github.com/reiver/greatape
Porównaj commity
3 Commity
3e0ec9db94
...
856480989c
Autor | SHA1 | Data |
---|---|---|
Xeronith | 856480989c | |
Xeronith | 39e4ae766e | |
Xeronith | adac16f851 |
|
@ -0,0 +1,34 @@
|
||||||
|
package activitypub
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Follow struct {
|
||||||
|
Context string `json:"@context" validate:"activitystream"`
|
||||||
|
Id string `json:"id"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
Actor string `json:"actor"`
|
||||||
|
Object string `json:"object"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewFollow(follower, followee, uuid string) *Follow {
|
||||||
|
return &Follow{
|
||||||
|
Context: ActivityStreams,
|
||||||
|
Id: fmt.Sprintf("%s#follow/%s", follower, uuid),
|
||||||
|
Type: TypeFollow,
|
||||||
|
Actor: follower,
|
||||||
|
Object: followee,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func UnmarshalFollow(data []byte) (Follow, error) {
|
||||||
|
var follow Follow
|
||||||
|
err := json.Unmarshal(data, &follow)
|
||||||
|
return follow, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (follow *Follow) Marshal() ([]byte, error) {
|
||||||
|
return json.Marshal(follow)
|
||||||
|
}
|
|
@ -1,10 +1,8 @@
|
||||||
package commands
|
package commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/reiver/greatape/app/activitypub"
|
"github.com/reiver/greatape/app/activitypub"
|
||||||
|
@ -26,20 +24,62 @@ func FollowActor(x IDispatcher, username string, acct string) (IFollowActorResul
|
||||||
webfinger, err := activitypub.UnmarshalWebfinger(data)
|
webfinger, err := activitypub.UnmarshalWebfinger(data)
|
||||||
x.AssertNoError(err)
|
x.AssertNoError(err)
|
||||||
|
|
||||||
template := ""
|
subject := ""
|
||||||
for _, link := range webfinger.Links {
|
for _, link := range webfinger.Links {
|
||||||
if link.Rel == OSTATUS_SUBSCRIPTION {
|
if link.Rel == "self" {
|
||||||
template = *link.Template
|
subject = *link.Href
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if template == "" {
|
if x.IsEmpty(subject) {
|
||||||
return nil, fmt.Errorf("remote_account_lookup_failed")
|
return nil, ERROR_INVALID_PARAMETERS
|
||||||
}
|
}
|
||||||
|
|
||||||
uri := url.QueryEscape(x.Format("%s/u/%s", x.PublicUrl(), username))
|
identities := x.FilterIdentities(func(identity IIdentity) bool {
|
||||||
template = strings.Replace(template, "{uri}", uri, -1)
|
return identity.Username() == username
|
||||||
|
})
|
||||||
|
|
||||||
return x.NewFollowActorResult(template), nil
|
x.Assert(identities.HasExactlyOneItem()).Or(ERROR_USER_NOT_FOUND)
|
||||||
|
identity := identities.First()
|
||||||
|
|
||||||
|
follower := x.GetActorId()
|
||||||
|
|
||||||
|
followee := &activitypub.Actor{}
|
||||||
|
if err := x.GetActivityStreamSigned(subject, nil, followee); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
uniqueIdentifier := x.GenerateUUID()
|
||||||
|
follow := activitypub.NewFollow(follower, followee.ID, uniqueIdentifier)
|
||||||
|
|
||||||
|
x.Atomic(func() error {
|
||||||
|
activity := x.MarshalJson(follow)
|
||||||
|
|
||||||
|
x.AddActivityPubOutgoingActivity(
|
||||||
|
identity.Id(),
|
||||||
|
uniqueIdentifier,
|
||||||
|
x.UnixNano(),
|
||||||
|
follower,
|
||||||
|
followee.ID,
|
||||||
|
activitypub.TypeFollow,
|
||||||
|
activity,
|
||||||
|
)
|
||||||
|
|
||||||
|
x.AddActivityPubFollower(
|
||||||
|
follower,
|
||||||
|
followee.Inbox,
|
||||||
|
followee.ID,
|
||||||
|
activity,
|
||||||
|
false,
|
||||||
|
)
|
||||||
|
|
||||||
|
if err := x.PostActivityStreamSigned(followee.Inbox, follow, nil); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
return x.NewFollowActorResult(follow.Id), nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
package commands
|
package commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
|
|
||||||
"github.com/mitchellh/mapstructure"
|
|
||||||
"github.com/reiver/greatape/app/activitypub"
|
"github.com/reiver/greatape/app/activitypub"
|
||||||
. "github.com/reiver/greatape/components/constants"
|
. "github.com/reiver/greatape/components/constants"
|
||||||
. "github.com/reiver/greatape/components/contracts"
|
. "github.com/reiver/greatape/components/contracts"
|
||||||
|
@ -18,54 +15,72 @@ func PostToInbox(x IDispatcher, username string, body []byte) (IPostToInboxResul
|
||||||
identity := identities.First()
|
identity := identities.First()
|
||||||
|
|
||||||
object := &activitypub.Object{}
|
object := &activitypub.Object{}
|
||||||
if err := json.Unmarshal(body, object); err != nil {
|
x.UnmarshalJson(body, object)
|
||||||
return nil, ERROR_UNKNOWN_ACTIVITY_PUB_OBJECT
|
|
||||||
}
|
|
||||||
|
|
||||||
keyId := x.Format("%s/u/%s#main-key", x.PublicUrl(), username)
|
|
||||||
|
|
||||||
switch object.Type {
|
switch object.Type {
|
||||||
case activitypub.TypeFollow:
|
case activitypub.TypeAccept:
|
||||||
{
|
{
|
||||||
activity := &activitypub.Activity{}
|
activity := &activitypub.Activity{}
|
||||||
if err := json.Unmarshal(body, activity); err != nil {
|
x.UnmarshalJson(body, activity)
|
||||||
return nil, ERROR_UNKNOWN_ACTIVITY_PUB_ACTIVITY
|
|
||||||
|
switch activity.Object.(map[string]interface{})["type"] {
|
||||||
|
case activitypub.TypeFollow:
|
||||||
|
follow := &activitypub.Follow{}
|
||||||
|
x.DecodeMapStructure(activity.Object, follow)
|
||||||
|
|
||||||
|
x.Atomic(func() error {
|
||||||
|
x.ForEachActivityPubFollower(func(record IActivityPubFollower) {
|
||||||
|
if record.Handle() == follow.Actor && record.Subject() == follow.Object {
|
||||||
|
record.UpdateAcceptedAtomic(x.Transaction(), true, x.Identity())
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
x.AddActivityPubIncomingActivity(
|
||||||
|
identity.Id(),
|
||||||
|
x.GenerateUUID(),
|
||||||
|
x.UnixNano(),
|
||||||
|
follow.Object,
|
||||||
|
follow.Actor,
|
||||||
|
activitypub.TypeAccept,
|
||||||
|
string(body),
|
||||||
|
)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
default:
|
||||||
|
return nil, ERROR_INVALID_PARAMETERS
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
case activitypub.TypeFollow:
|
||||||
|
{
|
||||||
|
follow := &activitypub.Follow{}
|
||||||
|
x.UnmarshalJson(body, follow)
|
||||||
|
|
||||||
url := activity.Actor
|
url := follow.Actor
|
||||||
var inbox string
|
|
||||||
|
|
||||||
{
|
actor := &activitypub.Actor{}
|
||||||
actor := &activitypub.Actor{}
|
if err := x.GetActivityStreamSigned(url, nil, actor); err != nil {
|
||||||
if err := x.GetActivityStreamSigned(url, keyId, identity.PrivateKey(), nil, actor); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
inbox = actor.Inbox
|
|
||||||
}
|
|
||||||
|
|
||||||
data, err := json.Marshal(activity)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
follower := x.AddActivityPubFollower(
|
follower := x.AddActivityPubFollower(
|
||||||
activity.Actor,
|
follow.Actor,
|
||||||
inbox,
|
actor.Inbox,
|
||||||
x.Format("%s/u/%s", x.PublicUrl(), username),
|
x.Format("%s/u/%s", x.PublicUrl(), username),
|
||||||
string(data),
|
x.MarshalJson(follow),
|
||||||
false,
|
false,
|
||||||
)
|
)
|
||||||
|
|
||||||
data, _ = json.Marshal(&activitypub.Activity{
|
activity := &activitypub.Activity{
|
||||||
Context: activitypub.ActivityStreams,
|
Context: activitypub.ActivityStreams,
|
||||||
ID: x.Format("%s/%s", x.PublicUrl(), x.GenerateUUID()),
|
ID: x.Format("%s/%s", x.PublicUrl(), x.GenerateUUID()),
|
||||||
Type: activitypub.TypeAccept,
|
Type: activitypub.TypeAccept,
|
||||||
Actor: x.Format("%s/u/%s", x.PublicUrl(), username),
|
Actor: x.Format("%s/u/%s", x.PublicUrl(), username),
|
||||||
Object: activity,
|
Object: follow,
|
||||||
})
|
}
|
||||||
|
|
||||||
if err := x.PostActivityStreamSigned(inbox, keyId, identity.PrivateKey(), data, nil); err != nil {
|
if err := x.PostActivityStreamSigned(actor.Inbox, activity, nil); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,18 +89,12 @@ func PostToInbox(x IDispatcher, username string, body []byte) (IPostToInboxResul
|
||||||
case activitypub.TypeCreate:
|
case activitypub.TypeCreate:
|
||||||
{
|
{
|
||||||
activity := &activitypub.Activity{}
|
activity := &activitypub.Activity{}
|
||||||
if err := json.Unmarshal(body, activity); err != nil {
|
x.UnmarshalJson(body, activity)
|
||||||
return nil, ERROR_UNKNOWN_ACTIVITY_PUB_ACTIVITY
|
|
||||||
}
|
|
||||||
|
|
||||||
switch activity.Object.(map[string]interface{})["type"] {
|
switch activity.Object.(map[string]interface{})["type"] {
|
||||||
case activitypub.TypeNote:
|
case activitypub.TypeNote:
|
||||||
note := &activitypub.Note{}
|
note := &activitypub.Note{}
|
||||||
if err := mapstructure.Decode(activity.Object, note); err != nil {
|
x.DecodeMapStructure(activity.Object, note)
|
||||||
return nil, ERROR_UNKNOWN_ACTIVITY_PUB_ACTIVITY
|
|
||||||
}
|
|
||||||
|
|
||||||
raw, _ := json.Marshal(note)
|
|
||||||
|
|
||||||
x.AddActivityPubIncomingActivity(
|
x.AddActivityPubIncomingActivity(
|
||||||
identity.Id(),
|
identity.Id(),
|
||||||
|
@ -94,16 +103,14 @@ func PostToInbox(x IDispatcher, username string, body []byte) (IPostToInboxResul
|
||||||
note.AttributedTo,
|
note.AttributedTo,
|
||||||
note.To[0],
|
note.To[0],
|
||||||
note.Content,
|
note.Content,
|
||||||
string(raw),
|
string(body),
|
||||||
)
|
)
|
||||||
default:
|
default:
|
||||||
return nil, ERROR_INVALID_PARAMETERS
|
return nil, ERROR_INVALID_PARAMETERS
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
{
|
return nil, ERROR_INVALID_PARAMETERS
|
||||||
return nil, ERROR_INVALID_PARAMETERS
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return x.NewPostToInboxResult(body), nil
|
return x.NewPostToInboxResult(body), nil
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
package commands
|
package commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
ap "github.com/go-ap/activitypub"
|
|
||||||
"github.com/reiver/greatape/app/activitypub"
|
"github.com/reiver/greatape/app/activitypub"
|
||||||
. "github.com/reiver/greatape/components/constants"
|
. "github.com/reiver/greatape/components/constants"
|
||||||
. "github.com/reiver/greatape/components/contracts"
|
. "github.com/reiver/greatape/components/contracts"
|
||||||
|
@ -21,21 +19,21 @@ func PostToOutbox(x IDispatcher, username string, body []byte) (IPostToOutboxRes
|
||||||
|
|
||||||
item := x.UnmarshalActivityPubObjectOrLink(body)
|
item := x.UnmarshalActivityPubObjectOrLink(body)
|
||||||
|
|
||||||
id := x.Format("%s/u/%s", x.PublicUrl(), identity.Username())
|
actorId := x.GetActorId()
|
||||||
|
|
||||||
publicKeyId := x.Format("%s#main-key", id)
|
|
||||||
privateKey := identity.PrivateKey()
|
|
||||||
|
|
||||||
switch item.GetType() {
|
switch item.GetType() {
|
||||||
case ap.NoteType:
|
case activitypub.TypeNote:
|
||||||
{
|
{
|
||||||
note := x.UnmarshalActivityPubNote(body)
|
note, err := activitypub.UnmarshalNote(body)
|
||||||
|
if err != nil {
|
||||||
|
return nil, ERROR_INVALID_PARAMETERS
|
||||||
|
}
|
||||||
|
|
||||||
content := note.Content.First().Value.String()
|
content := note.Content
|
||||||
to := note.To.First().GetID().String()
|
to := note.To[0]
|
||||||
from := note.AttributedTo.GetID().String()
|
from := note.AttributedTo
|
||||||
|
|
||||||
if from != id {
|
if from != actorId {
|
||||||
return nil, ERROR_INVALID_PARAMETERS
|
return nil, ERROR_INVALID_PARAMETERS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,23 +49,19 @@ func PostToOutbox(x IDispatcher, username string, body []byte) (IPostToOutboxRes
|
||||||
Object: note,
|
Object: note,
|
||||||
}
|
}
|
||||||
|
|
||||||
if to != activitypub.Public {
|
if to != ACTIVITY_PUB_PUBLIC {
|
||||||
recipient := &activitypub.Actor{}
|
recipient := &activitypub.Actor{}
|
||||||
if err := x.GetActivityStreamSigned(to, publicKeyId, privateKey, nil, recipient); err != nil {
|
if err := x.GetActivityStreamSigned(to, nil, recipient); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
to = recipient.ID
|
to = recipient.ID
|
||||||
|
|
||||||
data, _ := json.Marshal(activity)
|
if err := x.PostActivityStreamSigned(recipient.Inbox, activity, nil); err != nil {
|
||||||
output := &struct{}{}
|
|
||||||
if err := x.PostActivityStreamSigned(recipient.Inbox, publicKeyId, privateKey, data, output); err != nil {
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
raw, _ := json.Marshal(note)
|
|
||||||
|
|
||||||
x.LogActivityPubOutgoingActivity(
|
x.LogActivityPubOutgoingActivity(
|
||||||
identity.Id(),
|
identity.Id(),
|
||||||
uniqueIdentifier,
|
uniqueIdentifier,
|
||||||
|
@ -75,7 +69,7 @@ func PostToOutbox(x IDispatcher, username string, body []byte) (IPostToOutboxRes
|
||||||
from,
|
from,
|
||||||
to,
|
to,
|
||||||
content,
|
content,
|
||||||
string(raw),
|
string(body),
|
||||||
"PostToOutbox",
|
"PostToOutbox",
|
||||||
EMPTY_JSON,
|
EMPTY_JSON,
|
||||||
)
|
)
|
||||||
|
|
|
@ -26,7 +26,7 @@ type (
|
||||||
Atomic(handler TransactionHandler) error
|
Atomic(handler TransactionHandler) error
|
||||||
Schedule(spec string, callback func()) error
|
Schedule(spec string, callback func()) error
|
||||||
GetSystemComponent(name string) ISystemComponent
|
GetSystemComponent(name string) ISystemComponent
|
||||||
RequestActivityStream(method, url, keyId, privateKey string, data []byte, output interface{}) error
|
RequestActivityStream(method, url, publicKeyId, privateKey string, input, output interface{}) error
|
||||||
LogRemoteCall(context IContext, eventType uint32, source string, input, result interface{}, err error)
|
LogRemoteCall(context IContext, eventType uint32, source string, input, result interface{}, err error)
|
||||||
|
|
||||||
// Document
|
// Document
|
||||||
|
|
|
@ -1234,16 +1234,26 @@ type IDispatcher interface {
|
||||||
// Join concatenates the elements of its first argument to create a single string. The separator
|
// Join concatenates the elements of its first argument to create a single string. The separator
|
||||||
// string is placed between elements in the resulting string.
|
// string is placed between elements in the resulting string.
|
||||||
Join(elements []string, separator string) string
|
Join(elements []string, separator string) string
|
||||||
|
// MarshalJson returns the JSON representation of input and panics in case of an error.
|
||||||
|
MarshalJson(input any) string
|
||||||
|
// UnmarshalJson parses the JSON-encoded data and stores the result in the
|
||||||
|
// value pointed to by output. If output is nil or not a pointer, it panics.
|
||||||
|
UnmarshalJson(data []byte, output any)
|
||||||
|
// DecodeMapStructure takes an input structure and uses reflection to
|
||||||
|
// translate it to the output structure. output must be a pointer to a
|
||||||
|
// map or struct. It panics in case of an error.
|
||||||
|
DecodeMapStructure(input, output interface{})
|
||||||
|
|
||||||
IsTestEnvironment() bool
|
IsTestEnvironment() bool
|
||||||
IsDevelopmentEnvironment() bool
|
IsDevelopmentEnvironment() bool
|
||||||
IsStagingEnvironment() bool
|
IsStagingEnvironment() bool
|
||||||
IsProductionEnvironment() bool
|
IsProductionEnvironment() bool
|
||||||
|
|
||||||
GetActivityStream(url string, data []byte, output interface{}) error
|
GetActorId() string
|
||||||
PostActivityStream(url string, data []byte, output interface{}) error
|
GetActivityStream(url string, input, output interface{}) error
|
||||||
GetActivityStreamSigned(url, keyId, privateKey string, data []byte, output interface{}) error
|
PostActivityStream(url string, input, output interface{}) error
|
||||||
PostActivityStreamSigned(url, keyId, privateKey string, data []byte, output interface{}) error
|
GetActivityStreamSigned(url string, input, output interface{}) error
|
||||||
|
PostActivityStreamSigned(url string, input, output interface{}) error
|
||||||
UnmarshalActivityPubObjectOrLink([]byte) activitypub.ObjectOrLink
|
UnmarshalActivityPubObjectOrLink([]byte) activitypub.ObjectOrLink
|
||||||
UnmarshalActivityPubNote([]byte) *activitypub.Note
|
UnmarshalActivityPubNote([]byte) *activitypub.Note
|
||||||
}
|
}
|
||||||
|
|
|
@ -238,7 +238,19 @@ func (conductor *conductor) SignRequest(keyId, privateKey string, data []byte, r
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (conductor *conductor) RequestActivityStream(method, url, keyId, privateKey string, data []byte, output interface{}) error {
|
func (conductor *conductor) RequestActivityStream(method, url, publicKeyId, privateKey string, input, output interface{}) error {
|
||||||
|
var (
|
||||||
|
data []byte
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
|
||||||
|
if input != nil {
|
||||||
|
data, err = json.Marshal(input)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var reader io.Reader
|
var reader io.Reader
|
||||||
if data != nil {
|
if data != nil {
|
||||||
reader = bytes.NewBuffer(data)
|
reader = bytes.NewBuffer(data)
|
||||||
|
@ -252,7 +264,7 @@ func (conductor *conductor) RequestActivityStream(method, url, keyId, privateKey
|
||||||
req.Header.Set("Accept", "application/activity+json")
|
req.Header.Set("Accept", "application/activity+json")
|
||||||
|
|
||||||
if privateKey != "" {
|
if privateKey != "" {
|
||||||
if err := conductor.SignRequest(keyId, privateKey, data, req); err != nil {
|
if err := conductor.SignRequest(publicKeyId, privateKey, data, req); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/go-ap/activitypub"
|
"github.com/go-ap/activitypub"
|
||||||
|
"github.com/mitchellh/mapstructure"
|
||||||
. "github.com/reiver/greatape/components/contracts"
|
. "github.com/reiver/greatape/components/contracts"
|
||||||
"github.com/valyala/fastjson"
|
"github.com/valyala/fastjson"
|
||||||
. "github.com/xeronith/diamante/contracts/logging"
|
. "github.com/xeronith/diamante/contracts/logging"
|
||||||
|
@ -318,6 +319,27 @@ func (dispatcher *dispatcher) Join(elements []string, separator string) string {
|
||||||
return strings.Join(elements, separator)
|
return strings.Join(elements, separator)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (dispatcher *dispatcher) MarshalJson(input any) string {
|
||||||
|
data, err := json.Marshal(input)
|
||||||
|
if err != nil {
|
||||||
|
panic(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
return string(data)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (dispatcher *dispatcher) UnmarshalJson(data []byte, output any) {
|
||||||
|
if err := json.Unmarshal(data, output); err != nil {
|
||||||
|
panic(err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (dispatcher *dispatcher) DecodeMapStructure(input, output interface{}) {
|
||||||
|
if err := mapstructure.Decode(input, output); err != nil {
|
||||||
|
panic(err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (dispatcher *dispatcher) IsTestEnvironment() bool {
|
func (dispatcher *dispatcher) IsTestEnvironment() bool {
|
||||||
return dispatcher.conductor.IdentityManager().IsTestEnvironment()
|
return dispatcher.conductor.IdentityManager().IsTestEnvironment()
|
||||||
}
|
}
|
||||||
|
@ -334,20 +356,34 @@ func (dispatcher *dispatcher) IsProductionEnvironment() bool {
|
||||||
return dispatcher.conductor.IdentityManager().IsProductionEnvironment()
|
return dispatcher.conductor.IdentityManager().IsProductionEnvironment()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dispatcher *dispatcher) GetActivityStream(url string, data []byte, output interface{}) error {
|
func (dispatcher *dispatcher) GetActorId() string {
|
||||||
return dispatcher.conductor.RequestActivityStream(http.MethodGet, url, "", "", data, output)
|
config := dispatcher.conductor.Configuration().GetServerConfiguration()
|
||||||
|
return fmt.Sprintf("%s://%s/u/%s", config.GetProtocol(), config.GetFQDN(), dispatcher.identity.Username())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dispatcher *dispatcher) PostActivityStream(url string, data []byte, output interface{}) error {
|
func (dispatcher *dispatcher) GetPublicKeyId(identity Identity) string {
|
||||||
return dispatcher.conductor.RequestActivityStream(http.MethodPost, url, "", "", data, output)
|
config := dispatcher.conductor.Configuration().GetServerConfiguration()
|
||||||
|
return fmt.Sprintf("%s://%s/u/%s#main-key", config.GetProtocol(), config.GetFQDN(), identity.Username())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dispatcher *dispatcher) GetActivityStreamSigned(url, keyId, privateKey string, data []byte, output interface{}) error {
|
func (dispatcher *dispatcher) GetActivityStream(url string, input, output interface{}) error {
|
||||||
return dispatcher.conductor.RequestActivityStream(http.MethodGet, url, keyId, privateKey, data, output)
|
return dispatcher.conductor.RequestActivityStream(http.MethodGet, url, "", "", input, output)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dispatcher *dispatcher) PostActivityStreamSigned(url, keyId, privateKey string, data []byte, output interface{}) error {
|
func (dispatcher *dispatcher) PostActivityStream(url string, input, output interface{}) error {
|
||||||
return dispatcher.conductor.RequestActivityStream(http.MethodPost, url, keyId, privateKey, data, output)
|
return dispatcher.conductor.RequestActivityStream(http.MethodPost, url, "", "", input, output)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (dispatcher *dispatcher) GetActivityStreamSigned(url string, input, output interface{}) error {
|
||||||
|
identity := dispatcher.identity
|
||||||
|
keyId := dispatcher.GetPublicKeyId(identity)
|
||||||
|
return dispatcher.conductor.RequestActivityStream(http.MethodGet, url, keyId, identity.PrivateKey(), input, output)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (dispatcher *dispatcher) PostActivityStreamSigned(url string, input, output interface{}) error {
|
||||||
|
identity := dispatcher.identity
|
||||||
|
keyId := dispatcher.GetPublicKeyId(identity)
|
||||||
|
return dispatcher.conductor.RequestActivityStream(http.MethodPost, url, keyId, identity.PrivateKey(), input, output)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dispatcher *dispatcher) UnmarshalActivityPubObjectOrLink(data []byte) activitypub.ObjectOrLink {
|
func (dispatcher *dispatcher) UnmarshalActivityPubObjectOrLink(data []byte) activitypub.ObjectOrLink {
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -8,7 +8,7 @@ require (
|
||||||
github.com/robfig/cron v1.2.0
|
github.com/robfig/cron v1.2.0
|
||||||
github.com/sendgrid/sendgrid-go v3.12.0+incompatible
|
github.com/sendgrid/sendgrid-go v3.12.0+incompatible
|
||||||
github.com/valyala/fastjson v1.6.4
|
github.com/valyala/fastjson v1.6.4
|
||||||
github.com/xeronith/diamante v1.15.5
|
github.com/xeronith/diamante v1.15.6
|
||||||
google.golang.org/protobuf v1.28.1
|
google.golang.org/protobuf v1.28.1
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
4
go.sum
4
go.sum
|
@ -64,8 +64,8 @@ github.com/valyala/fastjson v1.6.4/go.mod h1:CLCAqky6SMuOcxStkYQvblddUtoRxhYMGLr
|
||||||
github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
|
github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
|
||||||
github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo=
|
github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo=
|
||||||
github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
|
github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
|
||||||
github.com/xeronith/diamante v1.15.5 h1:/VnxmLiG+CFqwMTphjgp2juQcpu0cVxD3DO8bj4rwOQ=
|
github.com/xeronith/diamante v1.15.6 h1:kC3BMP/vjwW1EOUzLHVeISO9s/O/MCc2kOBV7mn3i5A=
|
||||||
github.com/xeronith/diamante v1.15.5/go.mod h1:7kgdoRJVrQvML7Z9BT6di3XU1o2eTeE0hbwy66dMOrA=
|
github.com/xeronith/diamante v1.15.6/go.mod h1:7kgdoRJVrQvML7Z9BT6di3XU1o2eTeE0hbwy66dMOrA=
|
||||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||||
|
|
Ładowanie…
Reference in New Issue