use commands to request upload; let storage component figure out which one to call

This commit is contained in:
Iuri Matias 2018-07-07 18:11:45 +03:00
parent d40ae2f374
commit 44f5186af1
4 changed files with 13 additions and 22 deletions

View File

@ -327,34 +327,16 @@ class Embark {
engine.startService("codeGenerator");
callback();
},
function setupStoragePlugin(callback) {
function listLoadedPlugin(callback) {
let pluginList = engine.plugins.listPlugins();
if (pluginList.length > 0) {
engine.logger.info(__("loaded plugins") + ": " + pluginList.join(", "));
}
// check use has input existing storage plugin
let cmdPlugins = engine.plugins.getPluginsFor('uploadCmds');
if (cmdPlugins.length > 0) {
cmdPlugin = cmdPlugins.find((pluginCmd) => {
return pluginCmd.uploadCmds.some(uploadCmd => {
return uploadCmd.cmd === platform;
});
});
}
if (!cmdPlugin) {
return callback({message: __('platform "{{platform}}" is specified as the upload provider, however no plugins have registered an upload command for "{{platform}}".', {platform: platform})});
}
callback();
},
function deploy(callback) {
engine.events.on('outputDone', function () {
cmdPlugin.uploadCmds[0].cb()
.then((success) => {
callback(null, success);
})
.catch(callback);
embark.events.request("storage:upload", callback);
});
engine.events.on('check:backOnline:Ethereum', function () {
engine.logger.info(__('Ethereum node detected') + '..');

View File

@ -24,7 +24,7 @@ class IPFS {
configIpfsBin: this.storageConfig.ipfs_bin || "ipfs"
});
this.embark.registerUploadCommand('ipfs', upload_ipfs.deploy.bind(upload_ipfs));
this.events.setCommandHandler('storage:upload:ipfs', upload_ipfs.deploy.bind(upload_ipfs));
}
setServiceCheck() {

View File

@ -8,6 +8,7 @@ const constants = require('../../constants');
class Storage {
constructor(embark, options){
const self = this;
this._embark = embark;
this._options = options;
this._storageConfig = options.storageConfig;
@ -33,6 +34,14 @@ class Storage {
if(_.contains(options.context, constants.contexts.upload) || _.contains(options.context, constants.contexts.run)){
this.startStorageProcesses();
}
embark.events.setCommandHandler('storage:upload', (cb) => {
let platform = options.storageConfig.upload.provider;
if (['swarm', 'ipfs'].indexOf(platform) === -1) {
return cb({message: __('platform "{{platform}}" is specified as the upload provider, however no plugins have registered an upload command for "{{platform}}".', {platform: platform})});
}
});
}
_checkStorageEndpoint(platform, callback) {

View File

@ -30,7 +30,7 @@ class Swarm {
bzz: this.bzz
});
this.embark.registerUploadCommand('swarm', this.upload_swarm.deploy.bind(this.upload_swarm));
this.events.setCommandHandler('storage:upload:swarm', this.upload_swarm.deploy.bind(this.upload_swarm));
}
setServiceCheck() {