Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit 3dad1d1

Browse files
committed
jsipfs files add feature
1 parent ce871a1 commit 3dad1d1

File tree

8 files changed

+51
-17
lines changed

8 files changed

+51
-17
lines changed

.travis.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ node_js:
33
- "4"
44
- "5"
55

6-
branches:
7-
only:
8-
- master
9-
106
before_install:
117
- npm i -g npm
128
# Workaround for a permissions issue with Travis virtual machine images
9+
10+
addons:
11+
firefox: 'latest'
12+
1313
script:
1414
- npm test
1515

karma.conf.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ module.exports = function (config) {
2121
},
2222
externals: {
2323
fs: '{}',
24-
'node-forge': 'forge'
24+
'node-forge': 'forge',
25+
'ipfs-data-importing': '{ import: {} }'
2526
},
2627
node: {
2728
Buffer: true

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
"hapi": "^12.0.0",
8383
"ipfs-api": "^2.13.1",
8484
"ipfs-blocks": "^0.1.0",
85+
"ipfs-data-importing": "^0.3.0",
8586
"ipfs-merkle-dag": "^0.2.1",
8687
"ipfs-multipart": "^0.1.0",
8788
"ipfs-repo": "^0.5.0",

src/cli/commands/add.js

-10
This file was deleted.

src/cli/commands/files/add.js

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
'use strict'
2+
3+
const Command = require('ronin').Command
4+
const IPFS = require('../../../ipfs-core')
5+
const debug = require('debug')
6+
const log = debug('cli:version')
7+
log.error = debug('cli:version:error')
8+
const bs58 = require('bs58')
9+
10+
module.exports = Command.extend({
11+
desc: 'Add a file to IPFS using the UnixFS data format',
12+
13+
options: {
14+
recursive: {
15+
alias: 'r',
16+
type: 'boolean',
17+
default: false
18+
}
19+
},
20+
21+
run: (recursive, path) => {
22+
var node = new IPFS()
23+
path = process.cwd() + '/' + path
24+
node.files.add(path, {
25+
recursive: recursive
26+
}, (err, stats) => {
27+
if (err) {
28+
return console.log(err)
29+
}
30+
console.log('added', bs58.encode(stats.Hash).toString(), stats.Name)
31+
})
32+
}
33+
})

src/http-api/resources/config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ exports.replace = {
140140
}
141141

142142
const parser = multipart.reqParser(request.payload)
143-
let file
143+
var file
144144

145145
parser.on('file', (fileName, fileStream) => {
146146
fileStream.on('data', (data) => {

src/http-api/resources/object.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ exports.put = {
104104
}
105105

106106
const parser = multipart.reqParser(request.payload)
107-
let file
107+
var file
108108

109109
parser.on('file', (fileName, fileStream) => {
110110
fileStream.on('data', (data) => {

src/ipfs-core/index.js

+9
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const DAGService = mDAG.DAGService
1111
const Id = require('peer-id')
1212
const Info = require('peer-info')
1313
const multiaddr = require('multiaddr')
14+
const importer = require('ipfs-data-importing').import
1415

1516
exports = module.exports = IPFS
1617

@@ -320,6 +321,14 @@ function IPFS (repo) {
320321
records: {},
321322
ping: notImpl
322323
}
324+
325+
this.files = {
326+
add: (path, options, callback) => {
327+
options.path = path
328+
options.dagService = dagS
329+
importer(options, callback)
330+
}
331+
}
323332
}
324333

325334
function notImpl () {

0 commit comments

Comments
 (0)