aboutsummaryrefslogtreecommitdiff
path: root/cgi/servers.go
diff options
context:
space:
mode:
authorJulio Capote <jcapote@gmail.com>2022-12-28 03:20:11 +0000
committerJulio Capote <jcapote@gmail.com>2022-12-28 03:20:11 +0000
commit2408a50c46afad193e89f9381eb999cb5e8facab (patch)
tree606b713827f9e9ba0945fe5ebe8987f215f12d2f /cgi/servers.go
parentc0da8dd61b7447f18f03744202e52640220f10a9 (diff)
downloadcommunique-2408a50c46afad193e89f9381eb999cb5e8facab.tar.gz
working parse
Diffstat (limited to 'cgi/servers.go')
-rw-r--r--cgi/servers.go45
1 files changed, 33 insertions, 12 deletions
diff --git a/cgi/servers.go b/cgi/servers.go
index 91c98e9..e0917f1 100644
--- a/cgi/servers.go
+++ b/cgi/servers.go
@@ -73,13 +73,7 @@ func startTicker(h config.Handler, db *badger.DB, log *zap.SugaredLogger) {
return
case _ = <-ticker.C:
output := tick(h)
- 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)
- // })
+ err := processTick(h, output, db, log)
if err != nil {
log.Error(err)
}
@@ -88,8 +82,7 @@ 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))
+func processTick(h config.Handler, output []byte, db *badger.DB, log *zap.SugaredLogger) error {
var m map[string]interface{}
err := json.Unmarshal(output, &m)
if err != nil {
@@ -108,9 +101,37 @@ func processTick(output []byte, db *badger.DB, log *zap.SugaredLogger) error {
if err != nil {
return fmt.Errorf("could not resolve JSON: %w", err)
}
- log.Debugf("coll is %+v", coll)
- // TODO TODO TODO
- coll.GetActivityStreamsOrderedItems()
+ keyBase := fmt.Sprintf("outbox:%s", h.Name)
+ seq, err := db.GetSequence([]byte(keyBase), 10)
+ defer seq.Release()
+ orderedProp := coll.GetActivityStreamsOrderedItems()
+ for iter := orderedProp.Begin(); iter != orderedProp.End(); iter = iter.Next() {
+ contentType := iter.GetType().GetTypeName()
+ log.Debugf("found object type %s in activity stream", contentType)
+
+ contentNote := iter.GetActivityStreamsNote()
+ if contentNote.GetActivityStreamsContent() != nil {
+ content := contentNote.GetActivityStreamsContent()
+ var contentVal string
+ for contentIter := content.Begin(); contentIter != content.End(); contentIter = contentIter.Next() {
+ contentVal = contentIter.GetXMLSchemaString()
+ log.Debugf("contentVal is %+v", contentVal)
+ autoinc, err := seq.Next()
+ if err != nil {
+ return fmt.Errorf("could not auto inc: %w", err)
+ }
+ keyName := fmt.Sprintf("%s:%d", keyBase, autoinc)
+ err = db.Update(func(txn *badger.Txn) error {
+ e := badger.NewEntry([]byte(keyName), []byte(contentVal))
+ log.With("name", "ticker").Infof("writing '%s' to %s", contentVal, keyName)
+ return txn.SetEntry(e)
+ })
+ if err != nil {
+ return fmt.Errorf("could insert into outbox: %w", err)
+ }
+ }
+ }
+ }
return nil
}