feat: send firmware update through ws

This commit is contained in:
2025-10-21 13:15:15 +02:00
parent 3098e2166b
commit 9435af0137
5 changed files with 269 additions and 0 deletions

View File

@@ -538,6 +538,9 @@ func (hs *HTTPServer) updateNodeFirmware(w http.ResponseWriter, r *http.Request)
"file_size": len(fileData),
}).Info("Firmware upload received")
// Broadcast firmware upload status to WebSocket clients
hs.webSocketServer.BroadcastFirmwareUploadStatus(nodeIP, "uploading", filename, len(fileData))
// Send immediate acknowledgment to client
response := struct {
Success bool `json:"success"`
@@ -591,6 +594,9 @@ func (hs *HTTPServer) updateNodeFirmware(w http.ResponseWriter, r *http.Request)
"node_ip": nodeIP,
"error": err.Error(),
}).Error("Error uploading firmware to device")
// Broadcast failure status to WebSocket clients
hs.webSocketServer.BroadcastFirmwareUploadStatus(nodeIP, "failed", filename, len(fileData))
return
}
@@ -600,6 +606,9 @@ func (hs *HTTPServer) updateNodeFirmware(w http.ResponseWriter, r *http.Request)
"node_ip": nodeIP,
"message": result.Message,
}).Error("Device reported firmware update failure")
// Broadcast failure status to WebSocket clients
hs.webSocketServer.BroadcastFirmwareUploadStatus(nodeIP, "failed", filename, len(fileData))
return
}
@@ -609,6 +618,9 @@ func (hs *HTTPServer) updateNodeFirmware(w http.ResponseWriter, r *http.Request)
"filename": filename,
"result": result.Status,
}).Info("Firmware upload completed successfully")
// Broadcast success status to WebSocket clients
hs.webSocketServer.BroadcastFirmwareUploadStatus(nodeIP, "completed", filename, len(fileData))
}()
}