fix: activation via connexion WS principale, cascade delete student→nodes, lien fiche étudiant
- agent/websocket.go: expose sendMessage() + notifyUI() pour broadcaster les résultats d'activation à tous les clients UI connectés - agent/ui.go: supprime forwardActivation(), utilise sendMessage() sur la connexion WS principale au lieu d'une connexion temporaire - agent/activation.go: ajoute os.MkdirAll avant l'écriture d'activation.json - server/prisma/schema.prisma: onDelete Cascade sur Node→Student - server/app/dashboard/students/page.tsx: nom cliquable vers fiche détail - server/app/dashboard/students/[id]/actions.ts: deleteMany → delete
This commit is contained in:
+21
-28
@@ -29,13 +29,27 @@ func startUI(dataDir, nodeID, serverAddr string) {
|
||||
return
|
||||
}
|
||||
defer conn.Close()
|
||||
log.Printf("UI client connected from %s", r.RemoteAddr)
|
||||
|
||||
// Register notifier to forward activation results from main WS to this UI connection
|
||||
notifierID := registerUINotifier(func(msg map[string]interface{}) {
|
||||
log.Printf("UI notifier forwarding to browser: %+v", msg)
|
||||
if err := conn.WriteJSON(msg); err != nil {
|
||||
log.Printf("UI notify error: %v", err)
|
||||
} else {
|
||||
log.Printf("UI notifier sent successfully")
|
||||
}
|
||||
})
|
||||
defer unregisterUINotifier(notifierID)
|
||||
|
||||
for {
|
||||
var msg map[string]interface{}
|
||||
if err := conn.ReadJSON(&msg); err != nil {
|
||||
log.Printf("UI client disconnected: %v", err)
|
||||
break
|
||||
}
|
||||
action, _ := msg["action"].(string)
|
||||
log.Printf("UI received action: %s", action)
|
||||
switch action {
|
||||
case "check":
|
||||
act, err := loadActivation(dataDir)
|
||||
@@ -46,10 +60,13 @@ func startUI(dataDir, nodeID, serverAddr string) {
|
||||
}
|
||||
case "activate":
|
||||
code, _ := msg["code"].(string)
|
||||
// Forward to server WS
|
||||
go func() {
|
||||
forwardActivation(serverAddr, nodeID, code, conn)
|
||||
}()
|
||||
log.Printf("UI handling activate with code: %s", code)
|
||||
if err := sendMessage(WSMessage{Action: "activate", NodeID: nodeID, Code: code}); err != nil {
|
||||
log.Printf("UI sendMessage failed: %v", err)
|
||||
conn.WriteJSON(map[string]interface{}{"action": "activation_failed", "error": err.Error()})
|
||||
} else {
|
||||
log.Printf("UI sendMessage succeeded, waiting for server response...")
|
||||
}
|
||||
case "instances":
|
||||
listInstances(dataDir, conn)
|
||||
}
|
||||
@@ -63,30 +80,6 @@ func startUI(dataDir, nodeID, serverAddr string) {
|
||||
}
|
||||
}
|
||||
|
||||
func forwardActivation(serverAddr, nodeID, code string, uiConn *websocket.Conn) {
|
||||
conn, _, err := websocket.DefaultDialer.Dial(serverAddr, nil)
|
||||
if err != nil {
|
||||
uiConn.WriteJSON(map[string]interface{}{"action": "activation_failed", "error": err.Error()})
|
||||
return
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
conn.WriteJSON(map[string]interface{}{"action": "register", "nodeId": nodeID})
|
||||
conn.WriteJSON(map[string]interface{}{"action": "activate", "code": code, "nodeId": nodeID})
|
||||
|
||||
for {
|
||||
var msg map[string]interface{}
|
||||
if err := conn.ReadJSON(&msg); err != nil {
|
||||
break
|
||||
}
|
||||
action, _ := msg["action"].(string)
|
||||
if action == "activated" || action == "activation_failed" {
|
||||
uiConn.WriteJSON(msg)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func listInstances(dataDir string, conn *websocket.Conn) {
|
||||
dir := filepath.Join(dataDir, "instances")
|
||||
entries, err := os.ReadDir(dir)
|
||||
|
||||
Reference in New Issue
Block a user