aboutsummaryrefslogtreecommitdiff
path: root/cgi
diff options
context:
space:
mode:
authorJulio Capote <jcapote@gmail.com>2022-12-20 03:43:11 +0000
committerJulio Capote <jcapote@gmail.com>2022-12-20 03:43:11 +0000
commitc0da8dd61b7447f18f03744202e52640220f10a9 (patch)
treecc36dd69ef89b0171578681559a7ff374c40b27b /cgi
parentafdf8a014236452e098ab1266c9a9315824f8103 (diff)
downloadcommunique-c0da8dd61b7447f18f03744202e52640220f10a9.tar.gz
wip
Diffstat (limited to 'cgi')
-rw-r--r--cgi/servers.go44
1 files changed, 37 insertions, 7 deletions
diff --git a/cgi/servers.go b/cgi/servers.go
index 55bc5d2..91c98e9 100644
--- a/cgi/servers.go
+++ b/cgi/servers.go
@@ -2,6 +2,7 @@ package cgi
import (
"context"
+ "encoding/json"
"fmt"
"io/ioutil"
"net"
@@ -13,6 +14,8 @@ import (
"git.capotej.com/capotej/communique/config"
"github.com/dgraph-io/badger/v3"
+ "github.com/go-fed/activity/streams"
+ "github.com/go-fed/activity/streams/vocab"
"go.uber.org/zap"
)
@@ -68,14 +71,15 @@ func startTicker(h config.Handler, db *badger.DB, log *zap.SugaredLogger) {
select {
case <-done:
return
- case t := <-ticker.C:
+ case _ = <-ticker.C:
output := tick(h)
- keyName := fmt.Sprintf("outbox:%s:%d", h.Name, t.Unix())
- err := db.Update(func(txn *badger.Txn) error {
- e := badger.NewEntry([]byte(keyName), output)
- log.With("name", "ticker").Infof("writing '%s' to %s", output, keyName)
- return txn.SetEntry(e)
- })
+ err := processTick(output, db, log)
+ // keyName := fmt.Sprintf("outbox:%s:%d", h.Name, t.Unix())
+ // err := db.Update(func(txn *badger.Txn) error {
+ // e := badger.NewEntry([]byte(keyName), output)
+ // log.With("name", "ticker").Infof("writing '%s' to %s", output, keyName)
+ // return txn.SetEntry(e)
+ // })
if err != nil {
log.Error(err)
}
@@ -84,6 +88,32 @@ func startTicker(h config.Handler, db *badger.DB, log *zap.SugaredLogger) {
}()
}
+func processTick(output []byte, db *badger.DB, log *zap.SugaredLogger) error {
+ log.Debugf("processTick map is %+s", string(output))
+ var m map[string]interface{}
+ err := json.Unmarshal(output, &m)
+ if err != nil {
+ return fmt.Errorf("could not unmarshal JSON: %w", err)
+ }
+ log.Debugf("processTick map is %+v", m)
+ var coll vocab.ActivityStreamsOrderedCollection
+ resolver, err := streams.NewJSONResolver(func(c context.Context, a vocab.ActivityStreamsOrderedCollection) error {
+ // Example: store the article in the enclosing scope, for later.
+ coll = a
+ // We could pass an error back up, if desired.
+ return nil
+ })
+ ctx := context.Background()
+ err = resolver.Resolve(ctx, m)
+ if err != nil {
+ return fmt.Errorf("could not resolve JSON: %w", err)
+ }
+ log.Debugf("coll is %+v", coll)
+ // TODO TODO TODO
+ coll.GetActivityStreamsOrderedItems()
+ return nil
+}
+
func tick(h config.Handler) []byte {
sock := fmt.Sprintf("%s.sock", h.Name)
httpc := http.Client{