2017-09-21 20:10:59 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2017-09-21 23:10:16 +01:00
|
|
|
"io/ioutil"
|
|
|
|
"net/http"
|
2017-09-22 16:50:03 +01:00
|
|
|
// "fmt"
|
|
|
|
"encoding/json"
|
|
|
|
"strings"
|
2017-09-21 20:10:59 +01:00
|
|
|
)
|
|
|
|
|
2017-09-22 16:50:03 +01:00
|
|
|
type NewConfig struct {
|
|
|
|
Name string
|
|
|
|
Host string
|
|
|
|
Email string
|
|
|
|
Description string
|
|
|
|
Image string
|
|
|
|
PodcastUrl string
|
|
|
|
}
|
|
|
|
|
2017-09-21 20:10:59 +01:00
|
|
|
// Serve setup.html and config parameters
|
|
|
|
func ServeSetup(w http.ResponseWriter, r *http.Request) {
|
2017-09-21 23:10:16 +01:00
|
|
|
if r.Method == "GET" {
|
|
|
|
data, err := ioutil.ReadFile("assets/setup.html")
|
2017-09-21 20:10:59 +01:00
|
|
|
|
2017-09-21 23:10:16 +01:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
w.Write(data)
|
|
|
|
}
|
|
|
|
if r.Method == "POST" {
|
2017-09-22 16:50:03 +01:00
|
|
|
r.ParseMultipartForm(32 << 20)
|
2017-09-21 20:10:59 +01:00
|
|
|
|
2017-09-22 16:50:03 +01:00
|
|
|
// Parse form and convert to JSON
|
|
|
|
cnf := NewConfig{
|
|
|
|
strings.Join(r.Form["podcastname"], ""), // Podcast name
|
|
|
|
strings.Join(r.Form["podcasthost"], ""), // Podcast host
|
|
|
|
strings.Join(r.Form["podcastemail"], ""), // Podcast host email
|
|
|
|
strings.Join(r.Form["podcastdescription"], ""), // Podcast Description
|
|
|
|
"", // Podcast image
|
|
|
|
"", // Podcast location
|
|
|
|
}
|
2017-09-21 20:10:59 +01:00
|
|
|
|
2017-09-22 16:50:03 +01:00
|
|
|
b, err := json.Marshal(cnf)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2017-09-21 20:10:59 +01:00
|
|
|
|
2017-09-22 16:50:03 +01:00
|
|
|
ioutil.WriteFile("config.json", b, 0644)
|
|
|
|
w.Write([]byte("Done"))
|
|
|
|
}
|
2017-09-21 20:10:59 +01:00
|
|
|
}
|