show the size of your files, if you're logged in

pull/1/head
ansuz 8 years ago
parent 2b8579e8b7
commit 347459781c

@ -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";

@ -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');
}
});
};

@ -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 = $('<div>');
@ -1889,14 +1887,50 @@ the size of the pinned file (if it is pinned) */
$('<br>').appendTo($d);
if (!ro) {
$('<label>', {'for': 'propLink'}).text(Messages.editShare).appendTo($d);
$('<input>', {'id': 'propLink', 'readonly': 'readonly', 'value': base + el}).appendTo($d);
$('<input>', {'id': 'propLink', 'readonly': 'readonly', 'value': base + el})
.click(function () { $(this).select(); })
.appendTo($d);
}
var roLink = ro ? base + el : getReadOnlyUrl(base + el);
if (roLink) {
$('<label>', {'for': 'propROLink'}).text(Messages.viewShare).appendTo($d);
$('<input>', {'id': 'propROLink', 'readonly': 'readonly', 'value': roLink}).appendTo($d);
$('<input>', {'id': 'propROLink', 'readonly': 'readonly', 'value': roLink})
.click(function () { $(this).select(); })
.appendTo($d);
}
if (Cryptpad.isLoggedIn() && AppConfig.enablePinning) {
// check the size of this file...
Cryptpad.getFileSize(el, function (e, bytes) {
if (e) {
// there was a problem with the RPC
console.error(e);
// but we don't want to break the interface.
// continue as if there was no RPC
return void cb(void 0, $d);
}
var KB = Cryptpad.bytesToKilobytes(bytes);
$('<br>').appendTo($d);
$('<label>', {
'for': 'size'
}).text('Size in Kilobytes').appendTo($d);
$('<input>', {
id: 'size',
readonly: 'readonly',
value: KB + 'KB',
})
.click(function () { $(this).select(); })
.appendTo($d);
cb(void 0, $d);
});
} else {
cb(void 0, $d);
}
return $d.html();
};
$contextMenu.on("click", "a", function(e) {
@ -1944,11 +1978,11 @@ the size of the pinned file (if it is pinned) */
else if ($(this).hasClass("properties")) {
if (paths.length !== 1) { return; }
var el = filesOp.find(paths[0].path);
var prop = getProperties(el);
Cryptpad.alert('', undefined, true);
$('.alertify .msg').html(prop);
$('#propLink').click(function () { $(this).select(); });
$('#propROLink').click(function () { $(this).select(); });
getProperties(el, function (e, $prop) {
if (e) { return void console.error(e); }
Cryptpad.alert('', undefined, true);
$('.alertify .msg').html("").append($prop);
});
}
module.hideMenu();
});
@ -1984,11 +2018,11 @@ the size of the pinned file (if it is pinned) */
else if ($(this).hasClass("properties")) {
if (paths.length !== 1) { return; }
var el = filesOp.find(paths[0].path);
var prop = getProperties(el);
Cryptpad.alert('', undefined, true);
$('.alertify .msg').html(prop);
$('#propLink').click(function () { $(this).select(); });
$('#propROLink').click(function () { $(this).select(); });
getProperties(el, function (e, $prop) {
if (e) { return void console.error(e); }
Cryptpad.alert('', undefined, true);
$('.alertify .msg').html("").append($prop);
});
}
module.hideMenu();
});

Loading…
Cancel
Save