|
3 | 3 | const promisify = require('promisify-es6')
|
4 | 4 | const mfs = require('ipfs-mfs/core')
|
5 | 5 |
|
6 |
| -module.exports = self => { |
7 |
| - const mfsSelf = Object.assign({}, self) |
8 |
| - |
9 |
| - // A patched dag API to ensure preload doesn't happen for MFS operations |
10 |
| - // (MFS is preloaded periodically) |
11 |
| - mfsSelf.dag = Object.assign({}, self.dag, { |
12 |
| - get: promisify((cid, path, opts, cb) => { |
13 |
| - if (typeof path === 'function') { |
14 |
| - cb = path |
15 |
| - path = undefined |
16 |
| - } |
17 |
| - |
18 |
| - if (typeof opts === 'function') { |
19 |
| - cb = opts |
20 |
| - opts = {} |
21 |
| - } |
22 |
| - |
23 |
| - opts = Object.assign({}, opts, { preload: false }) |
24 |
| - |
25 |
| - return self.dag.get(cid, path, opts, cb) |
26 |
| - }), |
27 |
| - put: promisify((node, opts, cb) => { |
28 |
| - if (typeof opts === 'function') { |
29 |
| - cb = opts |
30 |
| - opts = {} |
31 |
| - } |
32 |
| - |
33 |
| - opts = Object.assign({}, opts, { preload: false }) |
34 |
| - |
35 |
| - return self.dag.put(node, opts, cb) |
36 |
| - }) |
37 |
| - }) |
38 |
| - |
39 |
| - return mfs(mfsSelf, mfsSelf._options) |
| 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) |
40 | 39 | }
|
0 commit comments