From a0c73c95d84eece36fc22410b0b6775599c2ffad Mon Sep 17 00:00:00 2001 From: ansuz Date: Sat, 28 May 2016 13:13:54 +0200 Subject: [PATCH] do away with a bit of boilerplate --- www/common/cryptpad-common.js | 19 +++++++++++++++++++ www/json/main.js | 20 ++++++-------------- 2 files changed, 25 insertions(+), 14 deletions(-) create mode 100644 www/common/cryptpad-common.js diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js new file mode 100644 index 000000000..c69b8e407 --- /dev/null +++ b/www/common/cryptpad-common.js @@ -0,0 +1,19 @@ +define([ + '/common/crypto.js', +], function (Crypto) { + var common = {}; + + var getSecrets = common.getSecrets = function () { + var secret = {}; + if (!/#/.test(window.location.href)) { + secret.key = Crypto.genKey(); + } else { + var hash = window.location.hash.slice(1); + secret.channel = hash.slice(0, 32); + secret.key = hash.slice(32); + } + return secret; + }; + + return common; +}); diff --git a/www/json/main.js b/www/json/main.js index 5e96cea5e..28865d852 100644 --- a/www/json/main.js +++ b/www/json/main.js @@ -1,24 +1,16 @@ define([ '/json/api.js', '/common/crypto.js', + '/common/cryptpad-common.js', //'/customize/pad.js' -], function (RtListMap, Crypto) { +], function (RtListMap, Crypto, Common) { var $ = window.jQuery; - var key; - var channel = ''; - var hash = false; - if (!/#/.test(window.location.href)) { - key = Crypto.genKey(); - } else { - hash = window.location.hash.slice(1); - channel = hash.slice(0,32); - key = hash.slice(32); - } + var secret = Common.getSecrets(); var config = { - channel: channel, - cryptKey: key, + channel: secret.channel, + cryptKey: secret.key, data: {}, }; @@ -38,7 +30,7 @@ define([ // or just remove? var onInit = config.onInit = function (info) { console.log("initializing!"); - window.location.hash = info.channel + key; + window.location.hash = info.channel + secret.key; }; // TODO replace with `proxy.on('ready'` ?