fix(pve): GetAll返回空数组而非nil,防止前端列表为空时崩溃 [砚砚/K2.6🐾]

This commit is contained in:
openclaw
2026-04-23 01:00:47 +08:00
parent 0cbc46cb62
commit 35f4f48424
2 changed files with 4 additions and 4 deletions

View File

@@ -93,7 +93,7 @@ func (h *ExportHandler) Import(c *gin.Context) {
}
if raw, ok := data["machines"]; ok {
var list []models.Machine
list := []models.Machine{}
if err := json.Unmarshal(raw, &list); err == nil {
for _, m := range list {
_, _ = db.DB.Exec(`INSERT OR IGNORE INTO machines (id, hostname, ip, mac, os_type, os_version, notes, ssh_port, ssh_username, ssh_password, is_online, cpu_info, memory_info, disk_info, uptime, listen_ports) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
@@ -103,7 +103,7 @@ func (h *ExportHandler) Import(c *gin.Context) {
}
if raw, ok := data["services"]; ok {
var list []models.Service
list := []models.Service{}
if err := json.Unmarshal(raw, &list); err == nil {
for _, s := range list {
_, _ = db.DB.Exec(`INSERT OR IGNORE INTO services (id, machine_id, name, port, protocol, notes, target_machine_id, target_notes) VALUES (?, ?, ?, ?, ?, ?, ?, ?)`,
@@ -113,7 +113,7 @@ func (h *ExportHandler) Import(c *gin.Context) {
}
if raw, ok := data["relationships"]; ok {
var list []models.Relationship
list := []models.Relationship{}
if err := json.Unmarshal(raw, &list); err == nil {
for _, r := range list {
_, _ = db.DB.Exec(`INSERT OR IGNORE INTO relationships (id, source_machine_id, target_machine_id, relation_type, source_port, target_port, notes) VALUES (?, ?, ?, ?, ?, ?, ?)`,

View File

@@ -324,7 +324,7 @@ func (s *PVEHostService) GetAll() ([]models.PVEHost, error) {
}
defer rows.Close()
var hosts []models.PVEHost
hosts := []models.PVEHost{}
for rows.Next() {
var h models.PVEHost
var verifySSL int