Apply suggestions from code review

This commit is contained in:
Anthony Wang 2022-07-17 11:19:48 -05:00
parent 08cb2d6d34
commit c100b8e1e0
Signed by: a
GPG key ID: BC96B00AEC5F2D76
10 changed files with 16 additions and 13 deletions

View file

@ -29,7 +29,7 @@ func BranchNew() *Branch {
func (br Branch) MarshalJSON() ([]byte, error) {
b, err := br.Object.MarshalJSON()
if len(b) == 0 || err != nil {
return make([]byte, 0), err
return nil, err
}
b = b[:len(b)-1]

View file

@ -33,7 +33,7 @@ func CommitNew() *Commit {
func (c Commit) MarshalJSON() ([]byte, error) {
b, err := c.Object.MarshalJSON()
if len(b) == 0 || err != nil {
return make([]byte, 0), err
return nil, err
}
b = b[:len(b)-1]

View file

@ -13,15 +13,16 @@ const ForgeFedNamespaceURI = "https://forgefed.org/ns"
// GetItemByType instantiates a new ForgeFed object if the type matches
// otherwise it defaults to existing activitypub package typer function.
func GetItemByType(typ ap.ActivityVocabularyType) (ap.Item, error) {
if typ == CommitType {
switch typ {
case CommitType:
return CommitNew(), nil
} else if typ == BranchType {
case BranchType:
return BranchNew(), nil
} else if typ == RepositoryType {
case RepositoryType:
return RepositoryNew(""), nil
} else if typ == PushType {
case PushType:
return PushNew(), nil
} else if typ == TicketType {
case TicketType:
return TicketNew(), nil
}
return ap.GetItemByType(typ)

View file

@ -33,7 +33,7 @@ func PushNew() *Push {
func (p Push) MarshalJSON() ([]byte, error) {
b, err := p.Object.MarshalJSON()
if len(b) == 0 || err != nil {
return make([]byte, 0), err
return nil, err
}
b = b[:len(b)-1]

View file

@ -34,7 +34,7 @@ func RepositoryNew(id ap.ID) *Repository {
func (r Repository) MarshalJSON() ([]byte, error) {
b, err := r.Actor.MarshalJSON()
if len(b) == 0 || err != nil {
return make([]byte, 0), err
return nil, err
}
b = b[:len(b)-1]

View file

@ -43,7 +43,7 @@ func TicketNew() *Ticket {
func (t Ticket) MarshalJSON() ([]byte, error) {
b, err := t.Object.MarshalJSON()
if len(b) == 0 || err != nil {
return make([]byte, 0), err
return nil, err
}
b = b[:len(b)-1]

View file

@ -21,6 +21,7 @@ func Comment(ctx context.Context, note ap.Note) {
actorUser, err := personIRIToUser(ctx, note.AttributedTo.GetLink())
if err != nil {
log.Warn("Couldn't find actor", err)
return
}
// TODO: Move IRI processing stuff to iri.go

View file

@ -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")
resp, _ := client.Post(binary, to.GetID().String())
respBody, _ := io.ReadAll(io.LimitReader(resp.Body, setting.Federation.MaxSize))
log.Debug(string(respBody))
log.Trace("Response from sending activity", string(respBody))
}
}

View file

@ -102,6 +102,7 @@ func PersonInbox(ctx *context.APIContext) {
body, err := io.ReadAll(io.LimitReader(ctx.Req.Body, setting.Federation.MaxSize))
if err != nil {
ctx.ServerError("Error reading request body", err)
return
}
var activity ap.Activity
@ -112,7 +113,7 @@ func PersonInbox(ctx *context.APIContext) {
case ap.UndoType:
activitypub.Unfollow(ctx, activity)
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")
return
}

View file

@ -140,7 +140,7 @@ func RepoInbox(ctx *context.APIContext) {
activitypub.Comment(ctx, note)
}
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")
return
}