Continue web server integration
This commit is contained in:
parent
14f8fe1933
commit
a4f958f846
5
dau.go
5
dau.go
@ -66,6 +66,7 @@ func main() {
|
|||||||
log.Fatal("could not watch path", err)
|
log.Fatal("could not watch path", err)
|
||||||
}
|
}
|
||||||
lastCheck = newLastCheck
|
lastCheck = newLastCheck
|
||||||
|
log.Print("sleeping before next check");
|
||||||
time.Sleep(time.Duration(config.watch) * time.Second)
|
time.Sleep(time.Duration(config.watch) * time.Second)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -235,6 +236,7 @@ func processFile(config Config, file string) {
|
|||||||
|
|
||||||
var retriesRemaining = 5
|
var retriesRemaining = 5
|
||||||
for retriesRemaining > 0 {
|
for retriesRemaining > 0 {
|
||||||
|
|
||||||
request, err := newfileUploadRequest(config.webhookURL, extraParams, "file", file)
|
request, err := newfileUploadRequest(config.webhookURL, extraParams, "file", file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
@ -251,6 +253,9 @@ func processFile(config Config, file string) {
|
|||||||
|
|
||||||
if resp.StatusCode != 200 {
|
if resp.StatusCode != 200 {
|
||||||
log.Print("Bad response from server:", resp.StatusCode)
|
log.Print("Bad response from server:", resp.StatusCode)
|
||||||
|
if b, err := ioutil.ReadAll(resp.Body); err == nil {
|
||||||
|
log.Print("Body:", string(b))
|
||||||
|
}
|
||||||
retriesRemaining--
|
retriesRemaining--
|
||||||
sleepForRetries(retriesRemaining)
|
sleepForRetries(retriesRemaining)
|
||||||
continue
|
continue
|
||||||
|
@ -6,6 +6,8 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"github.com/tardisx/discord-auto-upload/assets"
|
"github.com/tardisx/discord-auto-upload/assets"
|
||||||
|
// "strings"
|
||||||
|
"regexp"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DAUWebServer - stuff for the web server
|
// DAUWebServer - stuff for the web server
|
||||||
@ -30,8 +32,16 @@ var wsConfig DAUWebServer
|
|||||||
// fmt.Println("val:", strings.Join(v, ""))
|
// fmt.Println("val:", strings.Join(v, ""))
|
||||||
// }
|
// }
|
||||||
|
|
||||||
func getIndex(w http.ResponseWriter, r *http.Request) {
|
func getStatic(w http.ResponseWriter, r *http.Request) {
|
||||||
data, err := assets.Asset("index.html")
|
// 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 {
|
if err != nil {
|
||||||
// Asset was not found.
|
// Asset was not found.
|
||||||
fmt.Fprintln(w, err)
|
fmt.Fprintln(w, err)
|
||||||
@ -51,6 +61,7 @@ func getSetWebhook(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
w.Write(js)
|
w.Write(js)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getSetDirectory(w http.ResponseWriter, r *http.Request) {
|
func getSetDirectory(w http.ResponseWriter, r *http.Request) {
|
||||||
@ -64,8 +75,7 @@ func Init() DAUWebServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func startWebServer() {
|
func startWebServer() {
|
||||||
|
http.HandleFunc("/", getStatic)
|
||||||
http.HandleFunc("/", getIndex)
|
|
||||||
http.HandleFunc("/rest/config/webhook", getSetWebhook)
|
http.HandleFunc("/rest/config/webhook", getSetWebhook)
|
||||||
http.HandleFunc("/rest/config/directory", getSetDirectory)
|
http.HandleFunc("/rest/config/directory", getSetDirectory)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user