Continue web server integration
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user