refactor(contorller): update to consider iowa_2 and look at plant token vs server going forward

This commit is contained in:
2025-09-29 12:44:46 -05:00
parent 99e70fcafb
commit a5a67660e8
4 changed files with 214 additions and 93 deletions

View File

@@ -15,9 +15,9 @@ import (
)
type UpdatePayload struct {
Action string `json:"action"`
Target string `json:"target"`
Drive string `json:"drive"`
Action string `json:"action"`
Target string `json:"target"`
Location string `json:"location"`
}
func registerUpdateChannel(server *socketio.Server) {
@@ -32,7 +32,7 @@ func registerUpdateChannel(server *socketio.Server) {
server.OnEvent("/", "update", func(s socketio.Conn, payload UpdatePayload) {
switch strings.ToLower(payload.Action) {
case "copy":
copyLatestBuild(server, payload.Target, payload.Drive)
copyLatestBuild(server, payload.Target, payload.Location)
case "update":
updateServer(server, payload.Target)
@@ -81,13 +81,13 @@ func updateServer(server *socketio.Server, target string) {
}
}
func copyLatestBuild(server *socketio.Server, target string, drive string) {
func copyLatestBuild(server *socketio.Server, target string, location string) {
server.BroadcastToRoom("/", "update", "updateLogs",
fmt.Sprintf("🚀 Copying latest build to %v", target))
copyBuild(server, target, drive)
copyBuild(server, target, location)
}
func triggerRemoteUpdate(server *socketio.Server, remoteURL string, payload UpdatePayload) {
func triggerRemoteUpdate(server *socketio.Server, token string, payload UpdatePayload) {
fmt.Println("running the update process")
basePath := "/api/controller"
@@ -98,7 +98,7 @@ func triggerRemoteUpdate(server *socketio.Server, remoteURL string, payload Upda
// send POST request with JSON, expect SSE / streaming text back
body, _ := json.Marshal(payload)
url := fmt.Sprintf("https://%v.alpla.net%v/update", remoteURL, basePath)
url := fmt.Sprintf("https://%vprod.alpla.net%v/update", token, basePath)
fmt.Println(url)
//url := fmt.Sprintf("http://%v:8080/api/controller/update", remoteURL)
fmt.Println(url)