@@ -411,65 +411,52 @@ export default class SocketDaemon extends Daemon {
411411 * options: {}
412412 * }
413413 */
414- upload ( target , data ) {
415- if ( ! target . network ) {
416- this . closeSerialMonitor ( target . port ) ;
417- }
418- this . uploading . next ( { status : this . UPLOAD_IN_PROGRESS } ) ;
419-
420- if ( data . files . length === 0 ) { // At least one file to upload
421- this . uploading . next ( { status : this . UPLOAD_ERROR , err : 'You need at least one file to upload' } ) ;
422- return ;
423- }
414+ _upload ( uploadPayload , target , uploadCommandInfo ) {
415+ uploadCommandInfo . tools . forEach ( tool => {
416+ this . downloadTool ( tool . name , tool . version , tool . packager ) ;
417+ } ) ;
424418
425- // Main file
426- const file = data . files [ 0 ] ;
427- file . name = file . name . split ( '/' ) ;
428- file . name = file . name [ file . name . length - 1 ] ;
429-
430- const payload = {
431- board : target . board ,
432- port : target . port ,
433- commandline : data . commandline ,
434- signature : data . signature ,
435- hex : file . data ,
436- filename : file . name ,
419+ const socketParameters = {
420+ signature : uploadCommandInfo . signature ,
437421 extra : {
438422 auth : {
439423 username : target . auth_user ,
440424 password : target . auth_pass ,
441425 private_key : target . auth_key ,
442426 port : target . auth_port
443427 } ,
444- wait_for_upload_port : data . options . wait_for_upload_port === 'true' || data . options . wait_for_upload_port === true ,
445- use_1200bps_touch : data . options . use_1200bps_touch === 'true' || data . options . use_1200bps_touch === true ,
428+ wait_for_upload_port : uploadCommandInfo . options . wait_for_upload_port === 'true' || uploadCommandInfo . options . wait_for_upload_port === true ,
429+ use_1200bps_touch : uploadCommandInfo . options . use_1200bps_touch === 'true' || uploadCommandInfo . options . use_1200bps_touch === true ,
446430 network : target . network ,
447431 ssh : target . ssh ,
448- params_verbose : data . options . param_verbose ,
449- params_quiet : data . options . param_quiet ,
450- verbose : data . options . verbose
432+ params_verbose : uploadCommandInfo . options . param_verbose ,
433+ params_quiet : uploadCommandInfo . options . param_quiet ,
434+ verbose : uploadCommandInfo . options . verbose
451435 } ,
452- extrafiles : data . extrafiles || [ ]
436+ extrafiles : uploadCommandInfo . extrafiles || [ ]
437+ // Consider to push extra resource files from sketch in future if feature requested (from data folder)
453438 } ;
454439
455- for ( let i = 1 ; i < data . files . length ; i += 1 ) {
456- payload . extrafiles . push ( { filename : data . files [ i ] . name , hex : data . files [ i ] . data } ) ;
457- }
440+ const completePayload = Object . assign ( { } , uploadPayload , socketParameters ) ;
441+
442+ this . downloadingDone . subscribe ( ( ) => {
443+ this . serialMonitorOpened . pipe ( filter ( open => ! open ) )
444+ . pipe ( first ( ) )
445+ . subscribe ( ( ) => {
446+ fetch ( `${ this . pluginURL } /upload` , {
447+ method : 'POST' ,
448+ headers : {
449+ 'Content-Type' : 'text/plain; charset=utf-8'
450+ } ,
451+ body : JSON . stringify ( completePayload )
452+ } )
453+ . catch ( error => {
454+ this . uploading . next ( { status : this . UPLOAD_ERROR , err : error } ) ;
455+ } ) ;
456+ } ) ;
457+ } ) ;
458458
459- this . serialMonitorOpened . pipe ( filter ( open => ! open ) )
460- . pipe ( first ( ) )
461- . subscribe ( ( ) => {
462- fetch ( `${ this . pluginURL } /upload` , {
463- method : 'POST' ,
464- headers : {
465- 'Content-Type' : 'text/plain; charset=utf-8'
466- } ,
467- body : JSON . stringify ( payload )
468- } )
469- . catch ( error => {
470- this . uploading . next ( { status : this . UPLOAD_ERROR , err : error } ) ;
471- } ) ;
472- } ) ;
459+ this . downloadingError . subscribe ( error => this . uploading . next ( { status : this . UPLOAD_ERROR , err : error } ) ) ;
473460 }
474461
475462 /**
0 commit comments