From b281d51d90774a2280bb9b3a135cf55d6d044937 Mon Sep 17 00:00:00 2001 From: yflory Date: Tue, 23 May 2017 15:04:18 +0200 Subject: [PATCH 01/15] Fix typos in the french translation --- customize.dist/translations/messages.fr.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/customize.dist/translations/messages.fr.js b/customize.dist/translations/messages.fr.js index 576e0d403..a112d397e 100644 --- a/customize.dist/translations/messages.fr.js +++ b/customize.dist/translations/messages.fr.js @@ -389,15 +389,15 @@ define(function () { out.main_zeroKnowledge_p = "Vous n'avez pas besoin de croire que nous n'allons pas regarder vos pads. Avec la technologie Zero Knowledge de CryptPad, nous ne pouvons pas le faire. Apprenez-en plus sur notre manière de protéger vos données."; out.main_writeItDown = 'Prenez-en note'; out.main_writeItDown_p = "Les plus grands projets naissent des plus petites idées. Prenez note de vos moments d'inspiration et de vos idées inattendues car vous ne savez pas lesquels seront des découvertes capitales."; - out.main_share = 'Partager le lien, partager le pad'; - out.main_share_p = "Faites croître vos idées à plusieurs : réalisez des réunions efficaes, collaborez sur vos listes de tâches et réalisez des présentations rapide avec tous vos amis sur tous vos appareils."; - out.main_organize = 'Soyez organisés'; - out.main_organize_p = "Avec le CryptPad Drive, vous pouvez garder vos vues sur ce qui est important. Les dossiers vous permettent de garder la trace de vos projets et d'avoir une vision globale du travail effectué."; + out.main_share = 'Partagez le lien, partagez le pad'; + out.main_share_p = "Faites croître vos idées à plusieurs : réalisez des réunions efficaces, collaborez sur vos listes de tâches et réalisez des présentations rapides avec tous vos amis sur tous vos appareils."; + out.main_organize = 'Soyez organisé'; + out.main_organize_p = "Avec CryptDrive, vous pouvez garder vos vues sur ce qui est important. Les dossiers vous permettent de garder la trace de vos projets et d'avoir une vision globale du travail effectué."; out.tryIt = 'Essayez-le !'; out.main_richText = 'Éditeur de texte'; out.main_richText_p = 'Éditez des documents texte collaborativement avec notre application CkEditor temps-réel et Zero Knowledge.'; out.main_code = 'Éditeur de code'; - out.main_code_p = 'Modifier votre code collaborativement grâce à notre application CodeMirror temps-réel et Zero Knowledge.'; + out.main_code_p = 'Modifiez votre code collaborativement grâce à notre application CodeMirror temps-réel et Zero Knowledge.'; out.main_slide = 'Présentations'; out.main_slide_p = 'Créez vos présentations en syntaxe Markdown collaborativement de manière sécurisée et affichez les dans votre navigateur.'; out.main_poll = 'Sondages'; From 90f5713d4a053c634e6c76912b188dc5508a14b1 Mon Sep 17 00:00:00 2001 From: yflory Date: Tue, 23 May 2017 18:09:30 +0200 Subject: [PATCH 02/15] Fix an issue with the search bar redirecting to incorrect location --- www/drive/main.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/www/drive/main.js b/www/drive/main.js index 861136454..5343bd829 100644 --- a/www/drive/main.js +++ b/www/drive/main.js @@ -1771,7 +1771,8 @@ define([ if (parentPath) { $a = $('').text(Messages.fm_openParent).click(function (e) { e.preventDefault(); - parentPath.pop(); + if (filesOp.isInTrashRoot(parentPath)) { parentPath = [TRASH]; } + else { parentPath.pop(); } module.displayDirectory(parentPath); }); } @@ -1823,6 +1824,7 @@ define([ displayDirectory(parentPath, true); return; } + if (!isSearch) { delete APP.Search.oldLocation; } module.resetTree(); From dc80b6b11f102611cb48d6d792ee551f24bba165 Mon Sep 17 00:00:00 2001 From: ansuz Date: Wed, 24 May 2017 11:27:16 +0200 Subject: [PATCH 03/15] throttle markdown preview --- www/code/main.js | 9 ++++++--- www/common/common-util.js | 9 +++++++++ www/common/cryptpad-common.js | 1 + 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/www/code/main.js b/www/code/main.js index fa6ecf12b..660473ffd 100644 --- a/www/code/main.js +++ b/www/code/main.js @@ -110,6 +110,10 @@ define([ return stringify(obj); }; + var drawPreview = Cryptpad.throttle(function () { + DiffMd.apply(DiffMd.render(editor.getValue()), $preview); + }, 150); + var onLocal = config.onLocal = function () { if (initializing) { return; } if (isHistoryMode) { return; } @@ -117,7 +121,7 @@ define([ editor.save(); - DiffMd.apply(DiffMd.render(editor.getValue()), $preview); + drawPreview(); var textValue = canonicalize(CodeMirror.$textarea.val()); var shjson = stringifyInner(textValue); @@ -324,14 +328,13 @@ define([ var hjson = JSON.parse(shjson); var remoteDoc = hjson.content; - DiffMd.apply(DiffMd.render(remoteDoc), $preview); - var highlightMode = hjson.highlightMode; if (highlightMode && highlightMode !== APP.highlightMode) { CodeMirror.setMode(highlightMode, onModeChanged); } CodeMirror.setValueAndCursor(oldDoc, remoteDoc, TextPatcher); + drawPreview(); if (!readOnly) { var textValue = canonicalize(CodeMirror.$textarea.val()); diff --git a/www/common/common-util.js b/www/common/common-util.js index 6fb2ad7bb..debbd8e2d 100644 --- a/www/common/common-util.js +++ b/www/common/common-util.js @@ -122,5 +122,14 @@ define([], function () { xhr.send(null); }; + Util.throttle = function (f, ms) { + var to; + var g = function () { + window.clearTimeout(to); + to = window.setTimeout(f, ms); + }; + return g; + }; + return Util; }); diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index 730a7984f..20927dc04 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -71,6 +71,7 @@ define([ common.bytesToMegabytes = Util.bytesToMegabytes; common.bytesToKilobytes = Util.bytesToKilobytes; common.fetch = Util.fetch; + common.throttle = Util.throttle; // import hash utilities for export var createRandomHash = common.createRandomHash = Hash.createRandomHash; From 378bf2aa943994b488c0a91008e94fdcf80259c3 Mon Sep 17 00:00:00 2001 From: ansuz Date: Wed, 24 May 2017 11:27:31 +0200 Subject: [PATCH 04/15] yflory's word wrap fix --- www/code/inner.html | 1 + 1 file changed, 1 insertion(+) diff --git a/www/code/inner.html b/www/code/inner.html index f27544238..12f4c8cac 100644 --- a/www/code/inner.html +++ b/www/code/inner.html @@ -81,6 +81,7 @@ border-left: 1px solid black; box-sizing: border-box; font-family: Calibri,Ubuntu,sans-serif; + word-wrap: break-word; } #preview { max-width: 40vw; From fd83ae3e61d92f614361c52973c1b0464821eb96 Mon Sep 17 00:00:00 2001 From: ansuz Date: Wed, 24 May 2017 11:34:40 +0200 Subject: [PATCH 05/15] implement createRandomInteger --- www/common/common-util.js | 4 ++++ www/common/cryptpad-common.js | 1 + 2 files changed, 5 insertions(+) diff --git a/www/common/common-util.js b/www/common/common-util.js index debbd8e2d..0d0d4c776 100644 --- a/www/common/common-util.js +++ b/www/common/common-util.js @@ -131,5 +131,9 @@ define([], function () { return g; }; + Util.createRandomInteger = function () { + return Math.floor(Math.random() * Number.MAX_SAFE_INTEGER); + }; + return Util; }); diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index 20927dc04..5214fcc3b 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -72,6 +72,7 @@ define([ common.bytesToKilobytes = Util.bytesToKilobytes; common.fetch = Util.fetch; common.throttle = Util.throttle; + common.createRandomInteger = Util.createRandomInteger; // import hash utilities for export var createRandomHash = common.createRandomHash = Hash.createRandomHash; From c5bb8307573152c558756ebb78ec53ca3c435527 Mon Sep 17 00:00:00 2001 From: ansuz Date: Wed, 24 May 2017 14:21:31 +0200 Subject: [PATCH 06/15] don't preview if hightlight mode is not markdown --- www/code/main.js | 1 + 1 file changed, 1 insertion(+) diff --git a/www/code/main.js b/www/code/main.js index 660473ffd..9cb3cae10 100644 --- a/www/code/main.js +++ b/www/code/main.js @@ -111,6 +111,7 @@ define([ }; var drawPreview = Cryptpad.throttle(function () { + if (CodeMirror.highlightMode !== 'markdown') { return; } DiffMd.apply(DiffMd.render(editor.getValue()), $preview); }, 150); From 617e027f1273783f697331211aa6052baa5f6746 Mon Sep 17 00:00:00 2001 From: ansuz Date: Wed, 24 May 2017 15:50:35 +0200 Subject: [PATCH 07/15] catch markdown preview errors --- www/code/main.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/www/code/main.js b/www/code/main.js index 9cb3cae10..788ddddcf 100644 --- a/www/code/main.js +++ b/www/code/main.js @@ -112,7 +112,9 @@ define([ var drawPreview = Cryptpad.throttle(function () { if (CodeMirror.highlightMode !== 'markdown') { return; } - DiffMd.apply(DiffMd.render(editor.getValue()), $preview); + try { + DiffMd.apply(DiffMd.render(editor.getValue()), $preview); + } catch (e) { console.error(e); } }, 150); var onLocal = config.onLocal = function () { From 3803f6a20f789603c2707c48094f815ac0dc0eee Mon Sep 17 00:00:00 2001 From: ansuz Date: Wed, 24 May 2017 17:25:33 +0200 Subject: [PATCH 08/15] only render preview if preview container is visible --- www/code/main.js | 1 + 1 file changed, 1 insertion(+) diff --git a/www/code/main.js b/www/code/main.js index 788ddddcf..44ecec76b 100644 --- a/www/code/main.js +++ b/www/code/main.js @@ -112,6 +112,7 @@ define([ var drawPreview = Cryptpad.throttle(function () { if (CodeMirror.highlightMode !== 'markdown') { return; } + if (!$previewContainer.is(':visible')) { return; } try { DiffMd.apply(DiffMd.render(editor.getValue()), $preview); } catch (e) { console.error(e); } From a5ffd278a770ac78a464960c187c1ee7980d2ed8 Mon Sep 17 00:00:00 2001 From: ansuz Date: Wed, 24 May 2017 17:27:03 +0200 Subject: [PATCH 09/15] write styles for code in .less --- package.json | 2 +- www/code/code.css | 73 ++++++++++++++++++++++++++++++++++++++++ www/code/code.less | 81 +++++++++++++++++++++++++++++++++++++++++++++ www/code/inner.html | 65 +----------------------------------- 4 files changed, 156 insertions(+), 65 deletions(-) create mode 100644 www/code/code.css create mode 100644 www/code/code.less diff --git a/package.json b/package.json index e75ec7b32..3f8432ef5 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "scripts": { "lint": "jshint --config .jshintrc --exclude-path .jshintignore .", "test": "node TestSelenium.js", - "style": "lessc ./customize.dist/src/less/cryptpad.less > ./customize.dist/main.css && lessc ./customize.dist/src/less/toolbar.less > ./customize.dist/toolbar.css && lessc ./www/drive/file.less > ./www/drive/file.css && lessc ./www/settings/main.less > ./www/settings/main.css && lessc ./www/slide/slide.less > ./www/slide/slide.css && lessc ./www/whiteboard/whiteboard.less > ./www/whiteboard/whiteboard.css && lessc ./www/poll/poll.less > ./www/poll/poll.css && lessc ./www/file/file.less > ./www/file/file.css", + "style": "lessc ./customize.dist/src/less/cryptpad.less > ./customize.dist/main.css && lessc ./customize.dist/src/less/toolbar.less > ./customize.dist/toolbar.css && lessc ./www/drive/file.less > ./www/drive/file.css && lessc ./www/settings/main.less > ./www/settings/main.css && lessc ./www/slide/slide.less > ./www/slide/slide.css && lessc ./www/whiteboard/whiteboard.less > ./www/whiteboard/whiteboard.css && lessc ./www/poll/poll.less > ./www/poll/poll.css && lessc ./www/file/file.less > ./www/file/file.css && lessc ./www/code/code.less > ./www/code/code.css", "template": "cd customize.dist/src && node build.js" } } diff --git a/www/code/code.css b/www/code/code.css new file mode 100644 index 000000000..337a75fd9 --- /dev/null +++ b/www/code/code.css @@ -0,0 +1,73 @@ +html, +body { + height: 100%; + width: 100%; + padding: 0px; + margin: 0px; + overflow: hidden; + box-sizing: border-box; + position: relative; +} +body { + display: flex; + flex-flow: column; + max-height: 100%; + min-height: auto; +} +.CodeMirror { + display: inline-block; + height: 100%; + width: 50%; + min-width: 20%; + max-width: 80%; + resize: horizontal; +} +.CodeMirror.fullPage { + min-width: 100%; + max-width: 100%; + resize: none; +} +.CodeMirror-focused .cm-matchhighlight { + background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAYAAABytg0kAAAAFklEQVQI12NgYGBgkKzc8x9CMDAwAAAmhwSbidEoSQAAAABJRU5ErkJggg==); + background-position: bottom; + background-repeat: repeat-x; +} +#editorContainer { + flex: 1; + display: flex; + flex-flow: row; + height: 100%; + overflow: hidden; +} +#previewContainer { + flex: 1; + padding: 5px 20px; + overflow: auto; + display: inline-block; + height: 100%; + border-left: 1px solid black; + box-sizing: border-box; + font-family: Calibri, Ubuntu, sans-serif; + word-wrap: break-word; +} +#preview { + max-width: 40vw; + margin: auto; +} +#preview table { + border-collapse: collapse; +} +#preview table tr th { + border: 3px solid black; + padding: 15px; +} +@media (max-width: 720px) { + .CodeMirror { + flex: 1; + max-width: 100%; + resize: none; + } + #previewContainer { + display: none !important; + } +} diff --git a/www/code/code.less b/www/code/code.less new file mode 100644 index 000000000..420371c93 --- /dev/null +++ b/www/code/code.less @@ -0,0 +1,81 @@ +@import "../../customize.dist/src/less/variables.less"; +@import "../../customize.dist/src/less/mixins.less"; + +html, body{ + height: 100%; + width: 100%; + padding: 0px; + margin: 0px; + overflow: hidden; + box-sizing: border-box; + position: relative; +} +body { + display: flex; + flex-flow: column; + max-height: 100%; + min-height: auto; +} +.CodeMirror { + display: inline-block; + height: 100%; + width: 50%; + min-width: 20%; + max-width: 80%; + resize: horizontal; +} +.CodeMirror.fullPage { + min-width: 100%; + max-width: 100%; + resize: none; +} +.CodeMirror-focused .cm-matchhighlight { + background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAYAAABytg0kAAAAFklEQVQI12NgYGBgkKzc8x9CMDAwAAAmhwSbidEoSQAAAABJRU5ErkJggg==); + background-position: bottom; + background-repeat: repeat-x; +} +#editorContainer { + flex: 1; + display: flex; + flex-flow: row; + height: 100%; + overflow: hidden; +} +#previewContainer { + flex: 1; + padding: 5px 20px; + overflow: auto; + display: inline-block; + height: 100%; + border-left: 1px solid black; + box-sizing: border-box; + font-family: Calibri,Ubuntu,sans-serif; + word-wrap: break-word; +} + +#preview { + max-width: 40vw; + margin: auto; + + table { + border-collapse: collapse; + tr { + th { + border: 3px solid black; + padding: 15px; + } + } + } +} + +@media (max-width: 720px) { + .CodeMirror { + flex: 1; + max-width: 100%; + resize: none; + } + #previewContainer { + display: none !important; + } +} + diff --git a/www/code/inner.html b/www/code/inner.html index 12f4c8cac..b3ac7fed5 100644 --- a/www/code/inner.html +++ b/www/code/inner.html @@ -8,6 +8,7 @@ + @@ -31,70 +32,6 @@ -
From d9f7470f065ce1a9c7f8ea939a7ee0274154b235 Mon Sep 17 00:00:00 2001 From: ansuz Date: Wed, 24 May 2017 18:28:16 +0200 Subject: [PATCH 10/15] copy user details into sessionStorage for safari --- www/common/fsStore.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/www/common/fsStore.js b/www/common/fsStore.js index b20c38c48..726570574 100644 --- a/www/common/fsStore.js +++ b/www/common/fsStore.js @@ -173,6 +173,12 @@ 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. From b32c3292690067d2ae81ff58ef0a0dd1e6769d80 Mon Sep 17 00:00:00 2001 From: ansuz Date: Wed, 24 May 2017 18:41:19 +0200 Subject: [PATCH 11/15] remember whether you were using preview mode for a pad --- www/code/main.js | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/www/code/main.js b/www/code/main.js index 44ecec76b..d5feaf22a 100644 --- a/www/code/main.js +++ b/www/code/main.js @@ -110,12 +110,16 @@ define([ return stringify(obj); }; - var drawPreview = Cryptpad.throttle(function () { - if (CodeMirror.highlightMode !== 'markdown') { return; } - if (!$previewContainer.is(':visible')) { return; } + var forceDrawPreview = function () { try { DiffMd.apply(DiffMd.render(editor.getValue()), $preview); } catch (e) { console.error(e); } + }; + + var drawPreview = Cryptpad.throttle(function () { + if (CodeMirror.highlightMode !== 'markdown') { return; } + if (!$previewContainer.is(':visible')) { return; } + forceDrawPreview(); }, 150); var onLocal = config.onLocal = function () { @@ -239,9 +243,16 @@ define([ } $previewContainer.toggle(); if ($previewContainer.is(':visible')) { + forceDrawPreview(); $codeMirror.removeClass('fullPage'); + Cryptpad.setPadAttribute('previewMode', true, function (e, data) { + if (e) { return console.log(e); } + }); } else { $codeMirror.addClass('fullPage'); + Cryptpad.setPadAttribute('previewMode', false, function (e, data) { + if (e) { return console.log(e); } + }); } }); $rightside.append($previewButton); @@ -255,6 +266,7 @@ define([ CodeMirror.configureTheme(); } + // set the hash if (!readOnly) { Cryptpad.replaceHash(editHash); } }; @@ -306,6 +318,14 @@ define([ Title.updateTitle(Cryptpad.initialName); } + Cryptpad.getPadAttribute('previewMode', function (e, data) { + if (e) { return void console.error(e); } + var $codeMirror = $iframe.find('.CodeMirror'); + if (data === false && APP.$previewButton) { + APP.$previewButton.click(); + } + }); + Cryptpad.removeLoadingScreen(); setEditable(true); initializing = false; From dc2b0ae6b4627f9d33a52cfa972c35978ad3d5f3 Mon Sep 17 00:00:00 2001 From: ansuz Date: Wed, 24 May 2017 18:45:48 +0200 Subject: [PATCH 12/15] jshint compliance --- www/code/main.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/www/code/main.js b/www/code/main.js index d5feaf22a..38b5f2267 100644 --- a/www/code/main.js +++ b/www/code/main.js @@ -245,12 +245,12 @@ define([ if ($previewContainer.is(':visible')) { forceDrawPreview(); $codeMirror.removeClass('fullPage'); - Cryptpad.setPadAttribute('previewMode', true, function (e, data) { + Cryptpad.setPadAttribute('previewMode', true, function (e) { if (e) { return console.log(e); } }); } else { $codeMirror.addClass('fullPage'); - Cryptpad.setPadAttribute('previewMode', false, function (e, data) { + Cryptpad.setPadAttribute('previewMode', false, function (e) { if (e) { return console.log(e); } }); } @@ -320,7 +320,6 @@ define([ Cryptpad.getPadAttribute('previewMode', function (e, data) { if (e) { return void console.error(e); } - var $codeMirror = $iframe.find('.CodeMirror'); if (data === false && APP.$previewButton) { APP.$previewButton.click(); } From a04f179d8b9adb2860d27f6a0ac38d928699d5e9 Mon Sep 17 00:00:00 2001 From: ansuz Date: Wed, 24 May 2017 19:00:14 +0200 Subject: [PATCH 13/15] hide preview mode on phones --- www/code/code.css | 2 +- www/code/code.less | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/www/code/code.css b/www/code/code.css index 337a75fd9..78a4b7bf2 100644 --- a/www/code/code.css +++ b/www/code/code.css @@ -61,7 +61,7 @@ body { border: 3px solid black; padding: 15px; } -@media (max-width: 720px) { +@media (max-width: 600px) { .CodeMirror { flex: 1; max-width: 100%; diff --git a/www/code/code.less b/www/code/code.less index 420371c93..ef7cef32d 100644 --- a/www/code/code.less +++ b/www/code/code.less @@ -68,7 +68,7 @@ body { } } -@media (max-width: 720px) { +@media (max-width: @media-medium-screen) { .CodeMirror { flex: 1; max-width: 100%; From 0559b8cb775584f341fd84ec93809c3429d21a9d Mon Sep 17 00:00:00 2001 From: superniko Date: Fri, 26 May 2017 16:47:45 +0300 Subject: [PATCH 14/15] Update messages.ro.js --- customize.dist/translations/messages.ro.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/customize.dist/translations/messages.ro.js b/customize.dist/translations/messages.ro.js index 2c09b9a76..75c1c5852 100644 --- a/customize.dist/translations/messages.ro.js +++ b/customize.dist/translations/messages.ro.js @@ -274,7 +274,7 @@ define(function () { out.main_p2 = "Acest proiect folosește
CKEditor Visual Editor, CodeMirror, și ChainPad un motor în timp real."; out.main_howitworks_p1 = "CryptPad folosește o variantă a algoritmului de Operational transformation care este capabil să găsescă consens distribuit folosind Nakamoto Blockchain, o construcție popularizată de Bitcoin. Astfel algoritmul poate evita nevoia ca serverul central să rezove conflicte, iar serverul nu este interesat de conținutul care este editat în pad."; out.main_about_p2 = "Dacă ai orice fel de întrebare sau comentariu, poți să ne dai un tweet, semnalezi o problemă on github, spui salut pe IRC (irc.freenode.net), sau trimiți un email."; - out.main_info = "

Colaborează n siguranță


Dezvoltă-ți ideile împreună cu documente partajate în timp ce tehnologia Zero Knowledge îți păstrează securitatea; chiar și de noi."; + out.main_info = "

Colaborează în siguranță


Dezvoltă-ți ideile împreună cu documentele partajate în timp ce tehnologia Zero Knowledge îți păstrează securitatea; chiar și de noi."; out.main_howitworks = "Cum funcționează"; out.main_zeroKnowledge = "Zero Knowledge"; out.main_zeroKnowledge_p = "Nu trebuie să ne crezi că nu ne uităm la pad-urile tale, cu tehnologia revoluționară Zero Knowledge a CryptPad nu putem. Învață mai multe despre cum îți protejăm Intimitate și Securitate."; From 66520b60413a515454439da15715027478497885 Mon Sep 17 00:00:00 2001 From: Caleb James DeLisle Date: Fri, 26 May 2017 18:09:31 +0200 Subject: [PATCH 15/15] cleaned up the accounts, limits and revenue sharing and unified the config in one place --- config.example.js | 49 ++++++++++++++++++++----- customize.dist/application_config.js | 2 - customize.dist/translations/messages.js | 1 + rpc.js | 9 ++++- server.js | 1 + www/common/cryptpad-common.js | 11 ++++-- www/common/toolbar.js | 6 ++- www/common/toolbar2.js | 6 ++- www/drive/main.js | 12 +++--- 9 files changed, 70 insertions(+), 27 deletions(-) diff --git a/config.example.js b/config.example.js index fe3f2fb91..a0f3003e0 100644 --- a/config.example.js +++ b/config.example.js @@ -116,11 +116,46 @@ module.exports = { 'contact', ], - /* Domain - * If you want to have enable payments on your CryptPad instance, it has to be able to tell - * our account server what is your domain + /* Limits, Subscriptions and Contact + * + * CryptPad limits every registered user to 50MB of storage. + * By default it also allows that limit to be increased by subscribing at accounts.cryptpad.fr + * You can either: + * A: Hide the button for subscribing, so everyone is limited to 50MB + * B: Support cryptpad and share 50% of the revenue earned on your instance + * + * CryptPad is developed by people who need to live and who deserve an equivilent life to + * what they would get at a company which monitizes user data. However, we intend to have + * a mutually positive relationship with every one of our users, including you. If you are + * getting value from CryptPad, you should be giving equal value back. + * + * If you are using CryptPad in a business context, please consider taking a support contract + * by contacting sales@cryptpad.fr + * + * If you choose A, set this variable to true to hide the subscription button. */ - // domain: 'https://cryptpad.fr', + noSubscriptionButton: false, + /* + * If you choose B, set the domain of your cryptpad instance here and then contact + * sales@cryptpad.fr and tell us your domain, we will tell you what is needed to get paid. + */ + myDomain: 'i.did.not.read.my.config.cryptpad.myserver.tld', + /* + * If you are using CryptPad internally and you want to increase the per-user storage limit, + * change the following value. + * Please note: Providing a public offer that is better than cryptpad.fr is an attack on + * the project. Please leave this alone if you are providing a public service. + */ + defaultStorageLimit: 50 * 1024 * 1024, + /* + * By default, CryptPad contacts our accounts server once a day to check for changes in the + * people who have accounts. This check-in will also send your email and the version of + * CryptPad you run so we can reach you if we are aware of a serious problem with your + * CryptPad instance. We will never sell it or use it for marketing. If you want to block this + * check-in and remain completely private, set this to false and noSubscriptionButton to true. + */ + adminEmail: 'i.did.not.read.my.config@cryptpad.fr', + /* You have the option of specifying an alternative storage adaptor. @@ -211,12 +246,6 @@ module.exports = { */ //restrictUploads: false, - /* Default user storage limit (bytes) - * if you don't want to limit users, - * you can set this to the size of your hard disk - */ - defaultStorageLimit: 50 * 1024 * 1024, - /* Max Upload Size (bytes) * this sets the maximum size of any one file uploaded to the server. * anything larger than this size will be rejected diff --git a/customize.dist/application_config.js b/customize.dist/application_config.js index 24ed2c740..151a8b7da 100644 --- a/customize.dist/application_config.js +++ b/customize.dist/application_config.js @@ -37,8 +37,6 @@ define(function() { config.enableHistory = true; - config.enablePinLimit = true; - /* user passwords are hashed with scrypt, and salted with their username. this value will be appended to the username, causing the resulting hash to differ from other CryptPad instances if customized. This makes it diff --git a/customize.dist/translations/messages.js b/customize.dist/translations/messages.js index 751cf3633..d39407194 100644 --- a/customize.dist/translations/messages.js +++ b/customize.dist/translations/messages.js @@ -78,6 +78,7 @@ define(function () { out.updated_0_pinLimitReachedAlert = "You've reached your storage limit. New pads won't be stored in your CryptDrive.
" + 'You can either remove pads from your CryptDrive or subscribe to a premium offer to increase your limit.'; out.pinLimitReachedAlert = out.updated_0_pinLimitReachedAlert; + out.pinLimitReachedAlertNoAccounts = out.pinLimitReached; out.pinAboveLimitAlert = 'As of this release, we are imposing a 50MB limit on free data storage and you are currently using {0}. You will need to either delete some pads or subscribe on accounts.cryptpad.fr. Your contribution will help us improve CryptPad and spread Zero Knowledge. Please contact support if you have any other questions.'; out.pinLimitNotPinned = "You've reached your storage limit.
"+ "This pad is not stored in your CryptDrive."; diff --git a/rpc.js b/rpc.js index 0257c498f..45be04cc7 100644 --- a/rpc.js +++ b/rpc.js @@ -1,4 +1,5 @@ /*@flow*/ +/*jshint esversion: 6 */ /* Use Nacl for checking signatures of messages */ var Nacl = require("tweetnacl"); @@ -8,6 +9,7 @@ var Nacl = require("tweetnacl"); var Fs = require("fs"); var Path = require("path"); var Https = require("https"); +const Package = require('./package.json'); var RPC = module.exports; @@ -371,6 +373,7 @@ var getHash = function (Env, publicKey, cb) { // To each key is associated an object containing the 'limit' value and a 'note' explaining that limit var limits = {}; var updateLimits = function (config, publicKey, cb) { + if (config.adminEmail === false && config.noSubscriptionButton === true) { return; } if (typeof cb !== "function") { cb = function () {}; } var defaultLimit = typeof(config.defaultStorageLimit) === 'number'? @@ -382,8 +385,10 @@ var updateLimits = function (config, publicKey, cb) { } var body = JSON.stringify({ - domain: config.domain, - subdomain: config.subdomain + domain: config.myDomain, + subdomain: config.mySubdomain, + adminEmail: config.adminEmail, + version: Package.version }); var options = { host: 'accounts.cryptpad.fr', diff --git a/server.js b/server.js index 037a8adeb..e2527fa7d 100644 --- a/server.js +++ b/server.js @@ -121,6 +121,7 @@ app.get('/api/config', function(req, res){ waitSeconds: 60, urlArgs: 'ver=' + Package.version + (DEV_MODE? '-' + (+new Date()): ''), }, + noSubscriptionButton: (config.noSubscriptionButton === true), websocketPath: config.useExternalWebsocket ? undefined : config.websocketPath, websocketURL:'ws' + ((useSecureWebsockets) ? 's' : '') + '://' + host + ':' + websocketPort + '/cryptpad_websocket', diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index 5214fcc3b..ae73867de 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -599,7 +599,7 @@ define([ var data = makePad(href, name); getStore().pushData(data, function (e) { if (e) { - if (e === 'E_OVER_LIMIT' && AppConfig.enablePinLimit) { + if (e === 'E_OVER_LIMIT') { common.alert(Messages.pinLimitNotPinned, null, true); return; } @@ -761,7 +761,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); } @@ -817,7 +817,10 @@ define([ var width = Math.floor(Math.min(quota, 1)*200); // the bar is 200px width var $usage = $('', {'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 = $('', { href: "https://accounts.cryptpad.fr/#!on=" + origin, @@ -845,7 +848,7 @@ define([ else if (quota < 1) { $usage.addClass('warning'); } else { $usage.addClass('above'); - if (!limitReachedDisplayed) { + if (!limitReachedDisplayed && Config.noSubscriptionButton === true) { limitReachedDisplayed = true; common.alert(Messages._getKey('pinAboveLimitAlert', [prettyUsage, encodeURIComponent(window.location.hostname)]), null, true); } diff --git a/www/common/toolbar.js b/www/common/toolbar.js index 6920c0b0d..bf08fcb07 100644 --- a/www/common/toolbar.js +++ b/www/common/toolbar.js @@ -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); }); } }; diff --git a/www/common/toolbar2.js b/www/common/toolbar2.js index 57d113a48..a17e24199 100644 --- a/www/common/toolbar2.js +++ b/www/common/toolbar2.js @@ -616,8 +616,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); }); } }; diff --git a/www/drive/main.js b/www/drive/main.js index 5343bd829..03dcb7716 100644 --- a/www/drive/main.js +++ b/www/drive/main.js @@ -2712,13 +2712,11 @@ define([ } /* add the usage */ - if (AppConfig.enablePinLimit) { - Cryptpad.createUsageBar(function (err, $limitContainer) { - if (err) { return void logError(err); } - $leftside.html(''); - $leftside.append($limitContainer); - }); - } + Cryptpad.createUsageBar(function (err, $limitContainer) { + if (err) { return void logError(err); } + $leftside.html(''); + $leftside.append($limitContainer); + }); /* add a history button */ var histConfig = {