mirror of
https://github.com/gmemstr/pogo.git
synced 2024-09-20 01:31:09 +01:00
51 lines
1.1 KiB
Go
51 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"net/http"
|
|
"encoding/json"
|
|
"strings"
|
|
)
|
|
|
|
type NewConfig struct {
|
|
Name string
|
|
Host string
|
|
Email string
|
|
Description string
|
|
Image string
|
|
PodcastUrl string
|
|
}
|
|
|
|
// Serve setup.html and config parameters
|
|
func ServeSetup(w http.ResponseWriter, r *http.Request) {
|
|
if r.Method == "GET" {
|
|
data, err := ioutil.ReadFile("assets/web/setup.html")
|
|
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
w.Write(data)
|
|
}
|
|
if r.Method == "POST" {
|
|
r.ParseMultipartForm(32 << 20)
|
|
|
|
// 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
|
|
}
|
|
|
|
b, err := json.Marshal(cnf)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
ioutil.WriteFile("assets/config/config.json", b, 0644)
|
|
w.Write([]byte("Done"))
|
|
}
|
|
}
|