From a98eff5040b714feb24dab5b8825edb128f531ca Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Thu, 18 Jan 2018 13:40:27 +0000 Subject: [PATCH 1/2] files: normalize names --- src/files/ls.js | 15 +++++++++++++-- src/files/stat.js | 14 ++++++++++++-- test/files.spec.js | 14 +++++++------- 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/src/files/ls.js b/src/files/ls.js index e87f07719..fe6ee275e 100644 --- a/src/files/ls.js +++ b/src/files/ls.js @@ -2,16 +2,27 @@ const promisify = require('promisify-es6') +const transform = function (res, callback) { + callback(null, res.Entries.map((entry) => { + return { + name: entry.Name, + type: entry.Type, + size: entry.Size, + hash: entry.Hash + } + })) +} + module.exports = (send) => { return promisify((args, opts, callback) => { if (typeof (opts) === 'function') { callback = opts opts = {} } - return send({ + return send.andTransform({ path: 'files/ls', args: args, qs: opts - }, callback) + }, transform, callback) }) } diff --git a/src/files/stat.js b/src/files/stat.js index 845901b98..d53da0dab 100644 --- a/src/files/stat.js +++ b/src/files/stat.js @@ -2,16 +2,26 @@ const promisify = require('promisify-es6') +const transform = function (res, callback) { + callback(null, { + type: res.Type, + blocks: res.Blocks, + size: res.Size, + hash: res.Hash, + cumulativeSize: res.CumulativeSize + }) +} + module.exports = (send) => { return promisify((args, opts, callback) => { if (typeof (opts) === 'function') { callback = opts opts = {} } - send({ + send.andTransform({ path: 'files/stat', args: args, qs: opts - }, callback) + }, transform, callback) }) } diff --git a/test/files.spec.js b/test/files.spec.js index 6806643eb..61c802070 100644 --- a/test/files.spec.js +++ b/test/files.spec.js @@ -231,7 +231,7 @@ describe('.files (the MFS API part)', function () { it('files.ls', (done) => { ipfs.files.ls('/test-folder', (err, res) => { expect(err).to.not.exist() - expect(res.Entries.length).to.equal(1) + expect(res.length).to.equal(1) done() }) }) @@ -286,11 +286,11 @@ describe('.files (the MFS API part)', function () { ipfs.files.stat('/test-folder/test-file', (err, res) => { expect(err).to.not.exist() expect(res).to.deep.equal({ - Hash: 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', - Size: 12, - CumulativeSize: 20, - Blocks: 0, - Type: 'file' + hash: 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', + size: 12, + cumulativeSize: 20, + blocks: 0, + type: 'file' }) done() @@ -404,7 +404,7 @@ describe('.files (the MFS API part)', function () { it('files.ls', () => { return ipfs.files.ls('/test-folder') .then((res) => { - expect(res.Entries.length).to.equal(1) + expect(res.length).to.equal(1) }) }) From 4f4cf994d71d5c30bb4bdbc13bbcc61bb97a823a Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Thu, 18 Jan 2018 14:01:32 +0000 Subject: [PATCH 2/2] fix: tests --- test/files.spec.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/files.spec.js b/test/files.spec.js index 61c802070..c1ccc56d1 100644 --- a/test/files.spec.js +++ b/test/files.spec.js @@ -458,11 +458,11 @@ describe('.files (the MFS API part)', function () { return ipfs.files.stat('/test-folder/test-file') .then((res) => { expect(res).to.deep.equal({ - Hash: 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', - Size: 12, - CumulativeSize: 20, - Blocks: 0, - Type: 'file' + hash: 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', + size: 12, + cumulativeSize: 20, + blocks: 0, + type: 'file' }) }) })