From 3a9c8e3bf83f733dae5e42c507f59c26802a9173 Mon Sep 17 00:00:00 2001 From: JbIPS Date: Sun, 26 Nov 2017 23:12:42 +0100 Subject: [PATCH] Uses Buffer for Dropbox batch uploads Closes #130 --- CHANGELOG.md | 9 +++++---- lib/unifile-dropbox.js | 5 +++-- test/unifile-dropbox.js | 17 +++++++++++++++++ 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 10555a5..44e9a0e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,8 +5,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p ## [Unreleased] ### Fixed -- [Dropbox] Batch correctly overwrite existing files -- [Dropbox] Batch now correctly rejects the promise if one action failed +- [Dropbox] Batch correctly overwrite existing files (https://github.com/silexlabs/unifile/issues/131) +- [Dropbox] Batch now correctly rejects the promise if one action failed (https://github.com/silexlabs/unifile/issues/131) +- [Dropbox] Batch upload uses `Buffer` for file content and supports UTF-8 (https://github.com/silexlabs/unifile/issues/130) ## [2.0.0] - 2017-11-25 ### Changed @@ -15,7 +16,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p - Remove parameters mutations - `.readFile()` now always return a `Buffer` - [Dropbox] Retrieve account when providing only the token -- [Dropbox] Normalize errors (as for #103) +- [Dropbox] Normalize errors (https://github.com/silexlabs/unifile/issues/103) ### Added - Tools, index and FS are 100% covered @@ -24,7 +25,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p ### Fixed - In SFTP, directory type is now set to 'application/directory' -- [Dropbox] Fixes batch upload (Closes ##114) +- [Dropbox] Fixes batch upload (https://github.com/silexlabs/unifile/issues/114) ### Removed - WebDAV connector is now a separate plugin diff --git a/lib/unifile-dropbox.js b/lib/unifile-dropbox.js index 6f02def..82879dd 100644 --- a/lib/unifile-dropbox.js +++ b/lib/unifile-dropbox.js @@ -483,12 +483,13 @@ class DropboxConnector { const toUpload = uploadEntries.slice(); actionsChain = actionsChain.then(() => { return Promise.map(toUpload, (action) => { - return openUploadSession(session, action.content, true) + const bitContent = new Buffer(action.content); + return openUploadSession(session, bitContent, true) .then((result) => { return { cursor: { session_id: result.session_id, - offset: action.content.length + offset: bitContent.length }, commit: { path: makePathAbsolute(action.path), diff --git a/test/unifile-dropbox.js b/test/unifile-dropbox.js index d7ab473..58ae3fa 100644 --- a/test/unifile-dropbox.js +++ b/test/unifile-dropbox.js @@ -813,6 +813,23 @@ describe('DropboxConnector', function() { }); }); + it('can write files with special chars', function() { + const path = 'tmp/specialFile'; + const fileContent = 'Àà çéèîï'; + return connector.batch(session, [{ + name: 'writefile', + path: path, + content: fileContent + }]) + .then(() => { + return connector.readFile(session, path); + }) + .then((content) => { + return expect(content.toString()).to.equal(fileContent); + }) + .then(() => connector.rmdir(session, 'tmp')); + }); + it('can overwrite existing files', function() { const path = 'tmp/indexFile'; const fileContent = 'html';