Skip to content

Commit a9ba68d

Browse files
authored
Merge pull request #33 from TheCacophonyProject/use-file
change upload thermal to take whole map
2 parents ff8d1a3 + 4560352 commit a9ba68d

File tree

2 files changed

+17
-19
lines changed

2 files changed

+17
-19
lines changed

api.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,8 @@ func shaHash(r io.Reader) (string, error) {
290290
return hashString, nil
291291
}
292292

293-
// UploadThermalRaw uploads the file to Cacophony API as a multipartmessage
294-
// with data of type thermalRaw specified
295-
func (api *CacophonyAPI) UploadThermalRaw(r io.Reader, metadata map[string]interface{}) (int, error) {
293+
// UploadVideo uploads the file to Cacophony API as a multipartmessage
294+
func (api *CacophonyAPI) UploadVideo(r io.Reader, data map[string]interface{}) (int, error) {
296295
buf := new(bytes.Buffer)
297296
w := multipart.NewWriter(buf)
298297
//This will write to fileBytes as it reads r to get the sha hash
@@ -302,15 +301,14 @@ func (api *CacophonyAPI) UploadThermalRaw(r io.Reader, metadata map[string]inter
302301
if err != nil {
303302
return 0, err
304303
}
305-
306-
data := map[string]interface{}{
307-
"type": "thermalRaw",
308-
"fileHash": hash,
304+
if data == nil {
305+
data = make(map[string]interface{})
309306
}
310-
311-
if metadata != nil {
312-
data["metadata"] = metadata
307+
if _, ok := data["type"]; !ok {
308+
data["type"] = "thermalRaw"
313309
}
310+
data["fileHash"] = hash
311+
314312
// JSON encoded "data" parameter.
315313
dataBuf, err := json.Marshal(data)
316314

api_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,13 @@ func TestNewTokenHttpRequest(t *testing.T) {
8989
assert.NoError(t, err)
9090
}
9191

92-
func TestUploadThermalRawHttpRequest(t *testing.T) {
93-
ts := GetUploadThermalRawServer(t)
92+
func TestUploadVideoHttpRequest(t *testing.T) {
93+
ts := GetUploadVideoServer(t)
9494
defer ts.Close()
9595

9696
api := getAPI(ts.URL, "", true)
9797
reader := strings.NewReader(rawThermalData)
98-
id, err := api.UploadThermalRaw(reader, nil)
98+
id, err := api.UploadVideo(reader, nil)
9999
assert.NoError(t, err)
100100
assert.NotEmpty(t, id)
101101
}
@@ -182,9 +182,9 @@ func getMimeParts(r *http.Request) (map[string]interface{}, string) {
182182
return data, fileData
183183
}
184184

185-
//GetUploadThermalRawServer checks that the message is multipart and contains the required multipartmime file:file and Value:data
185+
//GetUploadVideoServer checks that the message is multipart and contains the required multipartmime file:file and Value:data
186186
//and Authorization header
187-
func GetUploadThermalRawServer(t *testing.T) *httptest.Server {
187+
func GetUploadVideoServer(t *testing.T) *httptest.Server {
188188
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
189189
assert.Equal(t, http.MethodPost, r.Method)
190190
assert.NotEmpty(t, r.Header.Get("Authorization"))
@@ -218,7 +218,7 @@ func randomRegister() (*CacophonyAPI, error) {
218218
return Register(randString(20), randString(20), defaultGroup, apiURL, int(rand.Int31()))
219219
}
220220

221-
func TestAPIUploadThermalRaw(t *testing.T) {
221+
func TestAPIUploadVideo(t *testing.T) {
222222
defer newFs(t, "")()
223223
api, err := randomRegister()
224224
require.NoError(t, err)
@@ -227,7 +227,7 @@ func TestAPIUploadThermalRaw(t *testing.T) {
227227
assert.NoError(t, err)
228228
defer reader.Close()
229229

230-
id, err := api.UploadThermalRaw(reader, nil)
230+
id, err := api.UploadVideo(reader, nil)
231231
assert.NoError(t, err)
232232
assert.NotEmpty(t, id)
233233
}
@@ -304,7 +304,7 @@ func TestRegisterAndNew(t *testing.T) {
304304
assert.NoError(t, err)
305305
defer reader.Close()
306306

307-
id, err := api2.UploadThermalRaw(reader, nil)
307+
id, err := api2.UploadVideo(reader, nil)
308308
assert.NoError(t, err, "check that api can upload recordings")
309309
assert.NotEmpty(t, id, "check that recording id is not 0")
310310

@@ -426,7 +426,7 @@ func TestDeviceReregister(t *testing.T) {
426426
assert.NoError(t, err)
427427
defer reader.Close()
428428

429-
id, err := api2.UploadThermalRaw(reader, nil)
429+
id, err := api2.UploadVideo(reader, nil)
430430
assert.NoError(t, err)
431431
assert.NotEmpty(t, id)
432432
}

0 commit comments

Comments
 (0)