add @context to actor

This commit is contained in:
Niko Abeler 2024-02-26 20:17:53 +01:00
parent 7eb3bf0b44
commit bc7b146e91
1 changed files with 17 additions and 3 deletions

View File

@ -9,6 +9,7 @@ import (
"owl-blogs/render" "owl-blogs/render"
vocab "github.com/go-ap/activitypub" vocab "github.com/go-ap/activitypub"
"github.com/go-ap/jsonld"
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
) )
@ -42,6 +43,7 @@ func (cfg *ActivityPubConfig) ParseFormData(data model.HttpFormData, binSvc mode
type WebfingerResponse struct { type WebfingerResponse struct {
Subject string `json:"subject"` Subject string `json:"subject"`
Aliases []string `json:"aliases"`
Links []WebfingerLink `json:"links"` Links []WebfingerLink `json:"links"`
} }
@ -64,8 +66,18 @@ func (s *ActivityPubServer) HandleWebfinger(ctx *fiber.Ctx) error {
s.configRepo.Get(ACT_PUB_CONF_NAME, &apConfig) s.configRepo.Get(ACT_PUB_CONF_NAME, &apConfig)
s.configRepo.Get(config.SITE_CONFIG, &siteConfig) s.configRepo.Get(config.SITE_CONFIG, &siteConfig)
domain, err := url.Parse(siteConfig.FullUrl)
if err != nil {
return err
}
subject := ctx.Query("resource", "")
if subject != "acct:"+apConfig.PreferredUsername+"@"+domain.Host {
return ctx.Status(404).JSON(nil)
}
webfinger := WebfingerResponse{ webfinger := WebfingerResponse{
Subject: ctx.Query("resource"), Subject: subject,
Links: []WebfingerLink{ Links: []WebfingerLink{
{ {
@ -101,8 +113,10 @@ func (s *ActivityPubServer) HandleActor(ctx *fiber.Ctx) error {
Owner: vocab.IRI(siteConfig.FullUrl + "/activitypub/actor"), Owner: vocab.IRI(siteConfig.FullUrl + "/activitypub/actor"),
PublicKeyPem: apConfig.PublicKeyPem, PublicKeyPem: apConfig.PublicKeyPem,
} }
data, err := jsonld.WithContext(
data, err := actor.MarshalJSON() jsonld.IRI(vocab.ActivityBaseURI),
jsonld.IRI(vocab.SecurityContextURI),
).Marshal(actor)
if err != nil { if err != nil {
return err return err
} }