41 lines
1.1 KiB
Go
Executable File
41 lines
1.1 KiB
Go
Executable File
package server
|
|
|
|
import (
|
|
"encoding/json"
|
|
"gitea.inhome.blapointe.com/local/firestormy/config"
|
|
"gitea.inhome.blapointe.com/local/firestormy/config/ns"
|
|
"gitea.inhome.blapointe.com/local/firestormy/scheduler"
|
|
"gitea.inhome.blapointe.com/local/logb"
|
|
"net/http"
|
|
"sort"
|
|
)
|
|
|
|
func (s *Server) list(w http.ResponseWriter, r *http.Request) {
|
|
logb.Debugf("[access] list %s", r.URL.Path)
|
|
jobs, err := config.Store.List(ns.Jobs)
|
|
logb.Debugf("[access] list : %v: %+v", err, jobs)
|
|
if err != nil {
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
return
|
|
}
|
|
out := make([]map[string]interface{}, len(jobs))
|
|
for i, job := range jobs {
|
|
out[i] = make(map[string]interface{})
|
|
b, err := config.Store.Get(job, ns.Jobs...)
|
|
if err != nil {
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
return
|
|
}
|
|
j := &scheduler.Job{}
|
|
if err := j.Decode(b); err != nil {
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
return
|
|
}
|
|
out[i] = toMap(j, false)
|
|
}
|
|
sort.Slice(out, func(i, j int) bool {
|
|
return out[i]["title"].(string) < out[j]["title"].(string)
|
|
})
|
|
json.NewEncoder(w).Encode(out)
|
|
}
|