diff --git a/dau.go b/dau.go index cf77c7a..7e89a40 100644 --- a/dau.go +++ b/dau.go @@ -66,6 +66,7 @@ func main() { log.Fatal("could not watch path", err) } lastCheck = newLastCheck + log.Print("sleeping before next check"); time.Sleep(time.Duration(config.watch) * time.Second) } } @@ -235,6 +236,7 @@ func processFile(config Config, file string) { var retriesRemaining = 5 for retriesRemaining > 0 { + request, err := newfileUploadRequest(config.webhookURL, extraParams, "file", file) if err != nil { log.Fatal(err) @@ -251,6 +253,9 @@ func processFile(config Config, file string) { if resp.StatusCode != 200 { log.Print("Bad response from server:", resp.StatusCode) + if b, err := ioutil.ReadAll(resp.Body); err == nil { + log.Print("Body:", string(b)) + } retriesRemaining-- sleepForRetries(retriesRemaining) continue diff --git a/web/server.go b/web/server.go index 64cde95..65ae2d7 100644 --- a/web/server.go +++ b/web/server.go @@ -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)