diff options
author | Anthony Wang | 2022-06-18 12:27:11 -0500 |
---|---|---|
committer | Anthony Wang | 2022-06-18 12:27:11 -0500 |
commit | 37d2d01f8f3273e169e771ade6a843c68e5f7d16 (patch) | |
tree | cafd86b54245657b1ae8133044f1042c42fff79f | |
parent | fe18cf7620442eb59ccad22f36a11aa6cd9a89bf (diff) |
Use go-ap/jsonld to add @context and marshal JSON
-rw-r--r-- | routers/api/v1/activitypub/person.go | 21 |
1 files changed, 3 insertions, 18 deletions
diff --git a/routers/api/v1/activitypub/person.go b/routers/api/v1/activitypub/person.go index 0e123881a..1cc5be8e1 100644 --- a/routers/api/v1/activitypub/person.go +++ b/routers/api/v1/activitypub/person.go @@ -10,11 +10,11 @@ import ( "code.gitea.io/gitea/modules/activitypub" "code.gitea.io/gitea/modules/context" - "code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" ap "github.com/go-ap/activitypub" + "github.com/go-ap/jsonld" ) // Person function returns the Person actor for a user @@ -72,28 +72,13 @@ func Person(ctx *context.APIContext) { } person.PublicKey.PublicKeyPem = publicKeyPem - binary, err := person.MarshalJSON() + binary, err := jsonld.WithContext(jsonld.IRI(ap.ActivityBaseURI), jsonld.IRI(ap.SecurityContextURI)).Marshal(person) if err != nil { - ctx.Error(http.StatusInternalServerError, "Serialize", err) + ctx.Error(http.StatusInternalServerError, "MarshalJSON", err) return } - - var jsonmap map[string]interface{} - err = json.Unmarshal(binary, &jsonmap) - if err != nil { - ctx.Error(http.StatusInternalServerError, "Unmarshal", err) - return - } - - jsonmap["@context"] = []string{"https://www.w3.org/ns/activitystreams", "https://w3id.org/security/v1"} - ctx.Resp.Header().Add("Content-Type", activitypub.ActivityStreamsContentType) ctx.Resp.WriteHeader(http.StatusOK) - binary, err = json.Marshal(jsonmap) - if err != nil { - ctx.Error(http.StatusInternalServerError, "Marshal", err) - return - } if _, err = ctx.Resp.Write(binary); err != nil { log.Error("write to resp err: %v", err) } |