diff options
Diffstat (limited to '')
-rw-r--r-- | http/server.go | 23 | ||||
-rw-r--r-- | registry/registry.go | 8 | ||||
-rw-r--r-- | resources/outbox.go | 25 |
3 files changed, 45 insertions, 11 deletions
diff --git a/http/server.go b/http/server.go index 5e6f652..bec683e 100644 --- a/http/server.go +++ b/http/server.go @@ -49,7 +49,7 @@ func (s *Server) Start(zapWriter io.Writer) { // // Inbox // router.POST("/actors/:actor/inbox", func(c *gin.Context) { // actorParam := c.Param("actor") - // resource := s.registry.LookupByName(actorParam) + // resource := s.registry.Inbox(actorParam) // if resource != nil { // c.JSON(http.StatusOK, resource) // } else { @@ -57,16 +57,17 @@ func (s *Server) Start(zapWriter io.Writer) { // } // }) - // // Outbox - // router.GET("/actors/:actor/outbox", func(c *gin.Context) { - // actorParam := c.Param("actor") - // resource := s.registry.LookupByName(actorParam) - // if resource != nil { - // c.JSON(http.StatusOK, resource) - // } else { - // c.JSON(http.StatusNotFound, nil) - // } - // }) + + // Outbox + router.GET("/actors/:actor/outbox", func(c *gin.Context) { + actorParam := c.Param("actor") + resource, _ := s.registry.Outbox(actorParam) + if resource != nil { + c.JSON(http.StatusOK, resource) + } else { + c.JSON(http.StatusNotFound, nil) + } + }) router.Run() } diff --git a/registry/registry.go b/registry/registry.go index 442e591..b12b773 100644 --- a/registry/registry.go +++ b/registry/registry.go @@ -33,6 +33,14 @@ func (r *Registry) Profile(name string) (map[string]interface{}, error) { return resources.RenderProfile(handler.handlerCfg.Name, r.cfg.Domain) } +func (r *Registry) Outbox(name string) (map[string]interface{}, error) { + handler := r.findByName(name) + if handler == nil { + return nil, nil + } + return resources.RenderOutbox(handler.handlerCfg.Name, r.cfg.Domain) +} + func (r *Registry) WebfingerResource(fqn string) (*resources.WebfingerResource, error) { handler := r.findByFQN(fqn) if handler == nil { diff --git a/resources/outbox.go b/resources/outbox.go new file mode 100644 index 0000000..9adb817 --- /dev/null +++ b/resources/outbox.go @@ -0,0 +1,25 @@ +package resources + +import ( + "fmt" + "net/url" + "path" + + "github.com/go-fed/activity/streams" +) + +func RenderOutbox(name, domain string) (map[string]interface{}, error) { + first, err := url.Parse(path.Join("https://", domain, "actors", name, "outbox", "?=page=true")) + if err != nil { + return nil, fmt.Errorf("could not partse url: %w", err) + } + + oc := streams.NewActivityStreamsOrderedCollection() + + ocProp := streams.NewActivityStreamsFirstProperty() + ocProp.SetIRI(first) + + oc.SetActivityStreamsFirst(ocProp) + + return oc.Serialize() +} |