From 508a8486167e5202a2abee00294719ec3f803dfa Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Fri, 20 Jan 2023 17:25:19 +0000 Subject: [PATCH] Check if Create object is Note to prevent panic --- routers/api/v1/activitypub/person.go | 16 +++++++++------- services/repository/star.go | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/routers/api/v1/activitypub/person.go b/routers/api/v1/activitypub/person.go index e0a0dd4028..28a3a60ba8 100644 --- a/routers/api/v1/activitypub/person.go +++ b/routers/api/v1/activitypub/person.go @@ -131,13 +131,15 @@ func PersonInbox(ctx *context.APIContext) { // Unfollowing a user err = unfollow(ctx, activity) case ap.CreateType: - // TODO: this is kinda a hack - err = ap.OnObject(activity.Object, func(n *ap.Note) error { - noteIRI := n.InReplyTo.GetLink().String() - noteIRISplit := strings.Split(noteIRI, "/") - n.Context = ap.IRI(strings.TrimSuffix(noteIRI, "/"+noteIRISplit[len(noteIRISplit)-1])) - return createComment(ctx, n) - }) + if activity.Object.GetType() == ap.NoteType { + // TODO: this is kinda a hack + err = ap.OnObject(activity.Object, func(n *ap.Note) error { + noteIRI := n.InReplyTo.GetLink().String() + noteIRISplit := strings.Split(noteIRI, "/") + n.Context = ap.IRI(strings.TrimSuffix(noteIRI, "/"+noteIRISplit[len(noteIRISplit)-1])) + return createComment(ctx, n) + }) + } case ap.DeleteType: // Deleting a user err = delete(ctx, activity) diff --git a/services/repository/star.go b/services/repository/star.go index c9079701c3..be78ae4de1 100644 --- a/services/repository/star.go +++ b/services/repository/star.go @@ -73,7 +73,7 @@ func StarRepo(ctx context.Context, userID, repoID int64, star bool) error { } for i := int64(0); i < count; i++ { if followers[i].LoginType == auth.Federated { - create.To.Append(ap.IRI(followers[i].GetIRI()+"/inbox")) + create.To.Append(ap.IRI(followers[i].GetIRI() + "/inbox")) } } return activitypub.Send(user, &create)