feat: send firmware update through ws
This commit is contained in:
@@ -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))
|
||||
}()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user