From 2408a50c46afad193e89f9381eb999cb5e8facab Mon Sep 17 00:00:00 2001 From: Julio Capote Date: Tue, 27 Dec 2022 22:20:11 -0500 Subject: working parse --- cgi/servers.go | 45 +++++++++++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 12 deletions(-) (limited to 'cgi/servers.go') 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 } -- cgit v1.2.3