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

Commit df6182a

Browse files
author
Alan Shaw
committed
fix: fixes and cleanup
License: MIT Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
1 parent 7497ead commit df6182a

File tree

12 files changed

+37
-103
lines changed

12 files changed

+37
-103
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,12 @@
107107
"ipfs-block": "~0.8.0",
108108
"ipfs-block-service": "~0.15.1",
109109
"ipfs-http-response": "~0.2.1",
110-
"ipfs-mfs": "~0.5.0",
110+
"ipfs-mfs": "~0.5.2",
111111
"ipfs-multipart": "~0.1.0",
112112
"ipfs-repo": "~0.25.0",
113113
"ipfs-unixfs": "~0.1.16",
114114
"ipfs-unixfs-engine": "~0.34.0",
115-
"ipld": "~0.20.0",
115+
"ipld": "~0.20.1",
116116
"ipld-bitcoin": "~0.1.8",
117117
"ipld-dag-pb": "~0.15.0",
118118
"ipld-ethereum": "^2.0.1",

src/cli/bin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ if (args[0] === 'daemon' || args[0] === 'init') {
102102
exitCode = 1
103103
})
104104
.then(() => cleanup())
105-
.catch((e) => {})
105+
.catch(() => {})
106106
.then(() => {
107107
if (exitCode !== 0) {
108108
process.exit(exitCode)

src/cli/commands/add.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ module.exports = {
231231
}
232232
}
233233

234-
next(null, ipfs.files.addPullStream(options))
234+
next(null, ipfs.addPullStream(options))
235235
}
236236
], (err, addStream) => {
237237
if (err) throw err

src/core/components/files-mfs.js

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,9 @@
11
'use strict'
22

3-
const promisify = require('promisify-es6')
43
const mfs = require('ipfs-mfs/core')
54

6-
module.exports = (self) => {
7-
const proxy = {
8-
add: self.add,
9-
dag: {
10-
get: promisify((cid, path, opts, cb) => {
11-
if (typeof path === 'function') {
12-
cb = path
13-
path = undefined
14-
}
15-
16-
if (typeof opts === 'function') {
17-
cb = opts
18-
opts = {}
19-
}
20-
21-
opts = Object.assign({}, opts, { preload: false })
22-
23-
return self.dag.get(cid, path, opts, cb)
24-
}),
25-
put: promisify((node, opts, cb) => {
26-
if (typeof opts === 'function') {
27-
cb = opts
28-
opts = {}
29-
}
30-
31-
opts = Object.assign({}, opts, { preload: false })
32-
33-
return self.dag.put(node, opts, cb)
34-
})
35-
}
36-
}
37-
38-
return mfs(proxy, self._options)
39-
}
5+
module.exports = self => mfs({
6+
ipld: self._ipld,
7+
repo: self._repo,
8+
repoOwner: self._options.repoOwner
9+
})

src/core/components/files-regular.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,5 +488,9 @@ module.exports = function (self) {
488488
},
489489

490490
lsPullStream: _lsPullStream
491+
492+
// TODO create addFromFs
493+
// TODO create addFromStream
494+
// TODO create addFromUrl
491495
}
492496
}

src/core/index.js

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ class IPFS extends EventEmitter {
137137
this.shutdown = this.stop
138138
this.isOnline = components.isOnline(this)
139139
// - interface-ipfs-core defined API
140+
Object.assign(this, components.filesRegular(this))
140141
this.version = components.version(this)
141142
this.id = components.id(this)
142143
this.repo = components.repo(this)
@@ -145,6 +146,7 @@ class IPFS extends EventEmitter {
145146
this.block = components.block(this)
146147
this.object = components.object(this)
147148
this.dag = components.dag(this)
149+
this.files = components.filesMFS(this)
148150
this.libp2p = components.libp2p(this)
149151
this.swarm = components.swarm(this)
150152
this.name = components.name(this)
@@ -172,27 +174,6 @@ class IPFS extends EventEmitter {
172174

173175
this.state = require('./state')(this)
174176

175-
// ipfs regular Files APIs
176-
const filesRegular = components.filesRegular(this)
177-
this.add = filesRegular.add
178-
this.addReadableStream = filesRegular.addReadableStream
179-
this.addPullStream = filesRegular.addPullStream
180-
// TODO create this.addFromFs
181-
// TODO create this.addFromStream
182-
// TODO create this.addFromUrl
183-
this.cat = filesRegular.catImmutable
184-
this.catReadableStream = filesRegular.catReadableStream
185-
this.catPullStream = filesRegular.catPullStream
186-
this.get = filesRegular.getImmutable
187-
this.getReadableStream = filesRegular.getReadableStream
188-
this.getPullStream = filesRegular.getPullStream
189-
this.ls = filesRegular.lsImmutable
190-
this.lsReadableStream = filesRegular.lsReadableStream
191-
this.lsPullStream = filesRegular.lsPullStream
192-
193-
// ipfs.files API (aka MFS)
194-
this.files = components.filesMFS(this)
195-
196177
// ipfs.util
197178
this.util = {
198179
crypto,

src/http/api/resources/files.js renamed to src/http/api/resources/files-regular.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ exports.add = {
282282
}
283283
}
284284

285-
exports.immutableLs = {
285+
exports.ls = {
286286
// uses common parseKey method that returns a `key`
287287
parseArgs: exports.parseKey,
288288

src/http/api/resources/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ exports.block = require('./block')
1313
exports.swarm = require('./swarm')
1414
exports.bitswap = require('./bitswap')
1515
exports.file = require('./file')
16-
exports.files = require('./files')
16+
exports.filesRegular = require('./files-regular')
1717
exports.pubsub = require('./pubsub')
1818
exports.dns = require('./dns')
1919
exports.key = require('./key')

src/http/api/routes/files.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ module.exports = (server) => {
1212
path: '/api/v0/cat',
1313
config: {
1414
pre: [
15-
{ method: resources.cat.parseArgs, assign: 'args' }
15+
{ method: resources.filesRegular.cat.parseArgs, assign: 'args' }
1616
],
17-
handler: resources.cat.handler
17+
handler: resources.filesRegular.cat.handler
1818
}
1919
})
2020

@@ -24,9 +24,9 @@ module.exports = (server) => {
2424
path: '/api/v0/get',
2525
config: {
2626
pre: [
27-
{ method: resources.get.parseArgs, assign: 'args' }
27+
{ method: resources.filesRegular.get.parseArgs, assign: 'args' }
2828
],
29-
handler: resources.get.handler
29+
handler: resources.filesRegular.get.handler
3030
}
3131
})
3232

@@ -40,8 +40,8 @@ module.exports = (server) => {
4040
output: 'stream',
4141
maxBytes: Number.MAX_SAFE_INTEGER
4242
},
43-
handler: resources.add.handler,
44-
validate: resources.add.validate
43+
handler: resources.filesRegular.add.handler,
44+
validate: resources.filesRegular.add.validate
4545
}
4646
})
4747

@@ -51,9 +51,9 @@ module.exports = (server) => {
5151
path: '/api/v0/ls',
5252
config: {
5353
pre: [
54-
{ method: resources.files.immutableLs.parseArgs, assign: 'args' }
54+
{ method: resources.filesRegular.ls.parseArgs, assign: 'args' }
5555
],
56-
handler: resources.files.immutableLs.handler
56+
handler: resources.filesRegular.ls.handler
5757
}
5858
})
5959

test/core/files.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const pull = require('pull-stream')
1111
const IPFSFactory = require('ipfsd-ctl')
1212
const IPFS = require('../../src/core')
1313

14-
describe.only('files', () => {
14+
describe('files', () => {
1515
let ipfsd, ipfs
1616

1717
before(function (done) {

test/core/interface.spec.js

Lines changed: 10 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -79,38 +79,16 @@ describe('interface-ipfs-core tests', () => {
7979
})
8080

8181
tests.filesRegular(defaultCommonFactory, {
82-
skip: [
83-
// .addFromStream
84-
isNode ? null : {
85-
name: 'same as .add',
86-
reason: 'Designed for Node.js only'
87-
},
88-
// .addFromFs
89-
isNode ? null : {
90-
name: 'a directory',
91-
reason: 'Designed for Node.js only'
92-
},
93-
isNode ? null : {
94-
name: 'a directory with an odd name',
95-
reason: 'Designed for Node.js only'
96-
},
97-
isNode ? null : {
98-
name: 'add and ignore a directory',
99-
reason: 'Designed for Node.js only'
100-
},
101-
isNode ? null : {
102-
name: 'a file',
103-
reason: 'Designed for Node.js only'
104-
},
105-
isNode ? null : {
106-
name: 'a hidden file in a directory',
107-
reason: 'Designed for Node.js only'
108-
},
109-
isNode ? null : {
110-
name: 'a with only-hash=true',
111-
reason: 'Designed for Node.js only'
112-
}
113-
]
82+
skip: [{
83+
name: 'addFromStream',
84+
reason: 'TODO: not implemented yet'
85+
}, {
86+
name: 'addFromFs',
87+
reason: 'TODO: not implemented yet'
88+
}, {
89+
name: 'addFromUrl',
90+
reason: 'TODO: not implemented yet'
91+
}]
11492
})
11593

11694
// TODO needs MFS module to be updated

test/http-api/interface.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ describe('interface-ipfs-core over ipfs-api tests', () => {
2626
})
2727

2828
tests.filesRegular(defaultCommonFactory)
29+
2930
tests.filesMFS(defaultCommonFactory)
3031

3132
tests.key(CommonFactory.create({

0 commit comments

Comments
 (0)