2018-07-07 19:29:04 +03:00
2018-05-28 22:59:18 +10:00
class Storage {
2018-07-08 23:41:37 +03:00
constructor ( embark , options ) {
2018-07-07 21:23:51 +03:00
this . embark = embark ;
this . storageConfig = embark . config . storageConfig ;
2018-07-08 23:41:37 +03:00
this . plugins = options . plugins ;
2018-05-30 16:34:36 +10:00
2018-07-07 21:23:51 +03:00
if ( ! this . storageConfig . enabled ) return ;
2018-06-26 14:18:55 +10:00
2018-07-08 20:40:06 +03:00
this . handleUploadCommand ( ) ;
2018-07-07 19:49:18 +03:00
this . addSetProviders ( ) ;
2018-07-08 20:40:06 +03:00
}
2018-05-30 16:34:36 +10:00
2018-07-08 20:40:06 +03:00
handleUploadCommand ( ) {
const self = this ;
this . embark . events . setCommandHandler ( 'storage:upload' , ( cb ) => {
let platform = self . storageConfig . upload . provider ;
2018-07-08 23:41:37 +03:00
let uploadCmds = self . plugins . getPluginsProperty ( 'uploadCmds' , 'uploadCmds' ) ;
2018-07-08 20:40:06 +03:00
for ( let uploadCmd of uploadCmds ) {
if ( uploadCmd . cmd === platform ) {
return uploadCmd . cb . call ( uploadCmd . cb , cb ) ;
}
2018-07-07 18:11:45 +03:00
}
2018-07-08 00:02:46 +03:00
2018-07-08 20:40:06 +03:00
cb ( { message : _ _ ( 'platform "{{platform}}" is specified as the upload provider, however no plugins have registered an upload command for "{{platform}}".' , { platform : platform } ) } ) ;
2018-07-07 18:11:45 +03:00
} ) ;
2018-06-01 13:12:17 +10:00
}
2018-05-30 16:34:36 +10:00
2018-06-01 13:12:17 +10:00
addSetProviders ( ) {
2018-07-08 20:40:06 +03:00
let code = ` \n EmbarkJS.Storage.setProviders( ${ JSON . stringify ( this . storageConfig . dappConnection || [ ] ) } ); ` ;
2018-07-08 00:56:15 +03:00
2018-06-01 13:12:17 +10:00
let shouldInit = ( storageConfig ) => {
2018-07-08 00:56:15 +03:00
return storageConfig . enabled ;
2018-06-01 13:12:17 +10:00
} ;
2018-06-01 12:53:23 -04:00
2018-07-07 21:23:51 +03:00
this . embark . addProviderInit ( 'storage' , code , shouldInit ) ;
2018-08-28 14:43:52 +01:00
this . embark . addConsoleProviderInit ( 'storage' , code , shouldInit ) ;
2018-06-01 12:53:23 -04:00
}
2018-05-28 22:59:18 +10:00
}
module . exports = Storage ;