From 69368def48a4981195317067dfdca3a50b6dfa21 Mon Sep 17 00:00:00 2001 From: ansuz Date: Fri, 28 Apr 2017 12:48:36 +0200 Subject: [PATCH 1/8] make pin, blob, and blobstage path configurable --- config.example.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/config.example.js b/config.example.js index 692a91c59..859c4b872 100644 --- a/config.example.js +++ b/config.example.js @@ -141,6 +141,23 @@ module.exports = { */ filePath: './datastore/', + /* CryptPad allows logged in users to request that particular documents be + * stored by the server indefinitely. This is called 'pinning'. + * Pin requests are stored in a pin-store. The location of this store is + * defined here. + */ + pinPath: './pins', + + /* CryptPad allows logged in users to upload encrypted files. Files/blobs + * are stored in a 'blob-store'. Set its location here. + */ + blobPath: './blob', + + /* CryptPad stores incomplete blobs in a 'staging' area until they are + * fully uploaded. Set its location here. + */ + blobStagingPath: './blobstage', + /* Cryptpad's file storage adaptor closes unused files after a configurale * number of milliseconds (default 30000 (30 seconds)) */ From 4d48c88807b49a88afc73222b9d47415852951c3 Mon Sep 17 00:00:00 2001 From: ansuz Date: Fri, 28 Apr 2017 12:49:08 +0200 Subject: [PATCH 2/8] create blob and blobstage stores if not exists --- rpc.js | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/rpc.js b/rpc.js index 5670f1c7a..4d1e0005d 100644 --- a/rpc.js +++ b/rpc.js @@ -2,6 +2,8 @@ /* Use Nacl for checking signatures of messages */ var Nacl = require("tweetnacl"); +var Fs = require("fs"); + var RPC = module.exports; var Store = require("./storage/file"); @@ -380,19 +382,17 @@ var getLimit = function (cb) { }; -var createBlobStaging = function (cb) { - -}; - -var createBlobStore = function (cb) { +var safeMkdir = function (path, cb) { + Fs.mkdir(path, function (e) { + if (!e || e.code === 'EEXIST') { return void cb(); } + cb(e); + }); }; var upload = function (store, Sessions, publicKey, cb) { }; - - /*::const ConfigType = require('./config.example.js');*/ RPC.create = function (config /*:typeof(ConfigType)*/, cb /*:(?Error, ?Function)=>void*/) { // load pin-store... @@ -509,15 +509,29 @@ RPC.create = function (config /*:typeof(ConfigType)*/, cb /*:(?Error, ?Function) } }; + var keyOrDefaultString = function (key, def) { + return typeof(config[key]) === 'string'? config[key]: def; + }; + + var pinPath = keyOrDefaultString('pinPath', './pins'); + var blobPath = keyOrDefaultString('blobPath', './blob'); + var blobStagingPath = keyOrDefaultString('blobStagingPath', './blobstage'); + Store.create({ - filePath: './pins' + filePath: pinPath, }, function (s) { store = s; - cb(void 0, rpc); - // expire old sessions once per minute - setInterval(function () { - expireSessions(Sessions); - }, 60000); + safeMkdir(blobPath, function (e) { + if (e) { throw e; } + safeMkdir(blobStagingPath, function (e) { + if (e) { throw e; } + cb(void 0, rpc); + // expire old sessions once per minute + setInterval(function () { + expireSessions(Sessions); + }, 60000); + }) + }); }); }; From 38a115d8f82a90c4c37df1f8a71a41f82e2e59f2 Mon Sep 17 00:00:00 2001 From: ansuz Date: Fri, 28 Apr 2017 14:08:17 +0200 Subject: [PATCH 3/8] feedback on anonymous drive --- www/drive/main.js | 1 + 1 file changed, 1 insertion(+) diff --git a/www/drive/main.js b/www/drive/main.js index 37a699a21..d60836ca1 100644 --- a/www/drive/main.js +++ b/www/drive/main.js @@ -2344,6 +2344,7 @@ define([ // don't initialize until the store is ready. Cryptpad.ready(function () { Cryptpad.reportAppUsage(); + if (!Cryptpad.isLoggedIn()) { Cryptpad.feedback('ANONYMOUS_DRIVE'); } APP.$bar = $iframe.find('#toolbar'); var storeObj = Cryptpad.getStore().getProxy && Cryptpad.getStore().getProxy().proxy ? Cryptpad.getStore().getProxy() : undefined; From 1b3ce5aa96eacaf09b8409fc52b07a5edd623c10 Mon Sep 17 00:00:00 2001 From: ansuz Date: Fri, 28 Apr 2017 16:08:47 +0200 Subject: [PATCH 4/8] fix typo --- www/common/toolbar.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/common/toolbar.js b/www/common/toolbar.js index 23de3262d..7dbba925c 100644 --- a/www/common/toolbar.js +++ b/www/common/toolbar.js @@ -498,7 +498,7 @@ define([ 'title': Messages.pinLimitReached }).append($limitIcon).hide().appendTo($userContainer); var todo = function (e, overLimit) { - if (e) { return void console.error("Unable tog et the pinned usage"); } + if (e) { return void console.error("Unable to get the pinned usage"); } if (overLimit) { $limit.show().click(function () { Cryptpad.alert(Messages.pinLimitReachedAlert, null, true); From 3fa0a73025b5df8c16d821b219cb493c520544e7 Mon Sep 17 00:00:00 2001 From: ansuz Date: Fri, 28 Apr 2017 16:09:46 +0200 Subject: [PATCH 5/8] prevent using string methods on undefined variable --- www/common/userObject.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/www/common/userObject.js b/www/common/userObject.js index 66d507a27..247d28694 100644 --- a/www/common/userObject.js +++ b/www/common/userObject.js @@ -606,6 +606,10 @@ define([ // Permanently delete multiple files at once using a list of paths // NOTE: We have to be careful when removing elements from arrays (trash root, unsorted or template) var removePadAttribute = function (f) { + if (typeof(f) !== 'string') { + console.error("Can't find pad attribute for an undefined pad"); + return; + } Object.keys(files).forEach(function (key) { var hash = f.indexOf('#') !== -1 ? f.slice(f.indexOf('#') + 1) : null; if (hash && key.indexOf(hash) === 0) { From 841c9ee9de3e483b311188d46e499ffa6c2468ca Mon Sep 17 00:00:00 2001 From: ansuz Date: Fri, 28 Apr 2017 16:11:22 +0200 Subject: [PATCH 6/8] don't close popup dialog when hitting enter if textarea has focus --- www/slide/main.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/www/slide/main.js b/www/slide/main.js index eb9919abc..d1972fae4 100644 --- a/www/slide/main.js +++ b/www/slide/main.js @@ -482,7 +482,10 @@ define([ // CSS $('