Skip to content

Commit 11edf17

Browse files
committed
Allow attaching additional files in the POST
To allow upload using tools which rely on {runtime.*} variables Actions server side: - Compile a "blacklist" (eg : {runtime.platform.path}/variants/{build.variant} ) - Replace these entries with {build.path} when found in commandline - Map the blacklisted entry to a set of extra files to be uploaded - Profit
1 parent 66ed59a commit 11edf17

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

conn.go

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ import (
1111
"encoding/hex"
1212
"encoding/pem"
1313
"errors"
14+
"io/ioutil"
1415
"net/http"
16+
"path"
1517

1618
log "github.com/Sirupsen/logrus"
1719
"github.com/arduino/arduino-create-agent/utilities"
@@ -46,16 +48,22 @@ func (s *WsServer) ServeHTTP(c *gin.Context) {
4648
s.Server.ServeHTTP(c.Writer, c.Request)
4749
}
4850

51+
type AdditionalFile struct {
52+
Hex []byte `json:"hex"`
53+
Filename string `json:"filename"`
54+
}
55+
4956
// Upload contains the data to upload a sketch onto a board
5057
type Upload struct {
51-
Port string `json:"port"`
52-
Board string `json:"board"`
53-
Rewrite string `json:"rewrite"`
54-
Commandline string `json:"commandline"`
55-
Signature string `json:"signature"`
56-
Extra boardExtraInfo `json:"extra"`
57-
Hex []byte `json:"hex"`
58-
Filename string `json:"filename"`
58+
Port string `json:"port"`
59+
Board string `json:"board"`
60+
Rewrite string `json:"rewrite"`
61+
Commandline string `json:"commandline"`
62+
Signature string `json:"signature"`
63+
Extra boardExtraInfo `json:"extra"`
64+
Hex []byte `json:"hex"`
65+
Filename string `json:"filename"`
66+
ExtraFiles []AdditionalFile `json:"extrafiles"`
5967
}
6068

6169
func uploadHandler(c *gin.Context) {
@@ -96,17 +104,21 @@ func uploadHandler(c *gin.Context) {
96104

97105
buffer := bytes.NewBuffer(data.Hex)
98106

99-
path, err := utilities.SaveFileonTempDir(data.Filename, buffer)
107+
filepath, err := utilities.SaveFileonTempDir(data.Filename, buffer)
100108
if err != nil {
101109
c.String(http.StatusBadRequest, err.Error())
102110
return
103111
}
104112

113+
for _, extraFile := range data.ExtraFiles {
114+
ioutil.WriteFile(path.Join(path.Dir(filepath), extraFile.Filename), extraFile.Hex, 0644)
115+
}
116+
105117
if data.Rewrite != "" {
106118
data.Board = data.Rewrite
107119
}
108120

109-
go spProgramRW(data.Port, data.Board, path, data.Commandline, data.Extra)
121+
go spProgramRW(data.Port, data.Board, filepath, data.Commandline, data.Extra)
110122

111123
c.String(http.StatusAccepted, "")
112124
}

0 commit comments

Comments
 (0)