From 29ae7e717f3fc720beed17b0519ba4dbc62cdebd Mon Sep 17 00:00:00 2001 From: Niko Abeler Date: Sat, 18 May 2024 13:10:14 +0200 Subject: [PATCH] actor details --- app/activity_pub_service.go | 23 +++++++++++++++++++++++ web/activity_pub_handler.go | 12 +++++++++--- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/app/activity_pub_service.go b/app/activity_pub_service.go index 9aecef6..e81ccb4 100644 --- a/app/activity_pub_service.go +++ b/app/activity_pub_service.go @@ -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) } diff --git a/web/activity_pub_handler.go b/web/activity_pub_handler.go index b5f6f54..3164e2b 100644 --- a/web/activity_pub_handler.go +++ b/web/activity_pub_handler.go @@ -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),