mirror of
https://github.com/mrusme/neonmodem.git
synced 2024-11-03 04:27:16 -05:00
Implemented connect check, fixed smaller issues
This commit is contained in:
parent
df13d05bd9
commit
32b1ffe1f0
@ -55,7 +55,7 @@ func (a *Aggregator) ListPosts() ([]post.Post, []error) {
|
||||
var posts []post.Post
|
||||
|
||||
// TODO: Clean up implementation
|
||||
if os.Getenv("neonmodem_TEST") == "true" {
|
||||
if os.Getenv("NEONMODEM_TEST") == "true" {
|
||||
jsonPosts, err := os.ReadFile("posts.db")
|
||||
if err == nil {
|
||||
err = json.Unmarshal(jsonPosts, &posts)
|
||||
@ -86,9 +86,11 @@ func (a *Aggregator) ListPosts() ([]post.Post, []error) {
|
||||
})
|
||||
|
||||
// TODO: Clean up implementation
|
||||
jsonPosts, err := json.Marshal(posts)
|
||||
if err == nil {
|
||||
os.WriteFile("posts.db", jsonPosts, 0600)
|
||||
if os.Getenv("NEONMODEM_TEST") == "true" {
|
||||
jsonPosts, err := json.Marshal(posts)
|
||||
if err == nil {
|
||||
os.WriteFile("posts.db", jsonPosts, 0600)
|
||||
}
|
||||
}
|
||||
|
||||
return posts, errs
|
||||
|
@ -2,7 +2,9 @@ package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/mrusme/neonmodem/config"
|
||||
"github.com/mrusme/neonmodem/system"
|
||||
@ -25,6 +27,7 @@ func connectBase() *cobra.Command {
|
||||
Long: "Add a new connection to a BBS.",
|
||||
PreRun: func(cmd *cobra.Command, args []string) {
|
||||
sysType, _ := cmd.Flags().GetString("type")
|
||||
sysType = strings.ToLower(sysType)
|
||||
if sysType != "hackernews" {
|
||||
cmd.MarkFlagRequired("url")
|
||||
}
|
||||
@ -36,6 +39,36 @@ func connectBase() *cobra.Command {
|
||||
LOG.Panicln(err)
|
||||
}
|
||||
|
||||
sysURLparsed, err := url.Parse(sysURL)
|
||||
if err != nil {
|
||||
fmt.Print(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if caps := sys.GetCapabilities(); !caps.IsCapableOf("connect:multiple") {
|
||||
for _, existingSys := range CFG.Systems {
|
||||
if existingSys.Type == sysType {
|
||||
existingSysURL, ok := existingSys.Config["url"]
|
||||
if !ok {
|
||||
fmt.Println("Cannot add multiple instances of this system!")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
existingSysURLparsed, err := url.Parse(existingSysURL.(string))
|
||||
if err != nil {
|
||||
fmt.Print(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
//&& existingSysURLparsed.RequestURI() == sysURLparsed.RequestURI()
|
||||
if existingSysURLparsed.Host == sysURLparsed.Host {
|
||||
fmt.Println("Cannot add multiple instances of this system!")
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if err := sys.Connect(sysURL); err != nil {
|
||||
LOG.Panicln(err)
|
||||
}
|
||||
|
@ -131,7 +131,7 @@ func (c *Client) NewRequest(
|
||||
return nil, err
|
||||
}
|
||||
|
||||
req.Header.Add("User-Agent", "neonmodem")
|
||||
req.Header.Add("User-Agent", "Neon Modem Overdrive")
|
||||
req.Header.Add("Accept", "application/json")
|
||||
req.Header.Add("Content-Type", "application/json")
|
||||
req.Header.Add("User-Api-Client-Id", c.credentials["client_id"])
|
||||
|
@ -50,6 +50,10 @@ func (sys *System) GetCapabilities() adapter.Capabilities {
|
||||
var caps []adapter.Capability
|
||||
|
||||
caps = append(caps,
|
||||
adapter.Capability{
|
||||
ID: "connect:multiple",
|
||||
Name: "Connect Multiple",
|
||||
},
|
||||
adapter.Capability{
|
||||
ID: "list:forums",
|
||||
Name: "List Forums",
|
||||
|
@ -9,6 +9,7 @@ func (sys *System) Connect(sysURL string) error {
|
||||
if sys.config == nil {
|
||||
sys.config = make(map[string]interface{})
|
||||
}
|
||||
sys.config["url"] = "https://news.ycombinator.com"
|
||||
sys.config["credentials"] = credentials
|
||||
|
||||
return nil
|
||||
|
@ -48,6 +48,11 @@ func (sys *System) GetCapabilities() adapter.Capabilities {
|
||||
var caps []adapter.Capability
|
||||
|
||||
caps = append(caps,
|
||||
// TODO: Requires accounts
|
||||
// adapter.Capability{
|
||||
// ID: "connect:multiple",
|
||||
// Name: "Connect Multiple",
|
||||
// },
|
||||
adapter.Capability{
|
||||
ID: "list:forums",
|
||||
Name: "List Forums",
|
||||
|
@ -47,6 +47,10 @@ func (sys *System) GetCapabilities() adapter.Capabilities {
|
||||
var caps []adapter.Capability
|
||||
|
||||
caps = append(caps,
|
||||
adapter.Capability{
|
||||
ID: "connect:multiple",
|
||||
Name: "Connect Multiple",
|
||||
},
|
||||
adapter.Capability{
|
||||
ID: "list:forums",
|
||||
Name: "List Forums",
|
||||
|
@ -128,7 +128,7 @@ func (c *Client) NewRequest(
|
||||
return nil, err
|
||||
}
|
||||
|
||||
req.Header.Add("User-Agent", "neonmodem")
|
||||
req.Header.Add("User-Agent", "Neon Modem Overdrive")
|
||||
req.Header.Add("Accept", "application/json")
|
||||
req.Header.Add("Content-Type", "application/json")
|
||||
|
||||
|
@ -49,6 +49,11 @@ func (sys *System) GetCapabilities() adapter.Capabilities {
|
||||
var caps []adapter.Capability
|
||||
|
||||
caps = append(caps,
|
||||
// TODO: Requires accounts
|
||||
// adapter.Capability{
|
||||
// ID: "connect:multiple",
|
||||
// Name: "Connect Multiple",
|
||||
// },
|
||||
adapter.Capability{
|
||||
ID: "list:forums",
|
||||
Name: "List Forums",
|
||||
|
Loading…
Reference in New Issue
Block a user