show the size of your files, if you're logged in
This commit is contained in:
parent
2b8579e8b7
commit
347459781c
@ -676,6 +676,14 @@ define([
|
|||||||
rpc.getFileListSize(cb);
|
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 createButton = common.createButton = function (type, rightside, data, callback) {
|
||||||
var button;
|
var button;
|
||||||
var size = "17px";
|
var size = "17px";
|
||||||
|
|||||||
@ -83,7 +83,14 @@ define([
|
|||||||
|
|
||||||
// get the total stored size of a channel's patches (in bytes)
|
// get the total stored size of a channel's patches (in bytes)
|
||||||
exp.getFileSize = function (file, cb) {
|
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
|
// get the combined size of all channels (in bytes) for all the
|
||||||
@ -93,6 +100,8 @@ define([
|
|||||||
if (e) { return void cb(e); }
|
if (e) { return void cb(e); }
|
||||||
if (response && response.length) {
|
if (response && response.length) {
|
||||||
cb(void 0, response[0]);
|
cb(void 0, response[0]);
|
||||||
|
} else {
|
||||||
|
cb('INVALID_RESPONSE');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1876,12 +1876,10 @@ define([
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var getProperties = function (el) {
|
var getProperties = function (el, cb) {
|
||||||
/* TODO...
|
if (!filesOp.isFile(el)) {
|
||||||
if we make this async, we can include an RPC call to the server which tells us
|
return void cb('NOT_FILE');
|
||||||
the size of the pinned file (if it is pinned) */
|
}
|
||||||
|
|
||||||
if (!filesOp.isFile(el)) { return; }
|
|
||||||
var ro = filesOp.isReadOnlyFile(el);
|
var ro = filesOp.isReadOnlyFile(el);
|
||||||
var base = window.location.origin;
|
var base = window.location.origin;
|
||||||
var $d = $('<div>');
|
var $d = $('<div>');
|
||||||
@ -1889,14 +1887,50 @@ the size of the pinned file (if it is pinned) */
|
|||||||
$('<br>').appendTo($d);
|
$('<br>').appendTo($d);
|
||||||
if (!ro) {
|
if (!ro) {
|
||||||
$('<label>', {'for': 'propLink'}).text(Messages.editShare).appendTo($d);
|
$('<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);
|
var roLink = ro ? base + el : getReadOnlyUrl(base + el);
|
||||||
if (roLink) {
|
if (roLink) {
|
||||||
$('<label>', {'for': 'propROLink'}).text(Messages.viewShare).appendTo($d);
|
$('<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) {
|
$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")) {
|
else if ($(this).hasClass("properties")) {
|
||||||
if (paths.length !== 1) { return; }
|
if (paths.length !== 1) { return; }
|
||||||
var el = filesOp.find(paths[0].path);
|
var el = filesOp.find(paths[0].path);
|
||||||
var prop = getProperties(el);
|
getProperties(el, function (e, $prop) {
|
||||||
Cryptpad.alert('', undefined, true);
|
if (e) { return void console.error(e); }
|
||||||
$('.alertify .msg').html(prop);
|
Cryptpad.alert('', undefined, true);
|
||||||
$('#propLink').click(function () { $(this).select(); });
|
$('.alertify .msg').html("").append($prop);
|
||||||
$('#propROLink').click(function () { $(this).select(); });
|
});
|
||||||
}
|
}
|
||||||
module.hideMenu();
|
module.hideMenu();
|
||||||
});
|
});
|
||||||
@ -1984,11 +2018,11 @@ the size of the pinned file (if it is pinned) */
|
|||||||
else if ($(this).hasClass("properties")) {
|
else if ($(this).hasClass("properties")) {
|
||||||
if (paths.length !== 1) { return; }
|
if (paths.length !== 1) { return; }
|
||||||
var el = filesOp.find(paths[0].path);
|
var el = filesOp.find(paths[0].path);
|
||||||
var prop = getProperties(el);
|
getProperties(el, function (e, $prop) {
|
||||||
Cryptpad.alert('', undefined, true);
|
if (e) { return void console.error(e); }
|
||||||
$('.alertify .msg').html(prop);
|
Cryptpad.alert('', undefined, true);
|
||||||
$('#propLink').click(function () { $(this).select(); });
|
$('.alertify .msg').html("").append($prop);
|
||||||
$('#propROLink').click(function () { $(this).select(); });
|
});
|
||||||
}
|
}
|
||||||
module.hideMenu();
|
module.hideMenu();
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user