actor details

This commit is contained in:
Niko Abeler 2024-05-18 13:10:14 +02:00
parent 741ccfac73
commit 29ae7e717f
2 changed files with 32 additions and 3 deletions

View File

@ -156,6 +156,29 @@ func (svc *ActivityPubService) HashtagId(hashtag string) string {
return cfg.FullUrl + "/tags/" + strings.ReplaceAll(hashtag, "#", "")
}
func (svc *ActivityPubService) ActorName() string {
cfg, _ := svc.siteConfigServcie.GetSiteConfig()
return cfg.Title
}
func (svc *ActivityPubService) ActorIcon() vocab.Image {
cfg, _ := svc.siteConfigServcie.GetSiteConfig()
u := cfg.AvatarUrl
pUrl, _ := url.Parse(u)
parts := strings.Split(pUrl.Path, ".")
fullUrl, _ := url.JoinPath(cfg.FullUrl, u)
return vocab.Image{
Type: vocab.ImageType,
MediaType: vocab.MimeType("image/" + parts[len(parts)-1]),
URL: vocab.IRI(fullUrl),
}
}
func (svc *ActivityPubService) ActorSummary() string {
cfg, _ := svc.siteConfigServcie.GetSiteConfig()
return cfg.SubTitle
}
func (s *ActivityPubService) AddFollower(follower string) error {
return s.followersRepo.Add(follower)
}

View File

@ -74,15 +74,16 @@ func (s *ActivityPubServer) HandleWebfinger(ctx *fiber.Ctx) error {
}
func (s *ActivityPubServer) Router(router fiber.Router) {
// router.Get("/actor", s.HandleActor)
router.Get("/outbox", s.HandleOutbox)
router.Post("/inbox", s.HandleInbox)
router.Get("/followers", s.HandleFollowers)
}
func (s *ActivityPubServer) HandleActor(ctx *fiber.Ctx) error {
accepts := strings.Contains(string(ctx.Request().Header.Peek("Accept")), "application/activity+json")
req_content := strings.Contains(string(ctx.Request().Header.Peek("Content-Type")), "application/activity+json")
accepts := (strings.Contains(string(ctx.Request().Header.Peek("Accept")), "application/activity+json") ||
strings.Contains(string(ctx.Request().Header.Peek("Accept")), "application/ld+json"))
req_content := (strings.Contains(string(ctx.Request().Header.Peek("Content-Type")), "application/activity+json") ||
strings.Contains(string(ctx.Request().Header.Peek("Content-Type")), "application/ld+json"))
if !accepts && !req_content {
return ctx.Next()
}
@ -98,6 +99,11 @@ func (s *ActivityPubServer) HandleActor(ctx *fiber.Ctx) error {
Owner: vocab.IRI(s.apService.ActorUrl()),
PublicKeyPem: apConfig.PublicKeyPem,
}
actor.Name = vocab.NaturalLanguageValues{{Value: vocab.Content(s.apService.ActorName())}}
actor.Icon = s.apService.ActorIcon()
actor.Summary = vocab.NaturalLanguageValues{{Value: vocab.Content(s.apService.ActorSummary())}}
data, err := jsonld.WithContext(
jsonld.IRI(vocab.ActivityBaseURI),
jsonld.IRI(vocab.SecurityContextURI),