Apply suggestions from code review
This commit is contained in:
parent
08cb2d6d34
commit
c100b8e1e0
10 changed files with 16 additions and 13 deletions
|
@ -29,7 +29,7 @@ func BranchNew() *Branch {
|
||||||
func (br Branch) MarshalJSON() ([]byte, error) {
|
func (br Branch) MarshalJSON() ([]byte, error) {
|
||||||
b, err := br.Object.MarshalJSON()
|
b, err := br.Object.MarshalJSON()
|
||||||
if len(b) == 0 || err != nil {
|
if len(b) == 0 || err != nil {
|
||||||
return make([]byte, 0), err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
b = b[:len(b)-1]
|
b = b[:len(b)-1]
|
||||||
|
|
|
@ -33,7 +33,7 @@ func CommitNew() *Commit {
|
||||||
func (c Commit) MarshalJSON() ([]byte, error) {
|
func (c Commit) MarshalJSON() ([]byte, error) {
|
||||||
b, err := c.Object.MarshalJSON()
|
b, err := c.Object.MarshalJSON()
|
||||||
if len(b) == 0 || err != nil {
|
if len(b) == 0 || err != nil {
|
||||||
return make([]byte, 0), err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
b = b[:len(b)-1]
|
b = b[:len(b)-1]
|
||||||
|
|
|
@ -13,15 +13,16 @@ const ForgeFedNamespaceURI = "https://forgefed.org/ns"
|
||||||
// GetItemByType instantiates a new ForgeFed object if the type matches
|
// GetItemByType instantiates a new ForgeFed object if the type matches
|
||||||
// otherwise it defaults to existing activitypub package typer function.
|
// otherwise it defaults to existing activitypub package typer function.
|
||||||
func GetItemByType(typ ap.ActivityVocabularyType) (ap.Item, error) {
|
func GetItemByType(typ ap.ActivityVocabularyType) (ap.Item, error) {
|
||||||
if typ == CommitType {
|
switch typ {
|
||||||
|
case CommitType:
|
||||||
return CommitNew(), nil
|
return CommitNew(), nil
|
||||||
} else if typ == BranchType {
|
case BranchType:
|
||||||
return BranchNew(), nil
|
return BranchNew(), nil
|
||||||
} else if typ == RepositoryType {
|
case RepositoryType:
|
||||||
return RepositoryNew(""), nil
|
return RepositoryNew(""), nil
|
||||||
} else if typ == PushType {
|
case PushType:
|
||||||
return PushNew(), nil
|
return PushNew(), nil
|
||||||
} else if typ == TicketType {
|
case TicketType:
|
||||||
return TicketNew(), nil
|
return TicketNew(), nil
|
||||||
}
|
}
|
||||||
return ap.GetItemByType(typ)
|
return ap.GetItemByType(typ)
|
||||||
|
|
|
@ -33,7 +33,7 @@ func PushNew() *Push {
|
||||||
func (p Push) MarshalJSON() ([]byte, error) {
|
func (p Push) MarshalJSON() ([]byte, error) {
|
||||||
b, err := p.Object.MarshalJSON()
|
b, err := p.Object.MarshalJSON()
|
||||||
if len(b) == 0 || err != nil {
|
if len(b) == 0 || err != nil {
|
||||||
return make([]byte, 0), err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
b = b[:len(b)-1]
|
b = b[:len(b)-1]
|
||||||
|
|
|
@ -34,7 +34,7 @@ func RepositoryNew(id ap.ID) *Repository {
|
||||||
func (r Repository) MarshalJSON() ([]byte, error) {
|
func (r Repository) MarshalJSON() ([]byte, error) {
|
||||||
b, err := r.Actor.MarshalJSON()
|
b, err := r.Actor.MarshalJSON()
|
||||||
if len(b) == 0 || err != nil {
|
if len(b) == 0 || err != nil {
|
||||||
return make([]byte, 0), err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
b = b[:len(b)-1]
|
b = b[:len(b)-1]
|
||||||
|
|
|
@ -43,7 +43,7 @@ func TicketNew() *Ticket {
|
||||||
func (t Ticket) MarshalJSON() ([]byte, error) {
|
func (t Ticket) MarshalJSON() ([]byte, error) {
|
||||||
b, err := t.Object.MarshalJSON()
|
b, err := t.Object.MarshalJSON()
|
||||||
if len(b) == 0 || err != nil {
|
if len(b) == 0 || err != nil {
|
||||||
return make([]byte, 0), err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
b = b[:len(b)-1]
|
b = b[:len(b)-1]
|
||||||
|
|
|
@ -21,6 +21,7 @@ func Comment(ctx context.Context, note ap.Note) {
|
||||||
actorUser, err := personIRIToUser(ctx, note.AttributedTo.GetLink())
|
actorUser, err := personIRIToUser(ctx, note.AttributedTo.GetLink())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warn("Couldn't find actor", err)
|
log.Warn("Couldn't find actor", err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Move IRI processing stuff to iri.go
|
// TODO: Move IRI processing stuff to iri.go
|
||||||
|
|
|
@ -55,6 +55,6 @@ func Send(user *user_model.User, activity *ap.Activity) {
|
||||||
client, _ := NewClient(user, setting.AppURL+"api/v1/activitypub/user/"+user.Name+"#main-key")
|
client, _ := NewClient(user, setting.AppURL+"api/v1/activitypub/user/"+user.Name+"#main-key")
|
||||||
resp, _ := client.Post(binary, to.GetID().String())
|
resp, _ := client.Post(binary, to.GetID().String())
|
||||||
respBody, _ := io.ReadAll(io.LimitReader(resp.Body, setting.Federation.MaxSize))
|
respBody, _ := io.ReadAll(io.LimitReader(resp.Body, setting.Federation.MaxSize))
|
||||||
log.Debug(string(respBody))
|
log.Trace("Response from sending activity", string(respBody))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -102,6 +102,7 @@ func PersonInbox(ctx *context.APIContext) {
|
||||||
body, err := io.ReadAll(io.LimitReader(ctx.Req.Body, setting.Federation.MaxSize))
|
body, err := io.ReadAll(io.LimitReader(ctx.Req.Body, setting.Federation.MaxSize))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("Error reading request body", err)
|
ctx.ServerError("Error reading request body", err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var activity ap.Activity
|
var activity ap.Activity
|
||||||
|
@ -112,7 +113,7 @@ func PersonInbox(ctx *context.APIContext) {
|
||||||
case ap.UndoType:
|
case ap.UndoType:
|
||||||
activitypub.Unfollow(ctx, activity)
|
activitypub.Unfollow(ctx, activity)
|
||||||
default:
|
default:
|
||||||
log.Debug("ActivityStreams type not supported", activity)
|
log.Info("Incoming unsupported ActivityStreams type: %s", activity.GetType())
|
||||||
ctx.PlainText(http.StatusNotImplemented, "ActivityStreams type not supported")
|
ctx.PlainText(http.StatusNotImplemented, "ActivityStreams type not supported")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -140,7 +140,7 @@ func RepoInbox(ctx *context.APIContext) {
|
||||||
activitypub.Comment(ctx, note)
|
activitypub.Comment(ctx, note)
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
log.Warn("ActivityStreams type not supported", activity)
|
log.Info("Incoming unsupported ActivityStreams type: %s", activity["type"])
|
||||||
ctx.PlainText(http.StatusNotImplemented, "ActivityStreams type not supported")
|
ctx.PlainText(http.StatusNotImplemented, "ActivityStreams type not supported")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue