Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function setup () {
// get a controller for the local ipfs node
ipfsd.local((err, _ipfsNode) => {
if (err) {
// note the error
// for now, let's keep the process running without ipfs, if it fails
console.error('Failed to start IPFS')
console.error(err)
return
}
ipfsNode = _ipfsNode // save global
// init and start the daemon
if (ipfsNode.initialized)
startDaemon()
else {
log('[IPFS] Initializing ~/.ipfs, keysize', KEYSIZE)
ipfsNode.init({ keySize: KEYSIZE }, (err, res) => {
if (err) {
export function boot (lokker) {
logger = lokker
// main entry point
ipfsd.local((err, node) => {
if (err) {
// We can't start if we fail to aquire
// a ipfs node
logger.error(err)
process.exit(1)
}
mb = menubar(config.menuBar)
// Ensure single instance
mb.app.makeSingleInstance(reboot)
mb.on('ready', () => {
logger.info('Application is ready')
// -- load the controls
return new Promise((resolve, reject) => {
ipfsd.local(this._options.IpfsDataDir, this._options, (err, node) => {
if(err)
reject(err)
this._daemon = node
logger.debug("Initializing IPFS daemon")
logger.debug(`Using IPFS repo at '${node.path}'`)
// try {
// if (fs.lstatSync(this._options.IpfsDataDir)) {
// logger.debug(`IPFS repo already exists at '${node.path}'`)
// return resolve()
// }
// } catch(e) {
// logger.debug(`IPFS repo doesn't exists at '${node.path}', creating a new one`)
// }
(cb) => {
if (this.disposable) {
const config = Object.assign({ init: this.init }, this.config)
ctl.disposable(config, cb)
} else if (this.init) {
ctl.local(this.path, (err, node) => {
if (err) {
return cb(err)
}
node.init((err) => cb(err, node))
})
} else {
ctl.local(this.path, cb)
}
},
(node, cb) => {
(cb) => {
if (this.disposable) {
const config = Object.assign({ init: this.init }, this.config)
ctl.disposable(config, cb)
} else if (this.init) {
ctl.local(this.path, (err, node) => {
if (err) {
return cb(err)
}
node.init((err) => cb(err, node))
})
} else {
ctl.local(this.path, cb)
}
},
(node, cb) => {
var getApi = W(function * (w) {
if (ipfsApi) return ipfsApi
try {
ipfsApi = IpfsApi('localhost', 5001)
yield ipfsApi.id(w)
} catch (e) {
yield mkdirp(inpmPath, w)
var node = yield ipfsd.local(ipfsPath, w)
if (!(yield utils.exists(ipfsPath, w))) {
yield node.init(w)
}
ipfsApi = yield node.startDaemon(w)
}
return ipfsApi
})
return new Promise((resolve, reject) => {
ipfsCtl.local(IPFS_REPO, {}, (err, node) => {
if (err) {
logger.error('[IPFSSync] _getNode', err);
reject(err);
return;
}
resolve(node);
});
});
}