1
0
mirror of https://github.com/writeas/writeas-cli synced 2025-07-26 23:08:16 +00:00

add config.TorURL

select tor URL based on provided host flag, default host in config or
default write.as onion address. in that order of precedence.
This commit is contained in:
Rob Loranger 2019-06-24 20:37:07 -07:00
parent 498a3af787
commit 83ad65c27d
No known key found for this signature in database
GPG Key ID: D6F1633A4F0903B8
2 changed files with 14 additions and 1 deletions

View File

@ -28,7 +28,7 @@ func newClient(c *cli.Context, authRequired bool) (*writeas.Client, error) {
clientConfig.URL = config.WriteasBaseURL + "/api"
}
if config.IsTor(c) {
clientConfig.URL = config.TorBaseURL
clientConfig.URL = config.TorURL(c)
clientConfig.TorPort = config.TorPort(c)
}

View File

@ -2,6 +2,7 @@ package config
import (
"net/url"
"strings"
"github.com/cloudfoundry/jibber_jabber"
"github.com/writeas/writeas-cli/log"
@ -38,6 +39,18 @@ func TorPort(c *cli.Context) int {
return torPort
}
func TorURL(c *cli.Context) string {
flagHost := c.String("host")
if flagHost != "" && strings.HasSuffix(flagHost, "onion") {
return flagHost
}
cfg, _ := LoadConfig(c.App.ExtraInfo()["configDir"])
if cfg != nil && cfg.Default.Host != "" && strings.HasSuffix(cfg.Default.Host, "onion") {
return cfg.Default.Host
}
return TorBaseURL
}
func Language(c *cli.Context, auto bool) string {
if l := c.String("lang"); l != "" {
return l