Compare commits
2 Commits
453b695901
...
8bad2d1a88
Author | SHA1 | Date | |
---|---|---|---|
8bad2d1a88 | |||
691be5300d |
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user