Don't store a pad in the drive if the limit has been reached
This commit is contained in:
@@ -570,8 +570,16 @@ define([
|
||||
|
||||
if (!contains) {
|
||||
var data = makePad(href, name);
|
||||
getStore().pushData(data);
|
||||
getStore().addPad(data, common.initialPath);
|
||||
getStore().pushData(data, function (e, state) {
|
||||
if (e) {
|
||||
if (e === 'E_OVER_LIMIT') {
|
||||
Cryptpad.alert(Messages.pinLimitNotPinned, null, true);
|
||||
return;
|
||||
}
|
||||
else { throw new Error("Cannot push this pad to CryptDrive", e); }
|
||||
}
|
||||
getStore().addPad(data, common.initialPath);
|
||||
});
|
||||
}
|
||||
if (updateWeaker.length > 0) {
|
||||
updateWeaker.forEach(function (obj) {
|
||||
@@ -709,7 +717,23 @@ define([
|
||||
};
|
||||
|
||||
var getPinLimit = common.getPinLimit = function (cb) {
|
||||
cb(void 0, 10);
|
||||
cb(void 0, 1000);
|
||||
};
|
||||
|
||||
var isOverPinLimit = common.isOverPinLimit = function (cb) {
|
||||
var andThen = function (e, limit) {
|
||||
if (e) { return void cb(e); }
|
||||
if (usage > limit) {
|
||||
return void cb (null, true);
|
||||
}
|
||||
return void cb (null, false);
|
||||
};
|
||||
var todo = function (e, used) {
|
||||
usage = common.bytesToMegabytes(used);
|
||||
if (e) { return void cb(e); }
|
||||
common.getPinLimit(andThen);
|
||||
};
|
||||
common.getPinnedUsage(todo);
|
||||
};
|
||||
|
||||
var createButton = common.createButton = function (type, rightside, data, callback) {
|
||||
|
||||
@@ -497,19 +497,15 @@ define([
|
||||
'class': LIMIT_ELEM_CLS,
|
||||
'title': Messages.pinLimitReached
|
||||
}).append($limitIcon).hide().appendTo($userContainer);
|
||||
var andThen = function (e, limit) {
|
||||
if (usage > limit) {
|
||||
var todo = function (e, overLimit) {
|
||||
if (e) { return void console.error("Unable tog et the pinned usage"); }
|
||||
if (overLimit) {
|
||||
$limit.show().click(function () {
|
||||
Cryptpad.alert(Messages.pinLimitReachedAlert, null, true);
|
||||
});
|
||||
}
|
||||
};
|
||||
var todo = function (e, used) {
|
||||
usage = Cryptpad.bytesToMegabytes(used);
|
||||
if (e) { console.error("Unable tog et the pinned usage"); return; }
|
||||
Cryptpad.getPinLimit(andThen);
|
||||
};
|
||||
Cryptpad.getPinnedUsage(todo);
|
||||
Cryptpad.isOverPinLimit(todo);
|
||||
}
|
||||
|
||||
if (config.displayed.indexOf('newpad') !== -1) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
define([
|
||||
'jquery',
|
||||
], function ($) {
|
||||
'/customize/application_config.js'
|
||||
], function ($, AppConfig) {
|
||||
var module = {};
|
||||
|
||||
var ROOT = module.ROOT = "root";
|
||||
@@ -427,19 +428,25 @@ define([
|
||||
};
|
||||
|
||||
// FILES DATA
|
||||
var pushFileData = exp.pushData = function (data) {
|
||||
var pushFileData = exp.pushData = function (data, cb) {
|
||||
if (typeof cb !== "function") { cb = function () {}; }
|
||||
var todo = function () {
|
||||
files[FILES_DATA].push(data);
|
||||
cb();
|
||||
};
|
||||
if (!Cryptpad.isLoggedIn() || !AppConfig.enablePinning) { todo(); }
|
||||
Cryptpad.pinPads([Cryptpad.hrefToHexChannelId(data.href)], function (e, hash) {
|
||||
if (e) { console.log(e); return; }
|
||||
console.log(hash);
|
||||
if (e) { return void cb(e); }
|
||||
cb('E_OVER_LIMIT'); return; //TODO
|
||||
todo();
|
||||
});
|
||||
files[FILES_DATA].push(data);
|
||||
};
|
||||
var spliceFileData = exp.removeData = function (idx) {
|
||||
var data = files[FILES_DATA][idx];
|
||||
if (typeof data === "object") {
|
||||
if (typeof data === "object" && Cryptpad.isLoggedIn() && AppConfig.enablePinning) {
|
||||
Cryptpad.unpinPads([Cryptpad.hrefToHexChannelId(data.href)], function (e, hash) {
|
||||
if (e) { console.log(e); return; }
|
||||
console.log(hash);
|
||||
if (e) { return void logError(e); }
|
||||
debug('UNPIN', hash);
|
||||
});
|
||||
}
|
||||
files[FILES_DATA].splice(idx, 1);
|
||||
|
||||
Reference in New Issue
Block a user