aboutsummaryrefslogtreecommitdiff
path: root/cgi/servers.go
diff options
context:
space:
mode:
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
}