Continue web server integration

This commit is contained in:
2020-03-26 11:40:35 +10:30
parent 14f8fe1933
commit a4f958f846
2 changed files with 19 additions and 4 deletions

View File

@@ -6,6 +6,8 @@ import (
"log"
"net/http"
"github.com/tardisx/discord-auto-upload/assets"
// "strings"
"regexp"
)
// DAUWebServer - stuff for the web server
@@ -30,8 +32,16 @@ var wsConfig DAUWebServer
// fmt.Println("val:", strings.Join(v, ""))
// }
func getIndex(w http.ResponseWriter, r *http.Request) {
data, err := assets.Asset("index.html")
func getStatic(w http.ResponseWriter, r *http.Request) {
// haha this is dumb and I should change it
fmt.Println(r.URL)
re := regexp.MustCompile(`[^a-zA-Z0-9\.]`)
path := r.URL.Path
sanitized_path := re.ReplaceAll([]byte(path), []byte("_"))
fmt.Println(sanitized_path)
data, err := assets.Asset(string(sanitized_path))
if err != nil {
// Asset was not found.
fmt.Fprintln(w, err)
@@ -51,6 +61,7 @@ func getSetWebhook(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.Write(js)
}
func getSetDirectory(w http.ResponseWriter, r *http.Request) {
@@ -64,8 +75,7 @@ func Init() DAUWebServer {
}
func startWebServer() {
http.HandleFunc("/", getIndex)
http.HandleFunc("/", getStatic)
http.HandleFunc("/rest/config/webhook", getSetWebhook)
http.HandleFunc("/rest/config/directory", getSetDirectory)