diff options
author | Julio Capote <jcapote@gmail.com> | 2022-12-28 03:20:11 +0000 |
---|---|---|
committer | Julio Capote <jcapote@gmail.com> | 2022-12-28 03:20:11 +0000 |
commit | 2408a50c46afad193e89f9381eb999cb5e8facab (patch) | |
tree | 606b713827f9e9ba0945fe5ebe8987f215f12d2f | |
parent | c0da8dd61b7447f18f03744202e52640220f10a9 (diff) | |
download | communique-2408a50c46afad193e89f9381eb999cb5e8facab.tar.gz |
working parse
-rw-r--r-- | cgi/servers.go | 45 | ||||
-rwxr-xr-x | sample-cgi-handler.sh | 2 |
2 files changed, 34 insertions, 13 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 } diff --git a/sample-cgi-handler.sh b/sample-cgi-handler.sh index ccad5e7..5cafc84 100755 --- a/sample-cgi-handler.sh +++ b/sample-cgi-handler.sh @@ -5,7 +5,7 @@ echo '{ "@context": "https://www.w3.org/ns/activitystreams", "type": "OrderedCollection", "totalItems": 1, - "items": [ + "orderedItems": [ { "type": "Note", "content": "hi" |