From c29f6fc27ef0ef1f4a0b07ca9c0e18d6a597a510 Mon Sep 17 00:00:00 2001 From: life Date: Sat, 21 Nov 2015 14:56:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=88=97=E5=88=86=E5=BC=80,?= =?UTF-8?q?=20=E6=98=BE=E7=A4=BA=E6=95=B0=E6=8D=AE=E5=A4=A7=E5=B0=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- node_modules/common.js | 25 +++++++++++++ node_modules/user.js | 25 ++++++++++++- public/plugins/accounts/plugin.js | 61 +++++++++++++++++++++++++++---- 3 files changed, 102 insertions(+), 9 deletions(-) diff --git a/node_modules/common.js b/node_modules/common.js index 8cb5eba2..162b6962 100644 --- a/node_modules/common.js +++ b/node_modules/common.js @@ -291,5 +291,30 @@ var Common = { fs.rmdirSync(path); } }, + + /** + * 得到目录下的文件大小 + * @param {string} path 路径 + * @param {boolean} isRecursive 是否递归子目录 + * @return {number} 大小, 以KB为单位 + */ + getFolderSize: function (path, isRecursive) { + var me = this; + var size = 0; + var fies; + if ( fs.existsSync(path) ) { + files = fs.readdirSync(path); + files.forEach(function(file, index) { + var curPath = path + '/' + file; + var stat = fs.statSync(curPath); + if(stat.isDirectory() && isRecursive) { + size += me.getFolderSize(curPath, isRecursive); + } else { + size += stat.size / 1000; + } + }); + } + return size; + } }; module.exports = Common; diff --git a/node_modules/user.js b/node_modules/user.js index a599eb1b..01ec2ace 100644 --- a/node_modules/user.js +++ b/node_modules/user.js @@ -255,10 +255,10 @@ User = { return Evt.getBasePath() + '/data/' + userId; }, getUserImagesPath: function(userId) { - return this.getUserImagesAndAttachBasePath() + '/images'; + return this.getUserImagesAndAttachBasePath(userId) + '/images'; }, getUserAttachsPath: function(userId) { - return this.getUserImagesAndAttachBasePath() + '/attachs'; + return this.getUserImagesAndAttachBasePath(userId) + '/attachs'; }, getUserDBPath: function (userId) { @@ -306,6 +306,27 @@ User = { }); }, + /** + * 得到用户的数据统计 + * @param {User} user 用户 + * @return {Object} {db: 1232, image: 3232, attach: 3232} // 以KB为单位 + */ + getUserDataStats: function (user) { + var me = this; + var userId = user.UserId; + var dbPath = user.HasDB ? me.getUserDBPath(userId) : Evt.getDBPath(); + var dbSize = Common.getFolderSize(dbPath); + + var imageSize = Common.getFolderSize(me.getUserImagesPath(userId)); + var attachSize = Common.getFolderSize(me.getUserAttachsPath(userId)); + + return { + db: dbSize, + image: imageSize, + attach: attachSize + }; + }, + setUserDataPath: function(userId) { var me = this; // 判断是否存在, 不存在则创建dir diff --git a/public/plugins/accounts/plugin.js b/public/plugins/accounts/plugin.js index e2acbd05..9963b94a 100644 --- a/public/plugins/accounts/plugin.js +++ b/public/plugins/accounts/plugin.js @@ -24,8 +24,11 @@ define(function() { "Options": "操作", "Current": "当前", + "Data": "数据", + "Open Dir": "打开目录", "Error": "错误", - "No such account": "无该帐户" + "No such account": "无该帐户", + }, 'zh-hk': { 'Accounts': '帐户管理', @@ -49,6 +52,19 @@ define(function() { #accountsDialog .modal-dialog { width: 750px ; } + #accountsDialog .user-data { + margin: 0; + padding: 0; + list-style: none; + } + #accountsDialog .user-data a { + color: #428bca; + display: inline-block; + margin: 0 3px; + } + #accountsDialog .user-data a:hover { + text-decoration: underline !important; + }