From 0b3348ee77ff5aec72381f47bc916f1a97919a25 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Wed, 15 May 2019 13:48:52 +0300 Subject: [PATCH] fix(dom) renameCurrent: try-to-promise RESTful.mv --- client/dom/index.js | 22 ++++++++++++---------- common/try-to-promisify.js | 11 +++++++++++ 2 files changed, 23 insertions(+), 10 deletions(-) create mode 100644 common/try-to-promisify.js diff --git a/client/dom/index.js b/client/dom/index.js index 271b563d..e2811916 100644 --- a/client/dom/index.js +++ b/client/dom/index.js @@ -8,6 +8,7 @@ const jonny = require('jonny/legacy'); const tryToCatch = require('try-to-catch/legacy'); const Util = require('../../common/util'); +const tryToPromisify = require('../../common/try-to-promisify'); const Images = require('./images'); const load = require('./load'); @@ -763,6 +764,7 @@ function CmdProto() { if (e) return; + const isExist = !!DOM.getCurrentByName(to); const dirPath = DOM.getCurrentDirPath(); @@ -774,16 +776,16 @@ function CmdProto() { to : dirPath + to, }; - RESTful.mv(files, (error) => { - if (error) - return; - - DOM.setCurrentName(to, current); - Storage.remove(dirPath); - - if (isExist) - CloudCmd.refresh(); - }); + const [error] = await tryToPromisify(RESTful.mv, files); + + if (error) + return; + + DOM.setCurrentName(to, current); + Storage.remove(dirPath); + + if (isExist) + CloudCmd.refresh(); }; /** diff --git a/common/try-to-promisify.js b/common/try-to-promisify.js new file mode 100644 index 00000000..ab4860d2 --- /dev/null +++ b/common/try-to-promisify.js @@ -0,0 +1,11 @@ +'use strict'; + +const {promisify} = require('es6-promisify'); +const tryToCatch = require('try-to-catch/legacy'); + +module.exports = (fn, ...args) => { + const promise = promisify(fn); + + return tryToCatch(promise, ...args); +}; +