diff options
author | Julio Capote <jcapote@gmail.com> | 2022-12-18 22:18:42 +0000 |
---|---|---|
committer | Julio Capote <jcapote@gmail.com> | 2022-12-18 22:18:42 +0000 |
commit | f0efb48bbd45ffd149cd9eb0603f7916ab9d8b67 (patch) | |
tree | 70ec7746b861d2f8791a4919a1247610605be211 | |
parent | 20faf99a2076905159a6d623a3f59f5eca1f808b (diff) | |
download | communique-f0efb48bbd45ffd149cd9eb0603f7916ab9d8b67.tar.gz |
start of profiles
-rw-r--r-- | README | 6 | ||||
-rw-r--r-- | http/server.go | 25 | ||||
-rw-r--r-- | registry/registry.go | 3 | ||||
-rw-r--r-- | resources/profile.go | 18 |
4 files changed, 48 insertions, 4 deletions
@@ -1,3 +1,7 @@ # Communique -Communique aims to be an activitypub platform that abstracts outboxes/inboxes away from handler implementations.
\ No newline at end of file +Communique aims to be an activitypub platform that abstracts outboxes/inboxes away from +handler implementations. + +1) handlers are defined in a config file +2) these are read into the registry which allows lookup by name or by fqdn
\ No newline at end of file diff --git a/http/server.go b/http/server.go index c720a6d..e0050b2 100644 --- a/http/server.go +++ b/http/server.go @@ -22,6 +22,7 @@ func (s *Server) Start(zapWriter io.Writer) { gin.DisableConsoleColor() gin.DefaultWriter = zapWriter // send gin logs to zap + // Webfinger router.GET("/.well-known/webfinger", func(c *gin.Context) { resourceParam := c.Query("resource") resource := s.registry.LookupResource(resourceParam) @@ -33,6 +34,7 @@ func (s *Server) Start(zapWriter io.Writer) { }) + // "User" endpoint router.GET("/actors/:actor", func(c *gin.Context) { actorParam := c.Param("actor") resource := s.registry.LookupByName(actorParam) @@ -44,5 +46,28 @@ 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) + 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.LookupByName(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 e8ed66c..7091819 100644 --- a/registry/registry.go +++ b/registry/registry.go @@ -34,9 +34,10 @@ func (r *Registry) LookupByName(name string) *resources.Profile { if r.LookupResource(fqdn) == nil { return nil } - return resources.RenderProfile() + return resources.RenderProfile(name, r.cfg.Domain) } +// TODO extract an existsbyname existsbyfqdn from this func (r *Registry) LookupResource(fqdn string) *resources.WebfingerResource { handler, ok := r.handlerMap[fqdn] if !ok { diff --git a/resources/profile.go b/resources/profile.go index 207f4de..83b2159 100644 --- a/resources/profile.go +++ b/resources/profile.go @@ -1,12 +1,26 @@ package resources +import "path" + type Profile struct { - Context []string `json:"@context"` + Context []string `json:"@context"` + Type string `json:"type"` + Id string `json:"id"` + Inbox string `json:"inbox"` + Outbox string `json:"outbox"` + Summary string `json:"summary"` + Username string `json:"preferredUsername"` +} + +type PublicKey struct { } -func RenderProfile() *Profile { +func RenderProfile(name, domain string) *Profile { p := Profile{ Context: []string{"https://www.w3.org/ns/activitystreams", "https://w3id.org/security/v1"}, + Type: "Service", + Inbox: path.Join("https://", domain, "actors", name, "inbox"), + Outbox: path.Join("https://", domain, "actors", name, "outbox"), } return &p } |