aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulio Capote <jcapote@gmail.com>2022-12-19 00:45:27 +0000
committerJulio Capote <jcapote@gmail.com>2022-12-19 00:45:27 +0000
commit6de1cd00cea3479a7a33418eebbc9399f77178c6 (patch)
tree580a612f5b9e0b729f63279481bd5c50d133d7d3
parentbd06b6e688c63ea9eb05e187e18ce535286ca3d4 (diff)
downloadcommunique-6de1cd00cea3479a7a33418eebbc9399f77178c6.tar.gz
start of outbox
Diffstat (limited to '')
-rw-r--r--http/server.go23
-rw-r--r--registry/registry.go8
-rw-r--r--resources/outbox.go25
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()
+}