2019-06-09 04:15:06 +00:00
|
|
|
package bot
|
|
|
|
|
|
|
|
import (
|
2021-07-29 16:33:03 +00:00
|
|
|
"embed"
|
2021-01-09 18:46:28 +00:00
|
|
|
"encoding/json"
|
2019-06-09 04:15:06 +00:00
|
|
|
"net/http"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2021-07-29 16:33:03 +00:00
|
|
|
//go:embed *.html
|
|
|
|
var embeddedFS embed.FS
|
|
|
|
|
2019-06-09 04:15:06 +00:00
|
|
|
func (b *bot) serveRoot(w http.ResponseWriter, r *http.Request) {
|
2021-07-29 16:33:03 +00:00
|
|
|
index, _ := embeddedFS.ReadFile("index.html")
|
|
|
|
w.Write(index)
|
2021-01-09 18:46:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (b *bot) serveNav(w http.ResponseWriter, r *http.Request) {
|
|
|
|
enc := json.NewEncoder(w)
|
|
|
|
err := enc.Encode(b.GetWebNavigation())
|
|
|
|
if err != nil {
|
|
|
|
jsonErr, _ := json.Marshal(err)
|
|
|
|
w.WriteHeader(500)
|
|
|
|
w.Write(jsonErr)
|
|
|
|
}
|
2019-06-09 04:15:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetWebNavigation returns a list of bootstrap-vue <b-nav-item> links
|
|
|
|
// The parent <nav> is not included so each page may display it as
|
|
|
|
// best fits
|
|
|
|
func (b *bot) GetWebNavigation() []EndPoint {
|
|
|
|
endpoints := b.httpEndPoints
|
|
|
|
moreEndpoints := b.config.GetArray("bot.links", []string{})
|
|
|
|
for _, e := range moreEndpoints {
|
2019-06-09 04:54:05 +00:00
|
|
|
link := strings.SplitN(e, ":", 2)
|
2019-06-09 04:15:06 +00:00
|
|
|
if len(link) != 2 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
endpoints = append(endpoints, EndPoint{link[0], link[1]})
|
|
|
|
}
|
|
|
|
return endpoints
|
|
|
|
}
|