diff --git a/karma.conf.js b/karma.conf.js index cfd13a8e7d..5ced2208cd 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -21,7 +21,8 @@ module.exports = function (config) { }, externals: { fs: '{}', - 'node-forge': 'forge' + 'node-forge': 'forge', + 'ipfs-data-importing': '{ import: {} }' }, node: { Buffer: true diff --git a/package.json b/package.json index 0a5ce3e833..46985cece3 100644 --- a/package.json +++ b/package.json @@ -82,6 +82,7 @@ "hapi": "^12.0.0", "ipfs-api": "^2.13.1", "ipfs-blocks": "^0.1.0", + "ipfs-data-importing": "^0.3.0", "ipfs-merkle-dag": "^0.2.1", "ipfs-multipart": "^0.1.0", "ipfs-repo": "^0.5.0", diff --git a/src/cli/commands/add.js b/src/cli/commands/add.js deleted file mode 100644 index af4020b384..0000000000 --- a/src/cli/commands/add.js +++ /dev/null @@ -1,10 +0,0 @@ -'use strict' - -const Command = require('ronin').Command - -module.exports = Command.extend({ - desc: '', - - run: (name) => { - } -}) diff --git a/src/cli/commands/files/add.js b/src/cli/commands/files/add.js new file mode 100644 index 0000000000..35ca7b4a0e --- /dev/null +++ b/src/cli/commands/files/add.js @@ -0,0 +1,33 @@ +'use strict' + +const Command = require('ronin').Command +const IPFS = require('../../../ipfs-core') +const debug = require('debug') +const log = debug('cli:version') +log.error = debug('cli:version:error') +const bs58 = require('bs58') + +module.exports = Command.extend({ + desc: 'Add a file to IPFS using the UnixFS data format', + + options: { + recursive: { + alias: 'r', + type: 'boolean', + default: false + } + }, + + run: (recursive, path) => { + var node = new IPFS() + path = process.cwd() + '/' + path + node.files.add(path, { + recursive: recursive + }, (err, stats) => { + if (err) { + return console.log(err) + } + console.log('added', bs58.encode(stats.Hash).toString(), stats.Name) + }) + } +}) diff --git a/src/ipfs-core/index.js b/src/ipfs-core/index.js index a969a23854..990d75101c 100644 --- a/src/ipfs-core/index.js +++ b/src/ipfs-core/index.js @@ -11,6 +11,7 @@ const DAGService = mDAG.DAGService const Id = require('peer-id') const Info = require('peer-info') const multiaddr = require('multiaddr') +const importer = require('ipfs-data-importing').import exports = module.exports = IPFS @@ -320,6 +321,14 @@ function IPFS (repo) { records: {}, ping: notImpl } + + this.files = { + add: (path, options, callback) => { + options.path = path + options.dagService = dagS + importer(options, callback) + } + } } function notImpl () {