diff --git a/server/rest/index.js b/server/rest/index.js index 028d5fb4..397472cd 100644 --- a/server/rest/index.js +++ b/server/rest/index.js @@ -12,7 +12,7 @@ const markdown = require(DIR + 'markdown'); const jaguar = require('jaguar'); const onezip = require('onezip'); const inly = require('inly'); -const currify = require('currify/legacy'); +const wraptile = require('wraptile/legacy'); const pullout = require('pullout/legacy'); const json = require('jonny/legacy'); const ponse = require('ponse'); @@ -21,7 +21,7 @@ const check = require('checkup'); const moveFiles = require('./move-files'); -const swap = currify((fn, a, b) => fn(b, a)); +const swap = wraptile((fn, a, b) => fn(b, a)); const isWin32 = process.platform === 'win32'; /** diff --git a/server/rest/move-files.js b/server/rest/move-files.js index 34136c39..bcb5883b 100644 --- a/server/rest/move-files.js +++ b/server/rest/move-files.js @@ -2,39 +2,42 @@ const path = require('path'); const flop = require('flop'); -const check = require('checkup'); const promisify = require('es6-promisify').promisify; const move = promisify(flop.move); module.exports = (files, callback) => { + check(files, callback); + if (!files.names) return move(files.from, files.to) .then(callback) .catch(callback); const names = files.names.slice(); - const copy = () => { + const iterate = () => { const isLast = !names.length; if (isLast) - return callback(null); + return callback(); const name = names.shift(); const from = path.join(files.from, name); const to = path.join(files.to, name); move(from, to) - .then(copy) + .then(iterate) .catch(callback); }; - check - .type('callback', callback, 'function') - .check({ - files, - }); - - copy(); + iterate(); }; +function check(files, callback) { + if (typeof files !== 'object') + throw Error('files should be an object!'); + + if (typeof callback !== 'function') + throw Error('callback should be a function!'); +} +