aboutsummaryrefslogtreecommitdiff
path: root/routers/api/v1/activitypub/response.go
diff options
context:
space:
mode:
Diffstat (limited to 'routers/api/v1/activitypub/response.go')
-rw-r--r--routers/api/v1/activitypub/response.go19
1 files changed, 6 insertions, 13 deletions
diff --git a/routers/api/v1/activitypub/response.go b/routers/api/v1/activitypub/response.go
index 1aa361982..6f3bdf91c 100644
--- a/routers/api/v1/activitypub/response.go
+++ b/routers/api/v1/activitypub/response.go
@@ -9,27 +9,20 @@ 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"
+
+ ap "github.com/go-ap/activitypub"
+ "github.com/go-ap/jsonld"
)
-func response(ctx *context.APIContext, binary []byte) {
- var jsonmap map[string]interface{}
- err := json.Unmarshal(binary, &jsonmap)
+func response(ctx *context.APIContext, v interface{}) {
+ binary, err := jsonld.WithContext(jsonld.IRI(ap.ActivityBaseURI), jsonld.IRI(ap.SecurityContextURI)).Marshal(v)
if err != nil {
- ctx.Error(http.StatusInternalServerError, "Unmarshal", err)
+ ctx.Error(http.StatusInternalServerError, "Marshal", 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)
}