From 347459781c370054d517011123e6b24b3662a14c Mon Sep 17 00:00:00 2001 From: ansuz Date: Tue, 18 Apr 2017 15:49:04 +0200 Subject: [PATCH] show the size of your files, if you're logged in --- www/common/cryptpad-common.js | 8 ++++ www/common/pinpad.js | 11 +++++- www/drive/main.js | 72 ++++++++++++++++++++++++++--------- 3 files changed, 71 insertions(+), 20 deletions(-) diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index ffb6936c5..1e5c51e5b 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -676,6 +676,14 @@ define([ rpc.getFileListSize(cb); }; + var getFileSize = common.getFileSize = function (href, cb) { + var channelId = Hash.hrefToHexChannelId(href); + rpc.getFileSize(channelId, function (e, bytes) { + if (e) { return void cb(e); } + cb(void 0, bytes); + }); + }; + var createButton = common.createButton = function (type, rightside, data, callback) { var button; var size = "17px"; diff --git a/www/common/pinpad.js b/www/common/pinpad.js index a9467cff9..f4d789a5e 100644 --- a/www/common/pinpad.js +++ b/www/common/pinpad.js @@ -83,7 +83,14 @@ define([ // get the total stored size of a channel's patches (in bytes) exp.getFileSize = function (file, cb) { - rpc.send('GET_FILE_SIZE', file, cb); + rpc.send('GET_FILE_SIZE', file, function (e, response) { + if (e) { return void cb(e); } + if (response && response.length) { + cb(void 0, response[0]); + } else { + cb('INVALID_RESPONSE'); + } + }); }; // get the combined size of all channels (in bytes) for all the @@ -93,6 +100,8 @@ define([ if (e) { return void cb(e); } if (response && response.length) { cb(void 0, response[0]); + } else { + cb('INVALID_RESPONSE'); } }); }; diff --git a/www/drive/main.js b/www/drive/main.js index 78733530f..3d1558cd0 100644 --- a/www/drive/main.js +++ b/www/drive/main.js @@ -1876,12 +1876,10 @@ define([ } }); - var getProperties = function (el) { -/* TODO... -if we make this async, we can include an RPC call to the server which tells us -the size of the pinned file (if it is pinned) */ - - if (!filesOp.isFile(el)) { return; } + var getProperties = function (el, cb) { + if (!filesOp.isFile(el)) { + return void cb('NOT_FILE'); + } var ro = filesOp.isReadOnlyFile(el); var base = window.location.origin; var $d = $('
'); @@ -1889,14 +1887,50 @@ the size of the pinned file (if it is pinned) */ $('
').appendTo($d); if (!ro) { $('