diff --git a/bot/index.html b/bot/index.html
new file mode 100644
index 0000000..213c142
--- /dev/null
+++ b/bot/index.html
@@ -0,0 +1,47 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ catbase
+
+
+
+
+
+ catbase
+
+ {{ item.name }}
+
+
+
+
+
+
+
diff --git a/bot/web.go b/bot/web.go
index 2d02145..e32aa23 100644
--- a/bot/web.go
+++ b/bot/web.go
@@ -1,14 +1,18 @@
package bot
import (
+ "embed"
"encoding/json"
- "fmt"
"net/http"
"strings"
)
+//go:embed *.html
+var embeddedFS embed.FS
+
func (b *bot) serveRoot(w http.ResponseWriter, r *http.Request) {
- fmt.Fprint(w, rootIndex)
+ index, _ := embeddedFS.ReadFile("index.html")
+ w.Write(index)
}
func (b *bot) serveNav(w http.ResponseWriter, r *http.Request) {
@@ -36,53 +40,3 @@ func (b *bot) GetWebNavigation() []EndPoint {
}
return endpoints
}
-
-var rootIndex = `
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- catbase
-
-
-
-
-
- catbase
-
- {{ item.name }}
-
-
-
-
-
-
-
-`
diff --git a/go.mod b/go.mod
index 933be0c..f9c5613 100644
--- a/go.mod
+++ b/go.mod
@@ -1,6 +1,6 @@
module github.com/velour/catbase
-go 1.13
+go 1.16
require (
code.chrissexton.org/cws/getaoc v0.0.0-20191201043947-d5417d4b618d
diff --git a/plugins/admin/apppass.html b/plugins/admin/apppass.html
new file mode 100644
index 0000000..77ecc59
--- /dev/null
+++ b/plugins/admin/apppass.html
@@ -0,0 +1,160 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Vars
+
+
+
+
+
+ App Pass
+
+ {{ item.name }}
+
+
+
+
+
+ ×
+
+ {{ err }}
+
+
+
+
+ Password:
+
+
+
+
+
+ Secret:
+
+
+
+
+
+
+ List
+
+
+ New
+
+
+
+
+
+
+ ID:
+ {{ entry.id }}
+
+
+ Password:
+ {{ entry.secret }}:{{ showPassword }}
+
+
+ Note: this password will only be displayed once. For
+ single-field entry passwords, use the secret:password format.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/plugins/admin/index.go b/plugins/admin/index.go
deleted file mode 100644
index 752d069..0000000
--- a/plugins/admin/index.go
+++ /dev/null
@@ -1,241 +0,0 @@
-package admin
-
-var varIndex = `
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Vars
-
-
-
-
-
- Variables
-
- {{ item.name }}
-
-
-
- {{ err }}
-
-
-
-
-
-
-
-
-
-`
-
-var apppassIndex = `
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-Vars
-
-
-
-
-
-App Pass
-
-{{ item.name }}
-
-
-
-
-
-×
-
-{{ err }}
-
-
-
-
-Password:
-
-
-
-
-
-Secret:
-
-
-
-
-
-
-List
-
-
-New
-
-
-
-
-
-
-ID:
-{{ entry.id }}
-
-
-Password:
-{{ entry.secret }}:{{ showPassword }}
-
-
-Note: this password will only be displayed once. For single-field entry passwords, use the secret:password format.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-`
diff --git a/plugins/admin/vars.html b/plugins/admin/vars.html
new file mode 100644
index 0000000..5b5346e
--- /dev/null
+++ b/plugins/admin/vars.html
@@ -0,0 +1,77 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Vars
+
+
+
+
+
+ Variables
+
+ {{ item.name }}
+
+
+
+
+ {{ err }}
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/plugins/admin/web.go b/plugins/admin/web.go
index 00d8c50..b20f143 100644
--- a/plugins/admin/web.go
+++ b/plugins/admin/web.go
@@ -3,6 +3,7 @@ package admin
import (
"crypto/md5"
"crypto/rand"
+ "embed"
"encoding/json"
"fmt"
"io/ioutil"
@@ -14,6 +15,9 @@ import (
"golang.org/x/crypto/bcrypt"
)
+//go:embed *.html
+var embeddedFS embed.FS
+
func (p *AdminPlugin) registerWeb() {
r := chi.NewRouter()
r.HandleFunc("/api", p.handleVarsAPI)
@@ -27,7 +31,8 @@ func (p *AdminPlugin) registerWeb() {
}
func (p *AdminPlugin) handleAppPass(w http.ResponseWriter, r *http.Request) {
- fmt.Fprint(w, apppassIndex)
+ index, _ := embeddedFS.ReadFile("apppass.html")
+ w.Write(index)
}
type PassEntry struct {
@@ -162,7 +167,8 @@ func writeErr(w http.ResponseWriter, err error) {
}
func (p *AdminPlugin) handleVars(w http.ResponseWriter, r *http.Request) {
- fmt.Fprint(w, varIndex)
+ index, _ := embeddedFS.ReadFile("vars.html")
+ w.Write(index)
}
func (p *AdminPlugin) handleVarsAPI(w http.ResponseWriter, r *http.Request) {
diff --git a/plugins/cli/cli.go b/plugins/cli/cli.go
index 7d98216..3e387a8 100644
--- a/plugins/cli/cli.go
+++ b/plugins/cli/cli.go
@@ -3,6 +3,7 @@
package cli
import (
+ "embed"
"encoding/json"
"fmt"
"net/http"
@@ -17,6 +18,9 @@ import (
"github.com/velour/catbase/bot/user"
)
+//go:embed *.html
+var embeddedFS embed.FS
+
type CliPlugin struct {
bot bot.Bot
db *sqlx.DB
@@ -97,7 +101,8 @@ func (p *CliPlugin) handleWebAPI(w http.ResponseWriter, r *http.Request) {
}
func (p *CliPlugin) handleWeb(w http.ResponseWriter, r *http.Request) {
- fmt.Fprint(w, indexHTML)
+ index, _ := embeddedFS.ReadFile("index.html")
+ w.Write(index)
}
// Completing the Connector interface, but will not actually be a connector
diff --git a/plugins/cli/index.go b/plugins/cli/index.go
deleted file mode 100644
index be228bc..0000000
--- a/plugins/cli/index.go
+++ /dev/null
@@ -1,136 +0,0 @@
-package cli
-
-var indexHTML = `
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- CLI
-
-
-
-
-
- CLI
-
- {{ item.name }}
-
-
-
- {{ err }}
-
-
-
- Password:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Send
-
-
-
-
-
-
-
-
-
-`
diff --git a/plugins/cli/index.html b/plugins/cli/index.html
new file mode 100644
index 0000000..27a7bf5
--- /dev/null
+++ b/plugins/cli/index.html
@@ -0,0 +1,132 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ CLI
+
+
+
+
+
+ CLI
+
+ {{ item.name }}
+
+
+
+ {{ err }}
+
+
+
+ Password:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Send
+
+
+
+
+
+
+
+
+
diff --git a/plugins/counter/api.go b/plugins/counter/api.go
index d5ef074..3c8fff1 100644
--- a/plugins/counter/api.go
+++ b/plugins/counter/api.go
@@ -1,6 +1,7 @@
package counter
import (
+ "embed"
"encoding/json"
"fmt"
"net/http"
@@ -12,6 +13,9 @@ import (
"github.com/velour/catbase/bot/msg"
)
+//go:embed *.html
+var embeddedFS embed.FS
+
func (p *CounterPlugin) registerWeb() {
r := chi.NewRouter()
r.HandleFunc("/api/users/{user}/items/{item}/increment", p.mkIncrementAPI(1))
@@ -89,7 +93,8 @@ func (p *CounterPlugin) mkIncrementAPI(delta int) func(w http.ResponseWriter, r
}
func (p *CounterPlugin) handleCounter(w http.ResponseWriter, r *http.Request) {
- fmt.Fprint(w, html)
+ index, _ := embeddedFS.ReadFile("index.html")
+ w.Write(index)
}
func (p *CounterPlugin) handleCounterAPI(w http.ResponseWriter, r *http.Request) {
diff --git a/plugins/counter/html.go b/plugins/counter/html.go
deleted file mode 100644
index f2de8d6..0000000
--- a/plugins/counter/html.go
+++ /dev/null
@@ -1,108 +0,0 @@
-package counter
-
-var html = `
-
-
-
-
-
-
-
-
-
-
-
-
-
- Counters
-
-
-
-
-
- Counters
-
- {{ item.name }}
-
-
-
- {{ err }}
-
-
-
- Password:
-
-
-
- {{ user }}:
-
-
-
- {{ thing }}:
-
-
- {{ count }}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-`
diff --git a/plugins/counter/index.html b/plugins/counter/index.html
new file mode 100644
index 0000000..271466b
--- /dev/null
+++ b/plugins/counter/index.html
@@ -0,0 +1,104 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Counters
+
+
+
+
+
+ Counters
+
+ {{ item.name }}
+
+
+
+ {{ err }}
+
+
+
+ Password:
+
+
+
+ {{ user }}:
+
+
+
+ {{ thing }}:
+
+
+ {{ count }}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/plugins/fact/factoid.go b/plugins/fact/factoid.go
index 9b493f7..e54b27a 100644
--- a/plugins/fact/factoid.go
+++ b/plugins/fact/factoid.go
@@ -4,6 +4,7 @@ package fact
import (
"database/sql"
+ "embed"
"encoding/json"
"fmt"
"html/template"
@@ -26,6 +27,9 @@ import (
// The factoid plugin provides a learning system to the bot so that it can
// respond to queries in a way that is unpredictable and fun
+//go:embed *.html
+var embeddedFS embed.FS
+
// factoid stores info about our factoid for lookup and later interaction
type Factoid struct {
ID sql.NullInt64
@@ -851,5 +855,6 @@ func (p *FactoidPlugin) serveAPI(w http.ResponseWriter, r *http.Request) {
}
func (p *FactoidPlugin) serveQuery(w http.ResponseWriter, r *http.Request) {
- fmt.Fprint(w, factoidIndex)
+ index, _ := embeddedFS.ReadFile("index.html")
+ w.Write(index)
}
diff --git a/plugins/fact/webTemplates.go b/plugins/fact/index.html
similarity index 90%
rename from plugins/fact/webTemplates.go
rename to plugins/fact/index.html
index fd75fb5..9e5a1f7 100644
--- a/plugins/fact/webTemplates.go
+++ b/plugins/fact/index.html
@@ -1,13 +1,3 @@
-// © 2013 the CatBase Authors under the WTFPL. See AUTHORS for the list of authors.
-
-package fact
-
-// I hate this, but I'm creating strings of the templates to avoid having to
-// track where templates reside.
-
-// 2016-01-15 Later note, why are these in plugins and the server is in bot?
-
-var factoidIndex = `
@@ -116,5 +106,4 @@ var factoidIndex = `
})
-
-`
+