package web
import (
"net/http"
"net/url"
"craftdesign.group/quarry/internal/ops"
)
// fossilMirrorPanel is the Mirror to Fossil section as the page draws
// it. The password is not on it, and the form never pre-fills one.
type fossilMirrorPanel struct {
On bool `json:"on"`
Remote string `json:"remote"`
User string `json:"user"`
Pushed string `json:"pushed"`
PushedAt string `json:"pushed_at"`
LastErr string `json:"error"`
LastErrAt string `json:"error_at"`
Paused string `json:"paused"`
// Err is this section's own refusal, back from its POST.
Err string `json:"-"`
}
// fossilMirrorPanelFor reads the mirror through `repo.fossilmirror.get`,
// the op the API serves. nil, so no section, when the forge keeps no
// mirrors.
func fossilMirrorPanelFor(r *ops.Registry, req *http.Request, repo string) *fossilMirrorPanel {
out, err := invoke(req.Context(), r, "repo.fossilmirror.get", url.Values{"repo": {repo}})
if err != nil {
return nil
}
var p fossilMirrorPanel
remarshal(out, &p)
p.Err = req.URL.Query().Get("fme")
if !p.On {
// A refused first enable keeps what was typed, bar the
// password, so the admin fixes the address rather than typing
// it again.
p.Remote, p.User = req.URL.Query().Get("fremote"), req.URL.Query().Get("fuser")
}
return &p
}