@@ -16,13 +16,13 @@ import { Config, EdgeImpulseConfig } from './config';
1616import { findSerial } from './find-serial' ;
1717import { canFlashSerial } from './can-flash-serial' ;
1818import jpegjs from 'jpeg-js' ;
19- import { makeImage } from './make-image' ;
2019import { RemoteMgmt , RemoteMgmtDevice , RemoteMgmtDeviceSampleEmitter } from '../shared/daemon/remote-mgmt-service' ;
2120import { EventEmitter } from "tsee" ;
2221import { getCliVersion , initCliApp , setupCliApp } from './init-cli-app' ;
2322import { Mutex } from 'async-mutex' ;
2423import WebSocket from 'ws' ;
2524import encodeLabel from '../shared/encoding' ;
25+ import { upload } from './make-image' ;
2626
2727const TCP_PREFIX = '\x1b[32m[WS ]\x1b[0m' ;
2828const SERIAL_PREFIX = '\x1b[33m[SER]\x1b[0m' ;
@@ -354,39 +354,21 @@ class SerialDevice extends (EventEmitter as new () => TypedEmitter<{
354354 height : height ,
355355 } , 100 ) ;
356356
357- let filename = s . label + '.jpg' ;
358- let processed = makeImage ( jpegImageData . data , this . _deviceConfig . sampling . hmacKey , filename ) ;
359-
360- let headers : { [ k : string ] : string } = {
361- 'x-api-key' : this . _deviceConfig . upload . apiKey ,
362- 'x-file-name' : encodeLabel ( filename ) ,
363- 'Content-Type' : ( ! processed . attachments ? processed . contentType : 'multipart/form-data' ) ,
364- 'Connection' : 'keep-alive'
365- } ;
366-
367- headers [ 'x-label' ] = encodeLabel ( s . label ) ;
368-
369357 let url = this . _config . endpoints . internal . ingestion + s . path ;
370358 console . log ( SERIAL_PREFIX , 'Uploading to' , url ) ;
371359
372360 ee . emit ( 'uploading' ) ;
373361
374- await request . post (
375- this . _config . endpoints . internal . ingestion + s . path , {
376- headers : headers ,
377- body : ( ! processed . attachments ? processed . encoded : undefined ) ,
378- formData : ( processed . attachments ? {
379- body : {
380- value : processed . encoded ,
381- options : {
382- filename : filename ,
383- contentType : processed . contentType
384- }
385- } ,
386- attachments : processed . attachments
387- } : undefined ) ,
388- encoding : null ,
389- } ) ;
362+ await upload ( {
363+ filename : s . label + '.jpg' ,
364+ allowDuplicates : false ,
365+ apiKey : this . _deviceConfig . upload . apiKey ,
366+ buffer : jpegImageData . data ,
367+ category : s . path . indexOf ( 'training' ) ? 'training' : 'testing' ,
368+ config : this . _config ,
369+ label : { label : s . label , type : 'label' } ,
370+ boundingBoxes : [ ] ,
371+ } ) ;
390372
391373 console . log ( SERIAL_PREFIX , 'Uploading to' , url , 'OK' ) ;
392374 }
0 commit comments