aboutsummaryrefslogtreecommitdiff
path: root/cgi/servers.go
diff options
context:
space:
mode:
authorJulio Capote <jcapote@gmail.com>2022-12-31 02:20:02 +0000
committerJulio Capote <jcapote@gmail.com>2022-12-31 02:20:02 +0000
commitc500a2be38afcbb5688537d97c7c3ee30a57dba4 (patch)
tree79cf1884ca7529299646b567b7705378bdf08fd3 /cgi/servers.go
parent74ffcfe6b2c80b7cf459798dc42bd278075ccb50 (diff)
downloadcommunique-c500a2be38afcbb5688537d97c7c3ee30a57dba4.tar.gz
parse and persist feeds from handlers
Diffstat (limited to 'cgi/servers.go')
-rw-r--r--cgi/servers.go38
1 files changed, 9 insertions, 29 deletions
diff --git a/cgi/servers.go b/cgi/servers.go
index f5652ed..c751135 100644
--- a/cgi/servers.go
+++ b/cgi/servers.go
@@ -2,7 +2,6 @@ package cgi
import (
"context"
- "encoding/json"
"fmt"
"io/ioutil"
"net"
@@ -14,8 +13,7 @@ import (
"git.capotej.com/capotej/communique/config"
"git.capotej.com/capotej/communique/models"
- "github.com/go-fed/activity/streams"
- "github.com/go-fed/activity/streams/vocab"
+ "github.com/mmcdole/gofeed"
"go.uber.org/zap"
)
@@ -83,35 +81,17 @@ func startTicker(h config.Handler, persister *models.Persister, log *zap.Sugared
}
func processTick(h config.Handler, output []byte, persister *models.Persister, log *zap.SugaredLogger) error {
- var m map[string]interface{}
- err := json.Unmarshal(output, &m)
+ fp := gofeed.NewParser()
+ fp.ParseString(string(output))
+ feed, err := fp.ParseString(string(output))
if err != nil {
- return fmt.Errorf("could not unmarshal JSON: %w", err)
+ return 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)
- }
- orderedProp := coll.GetActivityStreamsOrderedItems()
- for iter := orderedProp.Begin(); iter != orderedProp.End(); iter = iter.Next() {
- contentType := iter.GetType().GetTypeName()
- contentNote := iter.GetActivityStreamsNote() // TODO make this configurable since it cant be dynamic
-
- jsonMap, _ := streams.Serialize(contentNote)
- jsonIter, _ := json.Marshal(jsonMap)
- log.Debugf("found object %s of type %s in activity stream", jsonIter, contentType)
- localNote := models.NewActivityStreamsObject(contentNote, h)
- err = persister.Store(localNote)
+ for _, v := range feed.Items {
+ log.Debugf("found content '%s'", v.Content)
+ outboxItem := models.CreateOutboxItem(h, []byte(v.Content))
+ err = persister.Store(outboxItem)
if err != nil {
return err
}