implement enable disable with client side display and mod

This commit is contained in:
bel
2020-03-16 02:10:31 +00:00
parent 89822b7012
commit a8e50d3ce4
6 changed files with 119 additions and 6 deletions

40
server/able.go Normal file
View File

@@ -0,0 +1,40 @@
package server
import (
"local/firestormy/config"
"local/firestormy/config/ns"
"local/firestormy/scheduler"
"net/http"
"strings"
)
func (s *Server) disable(w http.ResponseWriter, r *http.Request) {
s.setDisabled(w, r, true)
}
func (s *Server) enable(w http.ResponseWriter, r *http.Request) {
s.setDisabled(w, r, false)
}
func (s *Server) setDisabled(w http.ResponseWriter, r *http.Request, disabled bool) {
keys := strings.Split(r.URL.Path, "/")
key := keys[len(keys)-1]
j := &scheduler.Job{}
b, err := config.Store.Get(key, ns.Jobs...)
if err != nil {
http.Error(w, err.Error(), http.StatusNotFound)
return
}
if err := j.Decode(b); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
j.Disabled = disabled
if err := scheduler.Schedule.Update(j); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.Write([]byte("{}"))
}