Rename previous config fields in agent API

This commit is contained in:
tian 2026-04-19 14:46:19 +08:00
parent 1742283989
commit e9a720a898
3 changed files with 17 additions and 14 deletions

View File

@ -94,8 +94,11 @@ func TestHandleConfigStatusReportsMetadataHashAndMediaStatus(t *testing.T) {
if !ok || media["running"] != true || media["pid"] != float64(1234) {
t.Fatalf("media_server = %#v", got["media_server"])
}
lastGood, ok := got["last_good"].(map[string]any)
if !ok || lastGood["exists"] != true {
t.Fatalf("last_good = %#v", got["last_good"])
previousConfig, ok := got["previous_config"].(map[string]any)
if !ok || previousConfig["exists"] != true {
t.Fatalf("previous_config = %#v", got["previous_config"])
}
if got["previous_config_path"] != filepath.ToSlash(cfgPath+".last_good.json") {
t.Fatalf("previous_config_path = %#v", got["previous_config_path"])
}
}

View File

@ -201,13 +201,13 @@ func (s *Server) configStatusPayload() map[string]any {
candidate := readConfigFileStatus(candidatePath)
resp := map[string]any{
"ok": true,
"config_path": filepath.ToSlash(s.agentCfg.ConfigPath),
"exists": current.Exists,
"last_good_path": filepath.ToSlash(lastGoodPath),
"last_good": lastGood,
"candidate_path": filepath.ToSlash(candidatePath),
"candidate": candidate,
"ok": true,
"config_path": filepath.ToSlash(s.agentCfg.ConfigPath),
"exists": current.Exists,
"previous_config_path": filepath.ToSlash(lastGoodPath),
"previous_config": lastGood,
"candidate_path": filepath.ToSlash(candidatePath),
"candidate": candidate,
}
if current.Exists {
resp["size"] = current.Size

View File

@ -67,9 +67,9 @@ type InfoResponse struct {
BuildID string `json:"build_id"`
BuildType string `json:"build_type"`
GitSHA string `json:"git_sha"`
ConfigPath string `json:"config_path"`
LastGoodPath string `json:"last_good_path"`
UptimeSec int64 `json:"uptime_sec"`
ConfigPath string `json:"config_path"`
PreviousConfigPath string `json:"previous_config_path"`
UptimeSec int64 `json:"uptime_sec"`
}
func New(agentCfg config.AgentConfig, baseDir string, ms *mediaserver.Client, store *modelstore.Store, deviceID string, agentPort int, mediaPort int, version, buildID, buildType, gitSHA string) *Server {
@ -165,7 +165,7 @@ func (s *Server) handleInfo(w http.ResponseWriter, r *http.Request) {
BuildType: s.buildType,
GitSHA: s.gitSHA,
ConfigPath: s.agentCfg.ConfigPath,
LastGoodPath: s.agentCfg.ConfigPath + ".last_good.json",
PreviousConfigPath: s.agentCfg.ConfigPath + ".last_good.json",
UptimeSec: sysinfo.UptimeSec(),
}
writeJSON(w, http.StatusOK, resp)