Merge branch 'staging' into newDrive
This commit is contained in:
@@ -7,7 +7,9 @@ define([], function () {
|
||||
// jquery declares itself as literally "jquery" so it cannot be pulled by path :(
|
||||
"jquery": "/bower_components/jquery/dist/jquery.min",
|
||||
// json.sortify same
|
||||
"json.sortify": "/bower_components/json.sortify/dist/JSON.sortify"
|
||||
"json.sortify": "/bower_components/json.sortify/dist/JSON.sortify",
|
||||
"pdfjs-dist/build/pdf": "/bower_components/pdfjs-dist/build/pdf",
|
||||
"pdfjs-dist/build/pdf.worker": "/bower_components/pdfjs-dist/build/pdf.worker"
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -194,10 +194,17 @@ define([
|
||||
};
|
||||
UI.removeLoadingScreen = function (cb) {
|
||||
$('#' + LOADING).fadeOut(750, cb);
|
||||
$('#loadingTip').css('top', '');
|
||||
window.setTimeout(function () {
|
||||
$('#loadingTip').fadeOut(750);
|
||||
}, 3000);
|
||||
var $tip = $('#loadingTip').css('top', '')
|
||||
// loading.less sets transition-delay: $wait-time
|
||||
// and transition: opacity $fadeout-time
|
||||
.css({
|
||||
'opacity': 0,
|
||||
'pointer-events': 'none',
|
||||
});
|
||||
setTimeout(function () {
|
||||
$tip.remove();
|
||||
}, 3750);
|
||||
// jquery.fadeout can get stuck
|
||||
};
|
||||
UI.errorLoadingScreen = function (error, transparent) {
|
||||
if (!$('#' + LOADING).is(':visible')) { UI.addLoadingScreen(undefined, true); }
|
||||
|
||||
@@ -25,7 +25,10 @@ define([
|
||||
*/
|
||||
var common = window.Cryptpad = {
|
||||
Messages: Messages,
|
||||
Clipboard: Clipboard
|
||||
Clipboard: Clipboard,
|
||||
donateURL: 'https://accounts.cryptpad.fr/#/donate?on=' + window.location.hostname,
|
||||
upgradeURL: 'https://accounts.cryptpad.fr/#/?on=' + window.location.hostname,
|
||||
account: {},
|
||||
};
|
||||
|
||||
// constants
|
||||
@@ -216,6 +219,7 @@ define([
|
||||
userNameKey,
|
||||
userHashKey,
|
||||
'loginToken',
|
||||
'plan',
|
||||
].forEach(function (k) {
|
||||
sessionStorage.removeItem(k);
|
||||
localStorage.removeItem(k);
|
||||
@@ -244,6 +248,11 @@ define([
|
||||
var getUserHash = common.getUserHash = function () {
|
||||
var hash = localStorage[userHashKey];
|
||||
|
||||
if (['undefined', 'undefined/'].indexOf(hash) !== -1) {
|
||||
localStorage.removeItem(userHashKey);
|
||||
return;
|
||||
}
|
||||
|
||||
if (hash) {
|
||||
var sHash = common.serializeHash(hash);
|
||||
if (sHash !== hash) { localStorage[userHashKey] = sHash; }
|
||||
@@ -575,7 +584,7 @@ define([
|
||||
var data = makePad(href, name);
|
||||
getStore().pushData(data, function (e, id) {
|
||||
if (e) {
|
||||
if (e === 'E_OVER_LIMIT' && AppConfig.enablePinLimit) {
|
||||
if (e === 'E_OVER_LIMIT') {
|
||||
common.alert(Messages.pinLimitNotPinned, null, true);
|
||||
return;
|
||||
}
|
||||
@@ -741,7 +750,7 @@ define([
|
||||
};
|
||||
|
||||
common.isOverPinLimit = function (cb) {
|
||||
if (!common.isLoggedIn() || !AppConfig.enablePinLimit) { return void cb(null, false); }
|
||||
if (!common.isLoggedIn()) { return void cb(null, false); }
|
||||
var usage;
|
||||
var andThen = function (e, limit, plan) {
|
||||
if (e) { return void cb(e); }
|
||||
@@ -775,7 +784,6 @@ define([
|
||||
};
|
||||
|
||||
var LIMIT_REFRESH_RATE = 30000; // milliseconds
|
||||
var limitReachedDisplayed = false;
|
||||
common.createUsageBar = function (cb, alwaysDisplayUpgrade) {
|
||||
var todo = function (err, state, data) {
|
||||
var $container = $('<span>', {'class':'limit-container'});
|
||||
@@ -797,7 +805,10 @@ define([
|
||||
var width = Math.floor(Math.min(quota, 1)*200); // the bar is 200px width
|
||||
var $usage = $('<span>', {'class': 'usage'}).css('width', width+'px');
|
||||
|
||||
if ((quota >= 0.8 || alwaysDisplayUpgrade) && data.plan !== "power") {
|
||||
if (Config.noSubscriptionButton !== true &&
|
||||
(quota >= 0.8 || alwaysDisplayUpgrade) &&
|
||||
data.plan !== "power")
|
||||
{
|
||||
var origin = encodeURIComponent(window.location.hostname);
|
||||
var $upgradeLink = $('<a>', {
|
||||
href: "https://accounts.cryptpad.fr/#!on=" + origin,
|
||||
@@ -823,13 +834,7 @@ define([
|
||||
|
||||
if (quota < 0.8) { $usage.addClass('normal'); }
|
||||
else if (quota < 1) { $usage.addClass('warning'); }
|
||||
else {
|
||||
$usage.addClass('above');
|
||||
if (!limitReachedDisplayed) {
|
||||
limitReachedDisplayed = true;
|
||||
common.alert(Messages._getKey('pinAboveLimitAlert', [prettyUsage, encodeURIComponent(window.location.hostname)]), null, true);
|
||||
}
|
||||
}
|
||||
else { $usage.addClass('above'); }
|
||||
var $text = $('<span>', {'class': 'usageText'});
|
||||
$text.text(usage + ' / ' + prettyLimit);
|
||||
$limit.append($usage).append($text);
|
||||
@@ -1405,6 +1410,14 @@ define([
|
||||
console.log('RPC handshake complete');
|
||||
rpc = common.rpc = env.rpc = call;
|
||||
|
||||
common.getPinLimit(function (e, limit, plan, note) {
|
||||
if (e) { return void console.error(e); }
|
||||
common.account.limit = limit;
|
||||
localStorage.plan = common.account.plan = plan;
|
||||
common.account.note = note;
|
||||
cb();
|
||||
});
|
||||
|
||||
common.arePinsSynced(function (err, yes) {
|
||||
if (!yes) {
|
||||
common.resetPins(function (err) {
|
||||
@@ -1413,7 +1426,6 @@ define([
|
||||
});
|
||||
}
|
||||
});
|
||||
cb();
|
||||
});
|
||||
} else if (PINNING_ENABLED) {
|
||||
console.log('not logged in. pads will not be pinned');
|
||||
|
||||
@@ -170,6 +170,10 @@ define([
|
||||
proxy[tokenKey] = Math.floor(Math.random()*Number.MAX_SAFE_INTEGER);
|
||||
}
|
||||
|
||||
// copy User_hash into sessionStorage because cross-domain iframes
|
||||
// on safari replaces localStorage with sessionStorage or something
|
||||
if (sessionStorage) { sessionStorage.setItem('User_hash', localStorage.getItem('User_hash')); }
|
||||
|
||||
var localToken = tryParsing(localStorage.getItem(tokenKey));
|
||||
if (localToken === null) {
|
||||
// if that number hasn't been set to localStorage, do so.
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -92,8 +92,8 @@ define([
|
||||
exp.getFileSize = function (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]);
|
||||
if (response && response.length && typeof(response[0]) === 'number') {
|
||||
return void cb(void 0, response[0]);
|
||||
} else {
|
||||
cb('INVALID_RESPONSE');
|
||||
}
|
||||
|
||||
@@ -27,7 +27,11 @@ types of messages:
|
||||
var hkn = network.historyKeeper;
|
||||
var txid = uid();
|
||||
|
||||
ctx.pending[txid] = cb;
|
||||
var pending = ctx.pending[txid] = function (err, response) {
|
||||
cb(err, response);
|
||||
};
|
||||
pending.data = data;
|
||||
pending.called = 0;
|
||||
return network.sendto(hkn, JSON.stringify([txid, data]));
|
||||
};
|
||||
|
||||
@@ -60,7 +64,22 @@ types of messages:
|
||||
|
||||
if (typeof(pending) === 'function') {
|
||||
if (parsed[1] === 'ERROR') {
|
||||
return void pending(parsed[2]);
|
||||
if (parsed[2] === 'NO_COOKIE') {
|
||||
return void ctx.send('COOKIE', "", function (e) {
|
||||
if (e) {
|
||||
console.error(e);
|
||||
return void pending(e);
|
||||
}
|
||||
|
||||
// resend the same command again
|
||||
// give up if you've already tried resending
|
||||
if (ctx.resend(txid)) { delete ctx.pending[txid]; }
|
||||
});
|
||||
}
|
||||
|
||||
pending(parsed[2]);
|
||||
delete ctx.pending[txid];
|
||||
return;
|
||||
} else {
|
||||
// update the cookie
|
||||
if (/\|/.test(cookie)) {
|
||||
@@ -70,8 +89,13 @@ types of messages:
|
||||
}
|
||||
}
|
||||
pending(void 0, response);
|
||||
|
||||
// if successful, delete the callback...
|
||||
delete ctx.pending[txid];
|
||||
}
|
||||
else {
|
||||
console.log("received message for txid with no callback");
|
||||
}
|
||||
//else { console.log("No callback provided"); }
|
||||
};
|
||||
|
||||
var create = function (network, edPrivateKey, edPublicKey, cb) {
|
||||
@@ -104,7 +128,7 @@ types of messages:
|
||||
connected: true,
|
||||
};
|
||||
|
||||
var send = function (type, msg, cb) {
|
||||
var send = ctx.send = function (type, msg, cb) {
|
||||
if (!ctx.connected && type !== 'COOKIE') {
|
||||
return void window.setTimeout(function () {
|
||||
cb('DISCONNECTED');
|
||||
@@ -129,6 +153,44 @@ types of messages:
|
||||
return sendMsg(ctx, data, cb);
|
||||
};
|
||||
|
||||
ctx.resend = function (txid) {
|
||||
var pending = ctx.pending[txid];
|
||||
if (pending.called) {
|
||||
console.error("[%s] called too many times", txid);
|
||||
return true;
|
||||
}
|
||||
pending.called++;
|
||||
|
||||
// update the cookie and signature...
|
||||
pending.data[2] = ctx.cookie;
|
||||
pending.data[0] = signMsg(pending.data.slice(2), signKey);
|
||||
try {
|
||||
return ctx.network.sendto(ctx.network.historyKeeper,
|
||||
JSON.stringify([txid, pending.data]));
|
||||
} catch (e) {
|
||||
console.log("failed to resend");
|
||||
console.error(e);
|
||||
}
|
||||
};
|
||||
|
||||
send.unauthenticated = function (type, msg, cb) {
|
||||
if (!ctx.connected) {
|
||||
return void window.setTimeout(function () {
|
||||
cb('DISCONNECTED');
|
||||
});
|
||||
}
|
||||
|
||||
// construct an unsigned message
|
||||
var data = [null, edPublicKey, null, type, msg];
|
||||
if (ctx.cookie && ctx.cookie.join) {
|
||||
data[2] = ctx.cookie.join('|');
|
||||
} else {
|
||||
data[2] = ctx.cookie;
|
||||
}
|
||||
|
||||
return sendMsg(ctx, data, cb);
|
||||
};
|
||||
|
||||
network.on('message', function (msg) {
|
||||
onMsg(ctx, msg);
|
||||
});
|
||||
|
||||
75
www/common/test.js
Normal file
75
www/common/test.js
Normal file
@@ -0,0 +1,75 @@
|
||||
define([], function () {
|
||||
var out = function () { };
|
||||
out.passed = out.failed = out;
|
||||
if (window.location.hash.indexOf("?test=test") > -1) {
|
||||
var cpt = window.__CRYPTPAD_TEST__ = {
|
||||
data: [],
|
||||
getData: function () {
|
||||
var data = JSON.stringify(cpt.data);
|
||||
cpt.data = [];
|
||||
return data;
|
||||
}
|
||||
};
|
||||
|
||||
// jshint -W103
|
||||
var errProto = (new Error()).__proto__;
|
||||
var doLog = function (o) {
|
||||
var s;
|
||||
if (typeof(o) === 'object' && o.__proto__ === errProto) {
|
||||
s = JSON.stringify([ o.message, o.stack ]);
|
||||
} else if (typeof(s) !== 'string') {
|
||||
try {
|
||||
s = JSON.stringify(o);
|
||||
} catch (e) {
|
||||
s = String(o);
|
||||
}
|
||||
}
|
||||
var out = [s];
|
||||
try { throw new Error(); } catch (e) { out.push(e.stack.split('\n')[3]); }
|
||||
cpt.data.push({ type: 'log', val: out.join('') });
|
||||
};
|
||||
|
||||
window.console._error = window.console.error;
|
||||
window.console._log = window.console.log;
|
||||
window.console.error = function (e) { window.console._error(e); doLog(e); };
|
||||
window.console.log = function (l) { window.console._log(l); doLog(l); };
|
||||
|
||||
window.onerror = function (msg, url, lineNo, columnNo, e) {
|
||||
cpt.data.push({
|
||||
type: 'report',
|
||||
val: 'failed',
|
||||
error: {
|
||||
message: e ? e.message : msg,
|
||||
stack: e ? e.stack : (url + ":" + lineNo)
|
||||
}
|
||||
});
|
||||
};
|
||||
require.onError = function (e) {
|
||||
cpt.data.push({
|
||||
type: 'report',
|
||||
val: 'failed',
|
||||
error: { message: e.message, stack: e.stack }
|
||||
});
|
||||
};
|
||||
out = function (f) { f(); };
|
||||
out.testing = true;
|
||||
out.passed = function () {
|
||||
cpt.data.push({
|
||||
type: 'report',
|
||||
val: 'passed'
|
||||
});
|
||||
};
|
||||
out.failed = function (reason) {
|
||||
var e;
|
||||
try { throw new Error(reason); } catch (err) { e = err; }
|
||||
cpt.data.push({
|
||||
type: 'report',
|
||||
val: 'failed',
|
||||
error: { message: e.message, stack: e.stack }
|
||||
});
|
||||
};
|
||||
} else {
|
||||
out.testing = false;
|
||||
}
|
||||
return out;
|
||||
});
|
||||
@@ -500,8 +500,12 @@ define([
|
||||
var todo = function (e, overLimit) {
|
||||
if (e) { return void console.error("Unable to get the pinned usage"); }
|
||||
if (overLimit) {
|
||||
var message = Messages.pinLimitReachedAlert;
|
||||
if (ApiConfig.noSubscriptionButton === true) {
|
||||
message = Messages.pinLimitReachedAlertNoAccounts;
|
||||
}
|
||||
$limit.show().click(function () {
|
||||
Cryptpad.alert(Messages.pinLimitReachedAlert, null, true);
|
||||
Cryptpad.alert(message, null, true);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -10,7 +10,7 @@ define([
|
||||
constants: {},
|
||||
};
|
||||
|
||||
var SPINNER_DISAPPEAR_TIME = 3000;
|
||||
var SPINNER_DISAPPEAR_TIME = 1000;
|
||||
|
||||
// Toolbar parts
|
||||
var TOOLBAR_CLS = Bar.constants.toolbar = 'cryptpad-toolbar';
|
||||
@@ -33,6 +33,7 @@ define([
|
||||
var LIMIT_CLS = Bar.constants.lag = 'cryptpad-limit';
|
||||
var TITLE_CLS = Bar.constants.title = "cryptpad-title";
|
||||
var NEWPAD_CLS = Bar.constants.newpad = "cryptpad-newpad";
|
||||
var UPGRADE_CLS = Bar.constants.upgrade = "cryptpad-upgrade";
|
||||
|
||||
// User admin menu
|
||||
var USERADMIN_CLS = Bar.constants.user = 'cryptpad-user-dropdown';
|
||||
@@ -70,6 +71,7 @@ define([
|
||||
var $userContainer = $('<span>', {
|
||||
'class': USER_CLS
|
||||
}).appendTo($topContainer);
|
||||
$('<button>', {'class': UPGRADE_CLS + ' buttonSuccess'}).hide().appendTo($userContainer);
|
||||
$('<span>', {'class': SPINNER_CLS}).hide().appendTo($userContainer);
|
||||
$('<span>', {'class': STATE_CLS}).hide().appendTo($userContainer);
|
||||
$('<span>', {'class': LAG_CLS}).hide().appendTo($userContainer);
|
||||
@@ -595,7 +597,6 @@ define([
|
||||
'class': 'synced fa fa-check',
|
||||
title: Messages.synced
|
||||
}).appendTo($spin);
|
||||
toolbar.$userAdmin.prepend($spin);
|
||||
if (config.realtime) {
|
||||
config.realtime.onPatch(ks(toolbar, config));
|
||||
config.realtime.onMessage(ks(toolbar, config, true));
|
||||
@@ -616,8 +617,12 @@ define([
|
||||
var todo = function (e, overLimit) {
|
||||
if (e) { return void console.error("Unable to get the pinned usage"); }
|
||||
if (overLimit) {
|
||||
var key = 'pinLimitReachedAlert';
|
||||
if (ApiConfig.noSubscriptionButton === true) {
|
||||
key = 'pinLimitReachedAlertNoAccounts';
|
||||
}
|
||||
$limit.show().click(function () {
|
||||
Cryptpad.alert(Messages._getKey('pinLimitReachedAlert', [encodeURIComponent(window.location.hostname)]), null, true);
|
||||
Cryptpad.alert(Messages._getKey(key, [encodeURIComponent(window.location.hostname)]), null, true);
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -631,6 +636,8 @@ define([
|
||||
var pads_options = [];
|
||||
Config.availablePadTypes.forEach(function (p) {
|
||||
if (p === 'drive') { return; }
|
||||
if (!Cryptpad.isLoggedIn() && Config.registeredOnlyTypes &&
|
||||
Config.registeredOnlyTypes.indexOf(p) !== -1) { return; }
|
||||
pads_options.push({
|
||||
tag: 'a',
|
||||
attributes: {
|
||||
@@ -692,6 +699,33 @@ define([
|
||||
return $userAdmin;
|
||||
};
|
||||
|
||||
var createUpgrade = function (toolbar) {
|
||||
if (ApiConfig.removeDonateButton) { return; }
|
||||
if (Cryptpad.account.plan) { return; }
|
||||
|
||||
var text;
|
||||
var feedback;
|
||||
var url;
|
||||
if (ApiConfig.allowSubscriptions && Cryptpad.isLoggedIn()) {
|
||||
text = Messages.upgradeAccount;
|
||||
feedback = "UPGRADE_ACCOUNT";
|
||||
url = Cryptpad.upgradeURL;
|
||||
} else {
|
||||
text = Messages.supportCryptpad;
|
||||
feedback = "SUPPORT_CRYPTPAD";
|
||||
url = Cryptpad.donateURL;
|
||||
}
|
||||
|
||||
var $upgrade = toolbar.$top.find('.' + UPGRADE_CLS).attr({
|
||||
'title': Messages.supportCryptpad
|
||||
}).text(text).show()
|
||||
.click(function () {
|
||||
Cryptpad.feedback(feedback);
|
||||
window.open(url,'_blank');
|
||||
});
|
||||
return $upgrade;
|
||||
};
|
||||
|
||||
// Events
|
||||
var initClickEvents = function (toolbar, config) {
|
||||
var removeDropdowns = function () {
|
||||
@@ -849,10 +883,10 @@ define([
|
||||
tb['spinner'] = createSpinner;
|
||||
tb['state'] = createState;
|
||||
tb['limit'] = createLimit;
|
||||
tb['upgrade'] = createUpgrade;
|
||||
tb['newpad'] = createNewPad;
|
||||
tb['useradmin'] = createUserAdmin;
|
||||
|
||||
|
||||
var addElement = toolbar.addElement = function (arr, additionnalCfg, init) {
|
||||
if (typeof additionnalCfg === "object") { $.extend(true, config, additionnalCfg); }
|
||||
arr.forEach(function (el) {
|
||||
|
||||
Reference in New Issue
Block a user