implement enable disable with client side display and mod
This commit is contained in:
40
server/able.go
Normal file
40
server/able.go
Normal 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("{}"))
|
||||
}
|
||||
32
server/delete.go
Normal file
32
server/delete.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"local/firestormy/config"
|
||||
"local/firestormy/config/ns"
|
||||
"local/firestormy/scheduler"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func (s *Server) delete(w http.ResponseWriter, r *http.Request) {
|
||||
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
|
||||
}
|
||||
|
||||
if err := scheduler.Schedule.Remove(j); err != nil {
|
||||
if err := j.Decode(b); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
w.Write([]byte("{}"))
|
||||
}
|
||||
@@ -24,6 +24,18 @@ func (s *Server) Routes() error {
|
||||
path: fmt.Sprintf("/api/job/list"),
|
||||
handler: s.gzip(s.authenticate(s.list)),
|
||||
},
|
||||
{
|
||||
path: fmt.Sprintf("/api/job/delete/%s", router.Wildcard),
|
||||
handler: s.gzip(s.authenticate(s.delete)),
|
||||
},
|
||||
{
|
||||
path: fmt.Sprintf("/api/job/disable/%s", router.Wildcard),
|
||||
handler: s.gzip(s.authenticate(s.disable)),
|
||||
},
|
||||
{
|
||||
path: fmt.Sprintf("/api/job/enable/%s", router.Wildcard),
|
||||
handler: s.gzip(s.authenticate(s.enable)),
|
||||
},
|
||||
{
|
||||
path: fmt.Sprintf("%s%s", wildcard, wildcard),
|
||||
handler: s.gzip(s.authenticate(s.static)),
|
||||
|
||||
Reference in New Issue
Block a user