-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: can start own ipfs node now mfs is in js-ipfs
fixes #15
- Loading branch information
1 parent
b855bd2
commit 05de260
Showing
6 changed files
with
126 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
'use strict' | ||
|
||
const promisify = require('promisify-es6') | ||
const IPFS = require('ipfs') | ||
const remote = require('ipfs-api') | ||
const mfs = require('./mfs') | ||
const log = require('debug')('ipfs:blob-store:create') | ||
const defaultOptions = { | ||
ipfs: null, | ||
flush: true, | ||
baseDir: '/' | ||
} | ||
|
||
module.exports = promisify((opts, callback) => { | ||
if (typeof opts === 'function') { | ||
callback = opts | ||
opts = defaultOptions | ||
} | ||
|
||
const options = Object.assign({}, defaultOptions, opts) | ||
|
||
if (options.ipfs) { | ||
log('Using pre-configured IPFS instance') | ||
return setImmediate(() => callback(null, mfs(options))) | ||
} | ||
|
||
if (options.host && options.port) { | ||
log(`Connecting to remote IPFS at ${options.host}:${options.port}`) | ||
options.ipfs = remote(options.host, options.port) | ||
|
||
return setImmediate(() => callback(null, mfs(options))) | ||
} | ||
|
||
log(`Starting an IPFS instance`) | ||
callback = once(callback) | ||
|
||
options.ipfs = new IPFS() | ||
options.ipfs.once('ready', () => callback(null, mfs(options))) | ||
options.ipfs.once('error', (error) => callback(error)) | ||
}) | ||
|
||
function once (cb) { | ||
let called = false | ||
|
||
return function () { | ||
if (called) { | ||
return | ||
} | ||
|
||
called = true | ||
cb.apply(null, arguments) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters