diff --git a/config/config.go b/config/config.go index 832d164..816977a 100644 --- a/config/config.go +++ b/config/config.go @@ -7,27 +7,27 @@ import ( ) type Server struct { - Port int `yaml:"port"` - Address string `yaml:"address"` - DownloadPath string `yaml:"download_path"` + Port int `yaml:"port" json:"port"` + Address string `yaml:"address" json:"address"` + DownloadPath string `yaml:"download_path" json:"download_path"` } type DownloadProfile struct { - Name string `yaml:"name"` - Command string `yaml:"command"` - Args []string `yaml:"args"` + Name string `yaml:"name" json:"name"` + Command string `yaml:"command" json:"command"` + Args []string `yaml:"args" json:"args"` } type UI struct { - PopupWidth int `yaml:"popup_width"` - PopupHeight int `yaml:"popup_height"` + PopupWidth int `yaml:"popup_width" json:"popup_width"` + PopupHeight int `yaml:"popup_height" json:"popup_height"` } type Config struct { - Server Server `yaml:"server"` - UI UI `yaml:"ui"` - DownloadProfiles []DownloadProfile `yaml:"profiles"` - ConfigVersion int `yaml:"config_version"` + Server Server `yaml:"server" json:"server"` + UI UI `yaml:"ui" json:"ui"` + DownloadProfiles []DownloadProfile `yaml:"profiles" json:"profiles"` + ConfigVersion int `yaml:"config_version" json:"config_version"` } func DefaultConfig() Config { @@ -41,11 +41,14 @@ func DefaultConfig() Config { defaultConfig.DownloadProfiles = append(defaultConfig.DownloadProfiles, stdProfile) defaultConfig.Server.Port = 6123 - defaultConfig.Server.Address = "localhost:6123" + defaultConfig.Server.Address = "http://localhost:6123" defaultConfig.Server.DownloadPath = "./" + defaultConfig.UI.PopupWidth = 500 defaultConfig.UI.PopupHeight = 500 + defaultConfig.ConfigVersion = 1 + return defaultConfig } diff --git a/main.go b/main.go index 03b0620..ba9a150 100644 --- a/main.go +++ b/main.go @@ -37,7 +37,7 @@ type download struct { var downloads []*download var downloadId = 0 -var versionInfo = version.Info{CurrentVersion: "v0.4.0"} +var versionInfo = version.Info{CurrentVersion: "v0.5.0"} //go:embed web var webFS embed.FS @@ -49,10 +49,13 @@ func main() { r := mux.NewRouter() r.HandleFunc("/", HomeHandler) + r.HandleFunc("/config", ConfigHandler) r.HandleFunc("/fetch", FetchHandler) - r.HandleFunc("/fetch/info", FetchInfoHandler) - r.HandleFunc("/fetch/info/{id}", FetchInfoOneHandler) - r.HandleFunc("/version", VersionHandler) + + r.HandleFunc("/rest/fetch/info", FetchInfoHandler) + r.HandleFunc("/rest/fetch/info/{id}", FetchInfoOneHandler) + r.HandleFunc("/rest/version", VersionHandler) + r.HandleFunc("/rest/config", ConfigRESTHandler) http.Handle("/", r) @@ -113,6 +116,27 @@ func HomeHandler(w http.ResponseWriter, r *http.Request) { } +func ConfigHandler(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusOK) + + t, err := template.ParseFS(webFS, "web/layout.tmpl", "web/config.html") + if err != nil { + panic(err) + } + + err = t.ExecuteTemplate(w, "layout", nil) + if err != nil { + panic(err) + } +} + +func ConfigRESTHandler(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusOK) + + b, _ := json.Marshal(conf) + w.Write(b) +} + func FetchInfoOneHandler(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) idString := vars["id"] diff --git a/web/config.html b/web/config.html new file mode 100644 index 0000000..6fbdd07 --- /dev/null +++ b/web/config.html @@ -0,0 +1,92 @@ +{{ define "content" }} + + +
+ Upgrade is available - + you have + and + + is available.
+ +