Compare commits

...

2 Commits

Author SHA1 Message Date
8bad2d1a88
Add export opml command
All checks were successful
the build was successful
2018-09-10 20:19:32 +02:00
691be5300d
Remove cache-control header 2018-09-08 20:29:07 +02:00
2 changed files with 52 additions and 1 deletions

View File

@ -24,7 +24,9 @@ import (
"log"
"net/url"
"os"
"time"
"github.com/gilliek/go-opml/opml"
"p83.nl/go/ekster/pkg/client"
"p83.nl/go/ekster/pkg/indieauth"
"p83.nl/go/ekster/pkg/microsub"
@ -138,6 +140,8 @@ Commands:
unfollow UID URL unfollow URL on channel UID
export opml export feeds as OPML
Global arguments:
`)
@ -326,6 +330,53 @@ func performCommands(sub microsub.Microsub, commands []string) {
log.Fatalf("An error occurred: %s\n", err)
}
}
if len(commands) == 2 && commands[0] == "export" {
filetype := commands[1]
if filetype == "opml" {
output := opml.OPML{}
output.Head.Title = "Microsub channels and feeds"
output.Head.DateCreated = time.Now().Format(time.RFC3339)
output.Version = "1.0"
channels, err := sub.ChannelsGetList()
if err != nil {
log.Fatalf("An error occurred: %s\n", err)
}
for _, c := range channels {
var feeds []opml.Outline
list, err := sub.FollowGetList(c.UID)
if err != nil {
log.Fatalf("An error occurred: %s\n", err)
}
for _, f := range list {
feeds = append(feeds, opml.Outline{
Title: f.Name,
Text: f.Name,
Type: f.Type,
URL: f.URL,
HTMLURL: f.URL,
XMLURL: f.URL,
})
}
output.Body.Outlines = append(output.Body.Outlines, opml.Outline{
Text: c.Name,
Title: c.Name,
Outlines: feeds,
})
}
xml, err := output.XML()
if err != nil {
log.Fatalf("An error occurred: %s\n", err)
}
os.Stdout.WriteString(xml)
} else {
log.Fatalf("unsupported filetype %q", filetype)
}
}
}
func showItem(item *microsub.Item) {

View File

@ -47,7 +47,7 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if r.Method == http.MethodOptions {
w.Header().Add("Access-Control-Allow-Origin", "*")
w.Header().Add("Access-Control-Allow-Methods", "GET, POST")
w.Header().Add("Access-Control-Allow-Headers", "Authorization, Cache-Control")
w.Header().Add("Access-Control-Allow-Headers", "Authorization")
return
}