add installer alpha version

This commit is contained in:
2025-12-15 16:38:20 +07:00
parent 732e5aca11
commit b4ef76f0d0
23 changed files with 4279 additions and 136 deletions

View File

@@ -36,6 +36,10 @@ func (a *App) handleListPools(w http.ResponseWriter, r *http.Request) {
writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
return
}
// Ensure we always return an array, not null
if pools == nil {
pools = []models.Pool{}
}
writeJSON(w, http.StatusOK, pools)
}
@@ -215,6 +219,10 @@ func (a *App) handleListDatasets(w http.ResponseWriter, r *http.Request) {
writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
return
}
// Ensure we always return an array, not null
if datasets == nil {
datasets = []models.Dataset{}
}
writeJSON(w, http.StatusOK, datasets)
}
@@ -398,6 +406,10 @@ func (a *App) handleListSnapshots(w http.ResponseWriter, r *http.Request) {
writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
return
}
// Ensure we always return an array, not null
if snapshots == nil {
snapshots = []models.Snapshot{}
}
writeJSON(w, http.StatusOK, snapshots)
}
@@ -485,6 +497,10 @@ func (a *App) handleListSnapshotPolicies(w http.ResponseWriter, r *http.Request)
} else {
policies = a.snapshotPolicy.List()
}
// Ensure we always return an array, not null
if policies == nil {
policies = []models.SnapshotPolicy{}
}
writeJSON(w, http.StatusOK, policies)
}
@@ -1322,6 +1338,10 @@ func (a *App) handleCreateUser(w http.ResponseWriter, r *http.Request) {
req.Role = models.RoleViewer // Default role
}
// Normalize role to lowercase for comparison
roleStr := strings.ToLower(string(req.Role))
req.Role = models.Role(roleStr)
// Validate role
if req.Role != models.RoleAdministrator && req.Role != models.RoleOperator && req.Role != models.RoleViewer {
writeJSON(w, http.StatusBadRequest, map[string]string{"error": "invalid role"})
@@ -1376,6 +1396,12 @@ func (a *App) handleUpdateUser(w http.ResponseWriter, r *http.Request) {
return
}
// Normalize role to lowercase if provided
if req.Role != "" {
roleStr := strings.ToLower(string(req.Role))
req.Role = models.Role(roleStr)
}
// Validate role if provided
if req.Role != "" && req.Role != models.RoleAdministrator && req.Role != models.RoleOperator && req.Role != models.RoleViewer {
writeJSON(w, http.StatusBadRequest, map[string]string{"error": "invalid role"})