added better feed url defaults (#18)

This commit is contained in:
davy wybiral 2019-08-08 05:34:53 -05:00 committed by GitHub
parent f41f2b823a
commit 02762c812c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -9,6 +9,7 @@ import (
"net" "net"
"net/http" "net/http"
"net/url" "net/url"
"os"
"path" "path"
"strconv" "strconv"
"time" "time"
@ -94,6 +95,7 @@ func (a *App) Run() error {
if err != nil { if err != nil {
return err return err
} }
a.Tor.OnionKey = key
} }
onion, err := key.Onion() onion, err := key.Onion()
if err != nil { if err != nil {
@ -233,10 +235,21 @@ func (a *App) rssHandler(w http.ResponseWriter, r *http.Request) {
var externalURL string var externalURL string
if len(cfg.ExternalURL) > 0 { if len(cfg.ExternalURL) > 0 {
externalURL = cfg.ExternalURL externalURL = cfg.ExternalURL
} else if a.Tor != nil {
onion, err := a.Tor.OnionKey.Onion()
if err != nil {
return
}
externalURL = fmt.Sprintf("http://%s.onion", onion.ServiceID)
} else { } else {
hostname, err := os.Hostname()
if err != nil {
host := a.Config.Server.Host host := a.Config.Server.Host
port := a.Config.Server.Port port := a.Config.Server.Port
externalURL = fmt.Sprintf("http://%s:%d", host, port) externalURL = fmt.Sprintf("http://%s:%d", host, port)
} else {
externalURL = fmt.Sprintf("http://%s", hostname)
}
} }
for _, v := range a.Library.Playlist() { for _, v := range a.Library.Playlist() {
u, err := url.Parse(externalURL) u, err := url.Parse(externalURL)