cli: Add more commands to client
This commit is contained in:
parent
fa969e3602
commit
eba2afc746
|
@ -7,6 +7,7 @@ import (
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"github.com/pstuifzand/microsub-server/microsub"
|
||||||
"github.com/pstuifzand/microsub-server/pkg/client"
|
"github.com/pstuifzand/microsub-server/pkg/client"
|
||||||
"github.com/pstuifzand/microsub-server/pkg/indieauth"
|
"github.com/pstuifzand/microsub-server/pkg/indieauth"
|
||||||
)
|
)
|
||||||
|
@ -129,11 +130,72 @@ func main() {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(os.Args) == 2 && os.Args[1] == "channels" {
|
performCommands(&c, os.Args)
|
||||||
channels := c.ChannelsGetList()
|
}
|
||||||
|
|
||||||
|
func performCommands(sub microsub.Microsub, commands []string) {
|
||||||
|
|
||||||
|
if len(commands) == 2 && commands[1] == "channels" {
|
||||||
|
channels := sub.ChannelsGetList()
|
||||||
for _, ch := range channels {
|
for _, ch := range channels {
|
||||||
fmt.Println(ch.UID, " ", ch.Name)
|
fmt.Println(ch.UID, " ", ch.Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(commands) == 3 && commands[1] == "timeline" {
|
||||||
|
channel := commands[2]
|
||||||
|
timeline := sub.TimelineGet("", "", channel)
|
||||||
|
|
||||||
|
for _, item := range timeline.Items {
|
||||||
|
fmt.Println("--------------------------")
|
||||||
|
if item.Name == "" && item.Content != nil {
|
||||||
|
fmt.Println(item.Content.HTML)
|
||||||
|
} else {
|
||||||
|
fmt.Println(item.Name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(commands) == 3 && commands[1] == "search" {
|
||||||
|
query := commands[2]
|
||||||
|
feeds := sub.Search(query)
|
||||||
|
|
||||||
|
for _, feed := range feeds {
|
||||||
|
fmt.Println(feed.Name, " ", feed.URL)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(commands) == 3 && commands[1] == "preview" {
|
||||||
|
url := commands[2]
|
||||||
|
timeline := sub.PreviewURL(url)
|
||||||
|
|
||||||
|
for _, item := range timeline.Items {
|
||||||
|
fmt.Println("--------------------------")
|
||||||
|
if item.Name == "" && item.Content != nil {
|
||||||
|
fmt.Println(item.Content.HTML)
|
||||||
|
} else {
|
||||||
|
fmt.Println(item.Name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(commands) == 3 && commands[1] == "follow" {
|
||||||
|
uid := commands[2]
|
||||||
|
feeds := sub.FollowGetList(uid)
|
||||||
|
for _, feed := range feeds {
|
||||||
|
fmt.Println(feed.Name, " ", feed.URL)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(commands) == 4 && commands[1] == "follow" {
|
||||||
|
uid := commands[2]
|
||||||
|
url := commands[3]
|
||||||
|
sub.FollowURL(uid, url)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(commands) == 4 && commands[1] == "unfollow" {
|
||||||
|
uid := commands[2]
|
||||||
|
url := commands[3]
|
||||||
|
sub.UnfollowURL(uid, url)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,16 +95,16 @@ func (c *Client) TimelineGet(after, before, channel string) microsub.Timeline {
|
||||||
return timeline
|
return timeline
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) PreviewURL(url string) []microsub.Timeline {
|
func (c *Client) PreviewURL(url string) microsub.Timeline {
|
||||||
args := make(map[string]string)
|
args := make(map[string]string)
|
||||||
args["url"] = url
|
args["url"] = url
|
||||||
res, err := c.microsubGetRequest("preview", args)
|
res, err := c.microsubGetRequest("preview", args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return []microsub.Timeline{}
|
return microsub.Timeline{}
|
||||||
}
|
}
|
||||||
defer res.Body.Close()
|
defer res.Body.Close()
|
||||||
dec := json.NewDecoder(res.Body)
|
dec := json.NewDecoder(res.Body)
|
||||||
var timeline []microsub.Timeline
|
var timeline microsub.Timeline
|
||||||
dec.Decode(&timeline)
|
dec.Decode(&timeline)
|
||||||
return timeline
|
return timeline
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user