2018-05-28 15:48:27 +00:00
|
|
|
const shelljs = require('shelljs');
|
|
|
|
const ProcessWrapper = require('../../process/processWrapper');
|
|
|
|
const constants = require('../../constants');
|
|
|
|
|
|
|
|
let ipfsProcess;
|
|
|
|
|
|
|
|
class IPFSProcess extends ProcessWrapper {
|
|
|
|
constructor(_options) {
|
|
|
|
super();
|
|
|
|
|
|
|
|
this.startIPFSDaemon();
|
|
|
|
}
|
|
|
|
|
|
|
|
startIPFSDaemon() {
|
2018-05-23 19:10:53 +00:00
|
|
|
shelljs.exec('ipfs daemon', {silent: true}, (err, _stdout, _stderr) => {
|
2018-05-28 15:48:27 +00:00
|
|
|
if (err) {
|
|
|
|
console.error(err);
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
process.exit();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
process.on('message', (msg) => {
|
2018-05-23 19:10:53 +00:00
|
|
|
if (msg.action === constants.storage.init) {
|
2018-05-28 15:48:27 +00:00
|
|
|
ipfsProcess = new IPFSProcess(msg.options);
|
2018-05-23 19:10:53 +00:00
|
|
|
return ipfsProcess.send({result: constants.storage.initiated});
|
2018-05-28 15:48:27 +00:00
|
|
|
}
|
|
|
|
});
|