|
9 | 9 | "crypto/sha256" |
10 | 10 | "crypto/x509" |
11 | 11 | "encoding/hex" |
| 12 | + "encoding/json" |
12 | 13 | "encoding/pem" |
13 | 14 | "errors" |
14 | 15 | "io/ioutil" |
@@ -124,11 +125,39 @@ func uploadHandler(c *gin.Context) { |
124 | 125 | data.Board = data.Rewrite |
125 | 126 | } |
126 | 127 |
|
127 | | - go programmer.Do(data.Port, data.Board, filePath, data.Commandline, data.Extra, nil) |
| 128 | + go func() { |
| 129 | + // Resolve commandline |
| 130 | + commandline, err := programmer.Resolve(data.Port, data.Board, filePath, data.Commandline, data.Extra, &Tools) |
| 131 | + if err != nil { |
| 132 | + |
| 133 | + return |
| 134 | + } |
| 135 | + |
| 136 | + // Upload |
| 137 | + if data.Extra.Network { |
| 138 | + send(map[string]string{"ProgrammerStatus": "Starting", "Cmd": "Network"}) |
| 139 | + err = programmer.Network(data.Port, data.Board, filePath, commandline, data.Extra.Auth, nil) |
| 140 | + } else { |
| 141 | + send(map[string]string{"ProgrammerStatus": "Starting", "Cmd": "Serial"}) |
| 142 | + err = programmer.Serial(data.Port, commandline, data.Extra, nil) |
| 143 | + } |
| 144 | + |
| 145 | + // Handle result |
| 146 | + if err != nil { |
| 147 | + send(map[string]string{"ProgrammerStatus": "Error", "Msg": err.Error()}) |
| 148 | + return |
| 149 | + } |
| 150 | + send(map[string]string{"ProgrammerStatus": "Done", "Flash": "Ok"}) |
| 151 | + }() |
128 | 152 |
|
129 | 153 | c.String(http.StatusAccepted, "") |
130 | 154 | } |
131 | 155 |
|
| 156 | +func send(args map[string]string) { |
| 157 | + mapB, _ := json.Marshal(args) |
| 158 | + h.broadcastSys <- mapB |
| 159 | +} |
| 160 | + |
132 | 161 | func verifyCommandLine(input string, signature string) error { |
133 | 162 | sign, _ := hex.DecodeString(signature) |
134 | 163 | block, _ := pem.Decode([]byte(*signatureKey)) |
|
0 commit comments