CI / test (push) Successful in 5m35s
The errors other packages give a page (store, catalog, mirror) are shown in its language; a percentage is written as the language writes it (%93 in Turkish); the footer's time in its date form; and a stale form is refused with a sentence rather than "bad request". Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
60 lines
2.2 KiB
Go
60 lines
2.2 KiB
Go
package web
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"net/url"
|
|
|
|
"gitea.mynodes.xyz/ilker/llmgw/internal/store"
|
|
)
|
|
|
|
// NodeEngineAdmin chooses an engine's build for a node: "auto", a build
|
|
// such as "cu129", or "none".
|
|
type NodeEngineAdmin interface {
|
|
SetNodeEngine(ctx context.Context, node, engine, build, by string) error
|
|
}
|
|
|
|
// RegisterNodeEngines mounts the choice of engine builds on the cluster
|
|
// page: for an administrator, with the session's CSRF token, and answered by
|
|
// going back to the page with what happened.
|
|
func (p *AccountPages) RegisterNodeEngines(mux *http.ServeMux, a NodeEngineAdmin) {
|
|
mux.HandleFunc("POST /admin/nodes/{id}/engines", p.adminOnly(func(w http.ResponseWriter, r *http.Request, admin store.User) {
|
|
sess, _, _ := p.session(r)
|
|
if !p.accounts.CheckCSRF(sess, r.FormValue("csrf")) {
|
|
badForm(w, r)
|
|
return
|
|
}
|
|
node, engine, build := r.PathValue("id"), r.FormValue("engine"), r.FormValue("build")
|
|
q := url.Values{}
|
|
if err := a.SetNodeEngine(r.Context(), node, engine, build, admin.Email); err != nil {
|
|
p.log.Warn("an engine build was not chosen", "admin", admin.Email, "node", node, "err", err)
|
|
// The control plane's reason, in the page's language where it
|
|
// is one the pages know, else as it gave it.
|
|
q.Set("problem", node+": "+langOf(r).Err(err))
|
|
} else {
|
|
p.log.Info("an engine build was chosen", "admin", admin.Email, "node", node, "engine", engine, "build", build)
|
|
// Said in the language of the person who chose, since the
|
|
// sentence travels to the page in the address.
|
|
q.Set("notice", buildNotice(langOf(r), node, engine, build))
|
|
}
|
|
http.Redirect(w, r, "/admin?"+q.Encode(), http.StatusSeeOther)
|
|
}))
|
|
}
|
|
|
|
// buildNotice says what a node was told to install. A whole sentence for
|
|
// each kind of choice, because where the build goes in it is the
|
|
// language's business.
|
|
func buildNotice(l *Lang, node, engine, build string) string {
|
|
switch build {
|
|
case "auto":
|
|
return l.T("nodeengine.notice.auto", node, engine)
|
|
case "none":
|
|
return l.T("nodeengine.notice.none", node, engine)
|
|
}
|
|
name := map[string]string{"cu13": "CUDA 13", "cu129": "CUDA 12.9", "cu126": "CUDA 12.6", "cu12": "CUDA 12"}[build]
|
|
if name == "" {
|
|
name = build
|
|
}
|
|
return l.T("nodeengine.notice.build", node, engine, name)
|
|
}
|