2023-12-19 01:23:40 +00:00
|
|
|
package hapi
|
|
|
|
|
|
|
|
import (
|
|
|
|
"embed"
|
2024-03-25 15:35:54 +00:00
|
|
|
"text/template"
|
2023-12-19 01:23:40 +00:00
|
|
|
|
2023-12-19 15:12:45 +00:00
|
|
|
"github.com/gorilla/mux"
|
2023-12-19 01:23:40 +00:00
|
|
|
logging "github.com/ipfs/go-log/v2"
|
2023-12-19 15:12:45 +00:00
|
|
|
"golang.org/x/xerrors"
|
2023-12-19 01:23:40 +00:00
|
|
|
|
2024-03-25 15:35:54 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
2024-03-15 21:38:13 +00:00
|
|
|
"github.com/filecoin-project/lotus/cmd/curio/deps"
|
2023-12-19 01:23:40 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
//go:embed web/*
|
|
|
|
var templateFS embed.FS
|
|
|
|
|
|
|
|
func Routes(r *mux.Router, deps *deps.Deps) error {
|
2024-03-25 15:35:54 +00:00
|
|
|
t, err := makeTemplate().ParseFS(templateFS, "web/*")
|
2023-12-19 01:23:40 +00:00
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("parse templates: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
a := &app{
|
|
|
|
db: deps.DB,
|
|
|
|
t: t,
|
|
|
|
}
|
|
|
|
|
2024-01-12 13:09:12 +00:00
|
|
|
go a.watchRpc()
|
|
|
|
go a.watchActor()
|
|
|
|
|
2024-03-25 15:35:54 +00:00
|
|
|
// index page (simple info)
|
2023-12-19 01:23:40 +00:00
|
|
|
r.HandleFunc("/simpleinfo/actorsummary", a.actorSummary)
|
|
|
|
r.HandleFunc("/simpleinfo/machines", a.indexMachines)
|
|
|
|
r.HandleFunc("/simpleinfo/tasks", a.indexTasks)
|
|
|
|
r.HandleFunc("/simpleinfo/taskhistory", a.indexTasksHistory)
|
2024-01-12 15:16:35 +00:00
|
|
|
r.HandleFunc("/simpleinfo/pipeline-porep", a.indexPipelinePorep)
|
2024-02-11 17:50:37 +00:00
|
|
|
|
|
|
|
// pipeline-porep page
|
2024-03-25 15:35:54 +00:00
|
|
|
r.HandleFunc("/pipeline-porep/sectors", a.pipelinePorepSectors)
|
|
|
|
|
|
|
|
// node info page
|
|
|
|
r.HandleFunc("/node/{id}", a.nodeInfo)
|
2024-04-11 16:30:53 +00:00
|
|
|
|
|
|
|
// sector info page
|
|
|
|
r.HandleFunc("/sector/{sp}/{id}", a.sectorInfo)
|
2023-12-19 01:23:40 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-03-25 15:35:54 +00:00
|
|
|
func makeTemplate() *template.Template {
|
|
|
|
return template.New("").Funcs(template.FuncMap{
|
|
|
|
"toHumanBytes": func(b int64) string {
|
|
|
|
return types.SizeStr(types.NewInt(uint64(b)))
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-03-15 21:38:13 +00:00
|
|
|
var log = logging.Logger("curio/web")
|