From de01672af822b384f3e7592d8221a2cebcf22d66 Mon Sep 17 00:00:00 2001 From: himetani_cafe Date: Mon, 25 Jan 2016 17:17:55 +0900 Subject: [PATCH] =?utf8?q?[Leave]=20removeDirectory()=E3=81=AE=E9=96=A2?= =?utf8?q?=E6=95=B0=E5=AE=9A=E7=BE=A9=E3=81=A0=E3=81=91=E6=9B=B8=E3=81=84?= =?utf8?q?=E3=81=9F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- server/class/DB.js | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/server/class/DB.js b/server/class/DB.js index 1ae1252..21bd4cb 100644 --- a/server/class/DB.js +++ b/server/class/DB.js @@ -351,9 +351,9 @@ function DB() { /** * createDirectory - * + * ディレクトリを作成 * @param directory - * @returns {promise} + * @returns {promise} ディレクトリの作成に成功すればresolve、失敗すればreject */ function createDirectory(directory) { return new Promise(function(resolve, reject) { @@ -382,6 +382,40 @@ function DB() { }); } + + /** + * removeDirectory + * ディレクトリを削除 + * @param directory + * @returns {promise} ディレクトリの削除に成功すればresolve、失敗すればreject + */ + function removeDirectory(directory) { + return new Promise(function(resolve, reject) { + var leaf = directory.split('/').pop(); + var parentDirectory = directory.replace('/'+leaf, ''); + if(!parentDirectory) { + parentDirectory = '/'; + } + Promise.all([existDirectory(parentDirectory), notExistDirectory(directory), notExistFile(leaf, parentDirectory)]) + .catch(function(error) { + reject(error); + }) + .then(function(r) { + var parentId = r[0]; + var q = { + fileId: uuid.v1(), + name: leaf, + parentId: parentId, + fileType: 0 + } + return Files.create(q) + }) + .then(function(r) { + resolve(r.dataValues.fileId); + }); + }); + } + /** * test1 * test用にデータベースのレコードを追加する関数 -- 2.11.0