Don't store a pad in the drive if the limit has been reached
This commit is contained in:
parent
bf7c7c45d0
commit
a165332c15
11 changed files with 58 additions and 26 deletions
|
@ -162,6 +162,7 @@
|
||||||
font-size: 20px;
|
font-size: 20px;
|
||||||
}
|
}
|
||||||
.cryptpad-toolbar .cryptpad-limit span {
|
.cryptpad-toolbar .cryptpad-limit span {
|
||||||
|
cursor: pointer;
|
||||||
margin: auto;
|
margin: auto;
|
||||||
}
|
}
|
||||||
.cryptpad-toolbar .cryptpad-lag {
|
.cryptpad-toolbar .cryptpad-lag {
|
||||||
|
|
|
@ -56,8 +56,10 @@ define(function () {
|
||||||
out.redLight = "Vous êtes déconnectés de la session";
|
out.redLight = "Vous êtes déconnectés de la session";
|
||||||
|
|
||||||
out.pinLimitReached = "Vous avez atteint votre limite de stockage";
|
out.pinLimitReached = "Vous avez atteint votre limite de stockage";
|
||||||
out.pinLimitReachedAlert = "Vous avez atteint votre limite de stockage. Ce pad ne sera pas enregistré dans votre CrypDrive.<br>" +
|
out.pinLimitReachedAlert = "Vous avez atteint votre limite de stockage. Les nouveaux pads ne seront pas enregistrés dans votre CrypDrive.<br>" +
|
||||||
"Pour résoudre ce problème, vous pouvez soit supprimer des pads de votre CryptDrive (y compris la corbeille), soit vous abonner à une offre premium pour augmenter la limite maximale.";
|
"Pour résoudre ce problème, vous pouvez soit supprimer des pads de votre CryptDrive (y compris la corbeille), soit vous abonner à une offre premium pour augmenter la limite maximale.";
|
||||||
|
out.pinLimitNotPinned = "Vous avez atteint votre limite de stockage.<br>"+
|
||||||
|
"Ce pad n'est pas enregistré dans votre CryptDrive.";
|
||||||
|
|
||||||
out.importButtonTitle = 'Importer un pad depuis un fichier local';
|
out.importButtonTitle = 'Importer un pad depuis un fichier local';
|
||||||
|
|
||||||
|
|
|
@ -58,8 +58,10 @@ define(function () {
|
||||||
out.redLight = "You are disconnected from the session";
|
out.redLight = "You are disconnected from the session";
|
||||||
|
|
||||||
out.pinLimitReached = "You've reached your storage limit";
|
out.pinLimitReached = "You've reached your storage limit";
|
||||||
out.pinLimitReachedAlert = "You've reached your storage limit. This pad won't be stored in your CryptDrive.<br>" +
|
out.pinLimitReachedAlert = "You've reached your storage limit. New pads won't be stored in your CryptDrive.<br>" +
|
||||||
"To fix this problem, you can either remove pads from your CryptDrive (including the trash) or subscribe to a premium offer to increase your limit.";
|
"To fix this problem, you can either remove pads from your CryptDrive (including the trash) or subscribe to a premium offer to increase your limit.";
|
||||||
|
out.pinLimitNotPinned = "You've reached your storage limit.<br>"+
|
||||||
|
"This pad is not stored in your CryptDrive.";
|
||||||
|
|
||||||
out.importButtonTitle = 'Import a pad from a local file';
|
out.importButtonTitle = 'Import a pad from a local file';
|
||||||
|
|
||||||
|
|
|
@ -570,8 +570,16 @@ define([
|
||||||
|
|
||||||
if (!contains) {
|
if (!contains) {
|
||||||
var data = makePad(href, name);
|
var data = makePad(href, name);
|
||||||
getStore().pushData(data);
|
getStore().pushData(data, function (e, state) {
|
||||||
getStore().addPad(data, common.initialPath);
|
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) {
|
if (updateWeaker.length > 0) {
|
||||||
updateWeaker.forEach(function (obj) {
|
updateWeaker.forEach(function (obj) {
|
||||||
|
@ -709,7 +717,23 @@ define([
|
||||||
};
|
};
|
||||||
|
|
||||||
var getPinLimit = common.getPinLimit = function (cb) {
|
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) {
|
var createButton = common.createButton = function (type, rightside, data, callback) {
|
||||||
|
|
|
@ -497,19 +497,15 @@ define([
|
||||||
'class': LIMIT_ELEM_CLS,
|
'class': LIMIT_ELEM_CLS,
|
||||||
'title': Messages.pinLimitReached
|
'title': Messages.pinLimitReached
|
||||||
}).append($limitIcon).hide().appendTo($userContainer);
|
}).append($limitIcon).hide().appendTo($userContainer);
|
||||||
var andThen = function (e, limit) {
|
var todo = function (e, overLimit) {
|
||||||
if (usage > limit) {
|
if (e) { return void console.error("Unable tog et the pinned usage"); }
|
||||||
|
if (overLimit) {
|
||||||
$limit.show().click(function () {
|
$limit.show().click(function () {
|
||||||
Cryptpad.alert(Messages.pinLimitReachedAlert, null, true);
|
Cryptpad.alert(Messages.pinLimitReachedAlert, null, true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
var todo = function (e, used) {
|
Cryptpad.isOverPinLimit(todo);
|
||||||
usage = Cryptpad.bytesToMegabytes(used);
|
|
||||||
if (e) { console.error("Unable tog et the pinned usage"); return; }
|
|
||||||
Cryptpad.getPinLimit(andThen);
|
|
||||||
};
|
|
||||||
Cryptpad.getPinnedUsage(todo);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.displayed.indexOf('newpad') !== -1) {
|
if (config.displayed.indexOf('newpad') !== -1) {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
define([
|
define([
|
||||||
'jquery',
|
'jquery',
|
||||||
], function ($) {
|
'/customize/application_config.js'
|
||||||
|
], function ($, AppConfig) {
|
||||||
var module = {};
|
var module = {};
|
||||||
|
|
||||||
var ROOT = module.ROOT = "root";
|
var ROOT = module.ROOT = "root";
|
||||||
|
@ -427,19 +428,25 @@ define([
|
||||||
};
|
};
|
||||||
|
|
||||||
// FILES DATA
|
// 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) {
|
Cryptpad.pinPads([Cryptpad.hrefToHexChannelId(data.href)], function (e, hash) {
|
||||||
if (e) { console.log(e); return; }
|
if (e) { return void cb(e); }
|
||||||
console.log(hash);
|
cb('E_OVER_LIMIT'); return; //TODO
|
||||||
|
todo();
|
||||||
});
|
});
|
||||||
files[FILES_DATA].push(data);
|
|
||||||
};
|
};
|
||||||
var spliceFileData = exp.removeData = function (idx) {
|
var spliceFileData = exp.removeData = function (idx) {
|
||||||
var data = files[FILES_DATA][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) {
|
Cryptpad.unpinPads([Cryptpad.hrefToHexChannelId(data.href)], function (e, hash) {
|
||||||
if (e) { console.log(e); return; }
|
if (e) { return void logError(e); }
|
||||||
console.log(hash);
|
debug('UNPIN', hash);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
files[FILES_DATA].splice(idx, 1);
|
files[FILES_DATA].splice(idx, 1);
|
||||||
|
|
|
@ -2392,7 +2392,7 @@ define([
|
||||||
|
|
||||||
var userList = APP.userList = info.userList;
|
var userList = APP.userList = info.userList;
|
||||||
var config = {
|
var config = {
|
||||||
displayed: ['useradmin', 'spinner', 'lag', 'state'],
|
displayed: ['useradmin', 'spinner', 'lag', 'state', 'limit'],
|
||||||
readOnly: readOnly,
|
readOnly: readOnly,
|
||||||
ifrw: window,
|
ifrw: window,
|
||||||
common: Cryptpad,
|
common: Cryptpad,
|
||||||
|
|
|
@ -578,7 +578,7 @@ define([
|
||||||
userList = info.userList;
|
userList = info.userList;
|
||||||
|
|
||||||
var configTb = {
|
var configTb = {
|
||||||
displayed: ['useradmin', 'spinner', 'lag', 'state', 'share', 'userlist', 'newpad'],
|
displayed: ['useradmin', 'spinner', 'lag', 'state', 'share', 'userlist', 'newpad', 'limit'],
|
||||||
userData: userData,
|
userData: userData,
|
||||||
readOnly: readOnly,
|
readOnly: readOnly,
|
||||||
ifrw: ifrw,
|
ifrw: ifrw,
|
||||||
|
|
|
@ -733,7 +733,7 @@ define([
|
||||||
userList = APP.userList = info.userList;
|
userList = APP.userList = info.userList;
|
||||||
|
|
||||||
var config = {
|
var config = {
|
||||||
displayed: ['useradmin', 'spinner', 'lag', 'state', 'share', 'userlist', 'newpad'],
|
displayed: ['useradmin', 'spinner', 'lag', 'state', 'share', 'userlist', 'newpad', 'limit'],
|
||||||
userData: userData,
|
userData: userData,
|
||||||
readOnly: readOnly,
|
readOnly: readOnly,
|
||||||
share: {
|
share: {
|
||||||
|
|
|
@ -513,7 +513,7 @@ define([
|
||||||
userList = info.userList;
|
userList = info.userList;
|
||||||
|
|
||||||
var configTb = {
|
var configTb = {
|
||||||
displayed: ['useradmin', 'spinner', 'lag', 'state', 'share', 'userlist', 'newpad'],
|
displayed: ['useradmin', 'spinner', 'lag', 'state', 'share', 'userlist', 'newpad', 'limit'],
|
||||||
userData: userData,
|
userData: userData,
|
||||||
readOnly: readOnly,
|
readOnly: readOnly,
|
||||||
ifrw: ifrw,
|
ifrw: ifrw,
|
||||||
|
|
|
@ -334,7 +334,7 @@ window.canvas = canvas;
|
||||||
var onInit = config.onInit = function (info) {
|
var onInit = config.onInit = function (info) {
|
||||||
userList = info.userList;
|
userList = info.userList;
|
||||||
var config = {
|
var config = {
|
||||||
displayed: ['useradmin', 'spinner', 'lag', 'state', 'share', 'userlist', 'newpad'],
|
displayed: ['useradmin', 'spinner', 'lag', 'state', 'share', 'userlist', 'newpad', 'limit'],
|
||||||
userData: userData,
|
userData: userData,
|
||||||
readOnly: readOnly,
|
readOnly: readOnly,
|
||||||
share: {
|
share: {
|
||||||
|
|
Loading…
Reference in a new issue