Clean cryptpad-common

pull/1/head
yflory 7 years ago
parent 677ba9bc0f
commit 280a7c2765

@ -5,8 +5,9 @@ define([
'/common/common-interface.js',
'/common/common-realtime.js',
'/common/common-constants.js',
'/common/outer/local-store.js',
'/customize/messages.js',
], function ($, Config, Cryptpad, UI, Realtime, Constants, Messages) {
], function ($, Config, Cryptpad, UI, Realtime, Constants, LocalStore, Messages) {
window.APP = {
Cryptpad: Cryptpad,
@ -25,7 +26,7 @@ define([
// Make sure we don't display non-translated content (empty button)
$main.find('#data').removeClass('hidden');
if (Cryptpad.isLoggedIn()) {
if (LocalStore.isLoggedIn()) {
if (window.location.pathname === '/') {
window.location = '/drive/';
return;
@ -47,7 +48,7 @@ define([
$('#buttons').find('.nologin').hide();
$logout.click(function () {
Cryptpad.logout(function () {
LocalStore.logout(function () {
window.location.reload();
});
});
@ -109,7 +110,7 @@ define([
proxy.edPublic = result.edPublic;
Realtime.whenRealtimeSyncs(result.realtime, function () {
Cryptpad.login(result.userHash, result.userName, function () {
LocalStore.login(result.userHash, result.userName, function () {
document.location.href = '/drive/';
});
});

@ -1,9 +1,11 @@
define([
'jquery',
'/common/cryptpad-common.js',
'/common/common-constants.js',
'/common/outer/local-store.js',
'/common/test.js',
'/bower_components/tweetnacl/nacl-fast.min.js'
], function ($, Cryptpad, Test) {
], function ($, Cryptpad, Constants, LocalStore, Test) {
var Nacl = window.nacl;
var signMsg = function (msg, privKey) {
@ -20,7 +22,8 @@ define([
];
// Safari is weird about localStorage in iframes but seems to let sessionStorage slide.
localStorage.User_hash = localStorage.User_hash || sessionStorage.User_hash;
localStorage[Constants.userHashKey] = localStorage[Constants.userHashKey] ||
sessionStorage[Constants.userHashKey];
Cryptpad.ready(function () {
console.log('IFRAME READY');
@ -40,7 +43,7 @@ define([
} else if (data.cmd === 'SIGN') {
if (!AUTHORIZED_DOMAINS.filter(function (x) { return x.test(domain); }).length) {
ret.error = "UNAUTH_DOMAIN";
} else if (!Cryptpad.isLoggedIn()) {
} else if (!LocalStore.isLoggedIn()) {
ret.error = "NOT_LOGGED_IN";
} else {
var proxy = Cryptpad.getStore().getProxy().proxy;

@ -0,0 +1,52 @@
define(['/customize/messages.js'], function (Messages) {
var Feedback = {};
Feedback.init = function (state) {
Feedback.state = state;
};
var randomToken = function () {
return Math.random().toString(16).replace(/0./, '');
};
var ajax = function (url, cb) {
var http = new XMLHttpRequest();
http.open('HEAD', url);
http.onreadystatechange = function() {
if (this.readyState === this.DONE) {
if (cb) { cb(); }
}
};
http.send();
};
Feedback.send = function (action, force) {
if (!action) { return; }
if (force !== true) {
if (!Feedback.state) { return; }
}
var href = '/common/feedback.html?' + action + '=' + randomToken();
ajax(href);
};
Feedback.reportAppUsage = function () {
var pattern = window.location.pathname.split('/')
.filter(function (x) { return x; }).join('.');
if (/^#\/1\/view\//.test(window.location.hash)) {
Feedback.send(pattern + '_VIEW');
} else {
Feedback.send(pattern);
}
};
Feedback.reportScreenDimensions = function () {
var h = window.innerHeight;
var w = window.innerWidth;
Feedback.send('DIMENSIONS:' + h + 'x' + w);
};
Feedback.reportLanguage = function () {
Feedback.send('LANG_' + Messages._languageUsed);
};
return Feedback;
});

@ -1,17 +1,22 @@
define([
'jquery',
'/api/config',
'/common/cryptpad-common.js',
'/common/common-util.js',
'/common/common-hash.js',
'/common/common-language.js',
'/common/common-interface.js',
'/common/common-feedback.js',
'/common/media-tag.js',
'/customize/messages.js',
'css!/common/tippy.css',
], function ($, Config, Cryptpad, Util, Hash, Language, UI, MediaTag) {
], function ($, Config, Util, Hash, Language, UI, Feedback, MediaTag, Messages) {
var UIElements = {};
var Messages = Cryptpad.Messages;
// Configure MediaTags to use our local viewer
if (MediaTag && MediaTag.PdfPlugin) {
MediaTag.PdfPlugin.viewer = '/common/pdfjs/web/viewer.html';
}
UIElements.updateTags = function (common, href) {
var sframeChan = common.getSframeChannel();
@ -143,7 +148,7 @@ define([
toSave: toSave
}, function () {
UI.alert(Messages.templateSaved);
common.feedback('TEMPLATE_CREATED');
Feedback.send('TEMPLATE_CREATED');
});
};
UI.prompt(Messages.saveTemplatePrompt, title, todo);
@ -236,6 +241,53 @@ define([
};
// Avatars
// Enable mediatags
$(window.document).on('decryption', function (e) {
var decrypted = e.originalEvent;
if (decrypted.callback) {
var cb = decrypted.callback;
cb(function (mediaObject) {
var root = mediaObject.element;
if (!root) { return; }
if (mediaObject.type === 'image') {
$(root).data('blob', decrypted.blob);
}
if (mediaObject.type !== 'download') { return; }
var metadata = decrypted.metadata;
var title = '';
var size = 0;
if (metadata && metadata.name) {
title = metadata.name;
}
if (decrypted.blob) {
size = decrypted.blob.size;
}
var sizeMb = Util.bytesToMegabytes(size);
var $btn = $(root).find('button');
$btn.addClass('btn btn-success')
.attr('type', 'download')
.html(function () {
var text = Messages.download_mt_button + '<br>';
if (title) {
text += '<b>' + Util.fixHTML(title) + '</b><br>';
}
if (size) {
text += '<em>' + Messages._getKey('formattedMB', [sizeMb]) + '</em>';
}
return text;
});
});
}
});
UIElements.displayMediatagImage = function (Common, $tag, cb) {
if (!$tag.length || !$tag.is('media-tag')) { return void cb('NOT_MEDIATAG'); }
var observer = new MutationObserver(function(mutations) {
@ -434,6 +486,7 @@ define([
// allowed options tags: ['a', 'hr', 'p']
UIElements.createDropdown = function (config) {
if (typeof config !== "object" || !Array.isArray(config.options)) { return; }
if (config.feedback && !config.common) { return void console.error("feedback in a dropdown requires sframe-common"); }
var allowedTags = ['a', 'p', 'hr'];
var isValidOption = function (o) {
@ -500,7 +553,7 @@ define([
setActive($val);
$innerblock.scrollTop($val.position().top + $innerblock.scrollTop());
}
if (config.feedback) { Cryptpad.feedback(config.feedback); }
if (config.feedback) { Feedback.send(config.feedback); }
};
$container.click(function (e) {
@ -676,6 +729,7 @@ define([
left: true, // Open to the left of the button
container: config.$initBlock, // optional
feedback: "USER_ADMIN",
common: Common
};
var $userAdmin = UIElements.createDropdown(dropdownConfigUser);
@ -777,7 +831,8 @@ define([
options: options, // Entries displayed in the menu
//left: true, // Open to the left of the button
container: $initBlock, // optional
isSelect: true
isSelect: true,
common: common
};
var $block = UIElements.createDropdown(dropdownConfig);
$block.attr('id', 'cp-language-selector');
@ -861,7 +916,7 @@ define([
sframeChan.query('Q_TEMPLATE_USE', data.href, function () {
first = false;
UI.removeLoadingScreen();
common.feedback('TEMPLATE_USED');
Feedback.send('TEMPLATE_USED');
});
if (focus) { focus.focus(); }
return;

@ -2,12 +2,12 @@ define([
'jquery',
'/bower_components/chainpad-crypto/crypto.js',
'/bower_components/chainpad-netflux/chainpad-netflux.js',
'/common/cryptpad-common.js',
'/common/common-util.js',
'/common/common-hash.js',
'/common/common-realtime.js',
'/common/outer/network-config.js',
'/bower_components/textpatcher/TextPatcher.js'
], function ($, Crypto, CPNetflux, Cryptpad, Util, Hash, Realtime, TextPatcher) {
], function ($, Crypto, CPNetflux, Util, Hash, Realtime, NetConfig, TextPatcher) {
//var Messages = Cryptpad.Messages;
//var noop = function () {};
var finish = function (S, err, doc) {
@ -29,7 +29,7 @@ define([
var secret = Hash.getSecrets('pad', hash);
if (!secret.keys) { secret.keys = secret.key; } // support old hashses
var config = {
websocketURL: Cryptpad.getWebsocketURL(),
websocketURL: NetConfig.getWebsocketURL(),
channel: secret.channel,
validateKey: secret.keys.validateKey || undefined,
crypto: Crypto.createEncryptor(secret.keys),

@ -6,25 +6,18 @@ define([
'/common/common-util.js',
'/common/common-hash.js',
'/common/common-messaging.js',
'/file/file-crypto.js',
'/common/common-realtime.js',
'/common/common-language.js',
'/common/common-constants.js',
'/common/common-feedback.js',
'/common/outer/local-store.js',
'/common/clipboard.js',
'/common/pinpad.js',
'/customize/application_config.js',
'/common/media-tag.js',
'/bower_components/nthen/index.js',
'/bower_components/localforage/dist/localforage.min.js',
], function ($, Config, Messages, Store, Util, Hash,
Messaging, FileCrypto, Realtime, Language, Constants, Clipboard,
Pinpad, AppConfig, MediaTag, Nthen, localForage) {
// Configure MediaTags to use our local viewer
if (MediaTag && MediaTag.PdfPlugin) {
MediaTag.PdfPlugin.viewer = '/common/pdfjs/web/viewer.html';
}
Messaging, Realtime, Language, Constants, Feedback, LocalStore,
Pinpad, AppConfig, Nthen) {
/* This file exposes functionality which is specific to Cryptpad, but not to
any particular pad type. This includes functions for committing metadata
@ -36,11 +29,9 @@ define([
var origin = encodeURIComponent(window.location.hostname);
var common = window.Cryptpad = {
Messages: Messages,
Clipboard: Clipboard,
donateURL: 'https://accounts.cryptpad.fr/#/donate?on=' + origin,
upgradeURL: 'https://accounts.cryptpad.fr/#/?on=' + origin,
account: {},
MediaTag: MediaTag,
};
var PINNING_ENABLED = AppConfig.enablePinning;
@ -49,63 +40,6 @@ define([
var rpc;
var anon_rpc;
// import common utilities for export
//common.find = Util.find;
//common.hexToBase64 = Util.hexToBase64;
//common.base64ToHex = Util.base64ToHex;
//var deduplicateString = common.deduplicateString = Util.deduplicateString;
//common.uint8ArrayToHex = Util.uint8ArrayToHex;
//common.replaceHash = Util.replaceHash;
//common.getHash = Util.getHash;
//common.fixFileName = Util.fixFileName;
//common.bytesToMegabytes = Util.bytesToMegabytes;
//common.bytesToKilobytes = Util.bytesToKilobytes;
//common.fetch = Util.fetch;
//common.throttle = Util.throttle;
//common.createRandomInteger = Util.createRandomInteger;
//common.getAppType = Util.getAppType;
//common.notAgainForAnother = Util.notAgainForAnother;
//common.uid = Util.uid;
//common.slice = Util.slice;
// import hash utilities for export
//var createRandomHash = common.createRandomHash = Hash.createRandomHash;
//common.parseTypeHash = Hash.parseTypeHash;
//var parsePadUrl = common.parsePadUrl = Hash.parsePadUrl;
//common.isNotStrongestStored = Hash.isNotStrongestStored;
//var hrefToHexChannelId = common.hrefToHexChannelId = Hash.hrefToHexChannelId;
//var getRelativeHref = common.getRelativeHref = Hash.getRelativeHref;
//common.getBlobPathFromHex = Hash.getBlobPathFromHex;
//common.getEditHashFromKeys = Hash.getEditHashFromKeys;
//common.getViewHashFromKeys = Hash.getViewHashFromKeys;
//common.getFileHashFromKeys = Hash.getFileHashFromKeys;
//common.getUserHrefFromKeys = Hash.getUserHrefFromKeys;
//common.getSecrets = Hash.getSecrets;
//common.getHashes = Hash.getHashes;
//common.createChannelId = Hash.createChannelId;
//common.findWeaker = Hash.findWeaker;
//common.findStronger = Hash.findStronger;
//common.serializeHash = Hash.serializeHash;
//common.createInviteUrl = Hash.createInviteUrl;
// Messaging
//common.addDirectMessageHandler = Messaging.addDirectMessageHandler;
//common.inviteFromUserlist = Messaging.inviteFromUserlist;
//common.getFriendList = Messaging.getFriendList;
//common.getFriendChannelsList = Messaging.getFriendChannelsList;
//common.createData = Messaging.createData;
//common.getPendingInvites = Messaging.getPending;
//common.getLatestMessages = Messaging.getLatestMessages;
// Realtime
//var whenRealtimeSyncs = common.whenRealtimeSyncs = function (realtime, cb) {
//Realtime.whenRealtimeSyncs(common, realtime, cb);
//};
//common.beginDetectingInfiniteSpinner = function (realtime) {
//Realtime.beginDetectingInfiniteSpinner(common, realtime);
//};
var getStore = common.getStore = function () {
if (store) { return store; }
throw new Error("Store is not ready!");
@ -157,62 +91,6 @@ define([
if (typeof cb === "function") { cb(null, name); }
return name;
};
common.getAccountName = function () {
return localStorage[Constants.userNameKey];
};
// REFACTOR: move to util?
var randomToken = function () {
return Math.random().toString(16).replace(/0./, '');
};
common.isFeedbackAllowed = function () {
try {
var entry = Util.find(getProxy(), [
'settings',
'general',
'allowUserFeedback'
]);
if (!entry) { return false; }
return true;
} catch (e) {
console.error(e);
return false;
}
};
var feedback = common.feedback = function (action, force) {
if (!action) { return; }
if (force !== true) {
try {
if (!common.isFeedbackAllowed()) { return; }
} catch (e) { return void console.error(e); }
}
var href = '/common/feedback.html?' + action + '=' + randomToken();
$.ajax({
type: "HEAD",
url: href,
});
};
common.reportAppUsage = function () {
var pattern = window.location.pathname.split('/')
.filter(function (x) { return x; }).join('.');
if (/^#\/1\/view\//.test(window.location.hash)) {
feedback(pattern + '_VIEW');
} else {
feedback(pattern);
}
};
common.reportScreenDimensions = function () {
var h = window.innerHeight;
var w = window.innerWidth;
feedback('DIMENSIONS:' + h + 'x' + w);
};
common.reportLanguage = function () {
feedback('LANG_' + Messages._languageUsed);
};
common.getUid = function () {
if (store && store.getProxy() && store.getProxy().proxy) {
@ -227,94 +105,6 @@ define([
return;
};
common.getWebsocketURL = function () {
if (!Config.websocketPath) { return Config.websocketURL; }
var path = Config.websocketPath;
if (/^ws{1,2}:\/\//.test(path)) { return path; }
var protocol = window.location.protocol.replace(/http/, 'ws');
var host = window.location.host;
var url = protocol + '//' + host + path;
return url;
};
common.login = function (hash, name, cb) {
if (!hash) { throw new Error('expected a user hash'); }
if (!name) { throw new Error('expected a user name'); }
hash = Hash.serializeHash(hash);
localStorage.setItem(Constants.userHashKey, hash);
localStorage.setItem(Constants.userNameKey, name);
if (cb) { cb(); }
};
var eraseTempSessionValues = common.eraseTempSessionValues = function () {
// delete sessionStorage values that might have been left over
// from the main page's /user redirect
[
'login',
'login_user',
'login_pass',
'login_rmb',
'register'
].forEach(function (k) {
delete sessionStorage[k];
});
};
var logoutHandlers = [];
common.logout = function (cb) {
[
Constants.userNameKey,
Constants.userHashKey,
'loginToken',
'plan',
].forEach(function (k) {
sessionStorage.removeItem(k);
localStorage.removeItem(k);
delete localStorage[k];
delete sessionStorage[k];
});
localForage.clear();
// Make sure we have an FS_hash in localStorage before reloading all the tabs
// so that we don't end up with tabs using different anon hashes
if (!localStorage[Constants.fileHashKey]) {
localStorage[Constants.fileHashKey] = Hash.createRandomHash();
}
eraseTempSessionValues();
logoutHandlers.forEach(function (h) {
if (typeof (h) === "function") { h(); }
});
if (cb) { cb(); }
};
common.onLogout = function (h) {
if (typeof (h) !== "function") { return; }
if (logoutHandlers.indexOf(h) !== -1) { return; }
logoutHandlers.push(h);
};
var getUserHash = common.getUserHash = function () {
var hash = localStorage[Constants.userHashKey];
if (['undefined', 'undefined/'].indexOf(hash) !== -1) {
localStorage.removeItem(Constants.userHashKey);
return;
}
if (hash) {
var sHash = Hash.serializeHash(hash);
if (sHash !== hash) { localStorage[Constants.userHashKey] = sHash; }
}
return hash;
};
var isLoggedIn = common.isLoggedIn = function () {
return typeof getUserHash() === "string";
};
common.hasSigningKeys = function (proxy) {
return typeof(proxy) === 'object' &&
typeof(proxy.edPrivate) === 'string' &&
@ -336,11 +126,6 @@ define([
};
};
common.isArray = $.isArray;
/*
* localStorage formatting
*/
var makePad = common.makePad = function (href, title) {
var now = +new Date();
return {
@ -367,9 +152,6 @@ define([
if (cb) { cb(err, data); }
});
};
common.setLSAttribute = function (attr, value) {
localStorage[attr] = value;
};
// STORAGE
common.getPadAttribute = function (attr, cb) {
@ -382,15 +164,6 @@ define([
});
};
common.setThumbnail = function (key, value, cb) {
localForage.setItem(key, value, cb);
};
common.getThumbnail = function (key, cb) {
localForage.getItem(key, cb);
};
common.clearThumbnail = function (cb) {
localForage.clear(cb);
};
/* this returns a reference to your proxy. changing it will change your drive.
*/
@ -482,10 +255,6 @@ define([
cb(void 0, all);
};
common.getLSAttribute = function (attr) {
return localStorage[attr];
};
// STORAGE - TEMPLATES
var listTemplates = common.listTemplates = function (type) {
var allTemplates = getStore().listTemplates();
@ -746,7 +515,7 @@ define([
};
var pinsReady = common.pinsReady = function () {
if (!isLoggedIn()) {
if (!LocalStore.isLoggedIn()) {
return false;
}
if (!PINNING_ENABLED) {
@ -883,7 +652,7 @@ define([
};
common.isOverPinLimit = function (cb) {
if (!common.isLoggedIn()) { return void cb(null, false); }
if (!LocalStore.isLoggedIn()) { return void cb(null, false); }
var usage;
var andThen = function (e, limit, plan) {
if (e) { return void cb(e); }
@ -960,52 +729,6 @@ define([
});
};
$(window.document).on('decryption', function (e) {
var decrypted = e.originalEvent;
if (decrypted.callback) {
var cb = decrypted.callback;
cb(function (mediaObject) {
var root = mediaObject.element;
if (!root) { return; }
if (mediaObject.type === 'image') {
$(root).data('blob', decrypted.blob);
}
if (mediaObject.type !== 'download') { return; }
var metadata = decrypted.metadata;
var title = '';
var size = 0;
if (metadata && metadata.name) {
title = metadata.name;
}
if (decrypted.blob) {
size = decrypted.blob.size;
}
var sizeMb = Util.bytesToMegabytes(size);
var $btn = $(root).find('button');
$btn.addClass('btn btn-success')
.attr('type', 'download')
.html(function () {
var text = Messages.download_mt_button + '<br>';
if (title) {
text += '<b>' + Util.fixHTML(title) + '</b><br>';
}
if (size) {
text += '<em>' + Messages._getKey('formattedMB', [sizeMb]) + '</em>';
}
return text;
});
});
}
});
common.getShareHashes = function (secret, cb) {
if (!window.location.hash) {
var hashes = Hash.getHashes(secret.channel, secret);
@ -1072,27 +795,42 @@ define([
var network;
var provideFeedback = function () {
if (Object.keys(proxy).length === 1) {
feedback("FIRST_APP_USE", true);
Feedback.send("FIRST_APP_USE", true);
}
if (typeof(window.Proxy) === 'undefined') {
feedback("NO_PROXIES");
Feedback.send("NO_PROXIES");
}
var shimPattern = /CRYPTPAD_SHIM/;
if (shimPattern.test(Array.isArray.toString())) {
feedback("NO_ISARRAY");
Feedback.send("NO_ISARRAY");
}
if (shimPattern.test(Array.prototype.fill.toString())) {
feedback("NO_ARRAYFILL");
Feedback.send("NO_ARRAYFILL");
}
if (typeof(Symbol) === 'undefined') {
feedback('NO_SYMBOL');
Feedback.send('NO_SYMBOL');
}
common.reportScreenDimensions();
common.reportLanguage();
Feedback.reportScreenDimensions();
Feedback.reportLanguage();
};
var initFeedback = function () {
// Initialize feedback
try {
var entry = Util.find(getProxy(), [
'settings',
'general',
'allowUserFeedback'
]);
Feedback.init(entry);
} catch (e) {
console.error(e);
Feedback.init(false);
}
provideFeedback();
};
Nthen(function (waitFor) {
@ -1107,7 +845,7 @@ define([
network.on('reconnect', function () {
Realtime.setConnectionState(true);
});
provideFeedback();
initFeedback();
}), common);
}).nThen(function (waitFor) {
$(waitFor());
@ -1137,15 +875,14 @@ define([
if (!o && n) {
document.location.reload();
} else if (o && !n) {
common.logout();
LocalStore.logout();
if (getNetwork()) {
getNetwork().disconnect();
}
}
});
if (PINNING_ENABLED && isLoggedIn()) {
if (PINNING_ENABLED && LocalStore.isLoggedIn()) {
console.log("logged in. pads will be pinned");
var w0 = waitFor();
Pinpad.create(network, proxy, function (e, call) {
@ -1241,7 +978,7 @@ define([
if (sessionStorage.migrateAnonDrive) {
var w = waitFor();
require(['/common/mergeDrive.js'], function (Merge) {
var hash = localStorage.FS_hash;
var hash = LocalStore.getFSHash();
Merge.anonDriveIntoUser(getStore().getProxy(), hash, function () {
delete sessionStorage.migrateAnonDrive;
w();

@ -6,9 +6,13 @@ define([
'/common/userObject.js',
'/common/common-interface.js',
'/common/common-hash.js',
'/common/common-util.js',
'/common/common-constants.js',
'/common/migrate-user-object.js',
], function ($, Listmap, Crypto, TextPatcher, FO, UI, Hash, Constants, Migrate) {
'/common/outer/network-config.js',
'/common/outer/local-store.js',
], function ($, Listmap, Crypto, TextPatcher, FO, UI, Hash, Util, Constants, Migrate, NetConfig,
LocalStore) {
/*
This module uses localStorage, which is synchronous, but exposes an
asyncronous API. This is so that we can substitute other storage
@ -192,7 +196,7 @@ define([
var onReady = function (f, proxy, Cryptpad, exp) {
var fo = exp.fo = FO.init(proxy.drive, {
Cryptpad: Cryptpad,
loggedIn: Cryptpad.isLoggedIn()
loggedIn: LocalStore.isLoggedIn()
});
var todo = function () {
fo.fixFiles();
@ -207,7 +211,7 @@ define([
var requestLogin = function () {
// log out so that you don't go into an endless loop...
Cryptpad.logout();
LocalStore.logout();
// redirect them to log in, and come back when they're done.
sessionStorage.redirectTo = window.location.href;
@ -215,7 +219,7 @@ define([
};
var tokenKey = 'loginToken';
if (Cryptpad.isLoggedIn()) {
if (LocalStore.isLoggedIn()) {
/* This isn't truly secure, since anyone who can read the user's object can
set their local loginToken to match that in the object. However, it exposes
a UI that will work most of the time. */
@ -254,7 +258,7 @@ define([
}
// if the user is logged in, but does not have signing keys...
if (Cryptpad.isLoggedIn() && (!Cryptpad.hasSigningKeys(proxy) ||
if (LocalStore.isLoggedIn() && (!Cryptpad.hasSigningKeys(proxy) ||
!Cryptpad.hasCurveKeys(proxy))) {
return void requestLogin();
}
@ -287,14 +291,14 @@ define([
if (!Cryptpad || initialized) { return; }
initialized = true;
var hash = Cryptpad.getUserHash() || localStorage.FS_hash || Hash.createRandomHash();
var hash = LocalStore.getUserHash() || LocalStore.getFSHash() || Hash.createRandomHash();
if (!hash) {
throw new Error('[Store.init] Unable to find or create a drive hash. Aborting...');
}
var secret = Hash.getSecrets('drive', hash);
var listmapConfig = {
data: {},
websocketURL: Cryptpad.getWebsocketURL(),
websocketURL: NetConfig.getWebsocketURL(),
channel: secret.channel,
readOnly: false,
validateKey: secret.keys.validateKey || undefined,
@ -311,8 +315,8 @@ define([
exp.proxy = rt.proxy;
rt.proxy.on('create', function (info) {
exp.info = info;
if (!Cryptpad.getUserHash()) {
localStorage.FS_hash = Hash.getEditHashFromKeys(info.channel, secret.keys);
if (!LocalStore.getUserHash()) {
LocalStore.setFSHash(Hash.getEditHashFromKeys(info.channel, secret.keys));
}
}).on('ready', function () {
if (store) { return; } // the store is already ready, it is a reconnection

@ -2,12 +2,12 @@ define([
'jquery',
'/bower_components/chainpad-listmap/chainpad-listmap.js',
'/bower_components/chainpad-crypto/crypto.js',
'/common/cryptpad-common.js',
'/common/common-util.js',
'/common/outer/network-config.js',
'/common/credential.js',
'/bower_components/tweetnacl/nacl-fast.min.js',
'/bower_components/scrypt-async/scrypt-async.min.js', // better load speed
], function ($, Listmap, Crypto, Cryptpad, Util, Cred) {
], function ($, Listmap, Crypto, Util, NetConfig, Cred) {
var Exports = {
Cred: Cred,
};
@ -58,7 +58,7 @@ define([
var loadUserObject = function (opt, cb) {
var config = {
websocketURL: Cryptpad.getWebsocketURL(),
websocketURL: NetConfig.getWebsocketURL(),
channel: opt.channelHex,
data: {},
validateKey: opt.keys.validateKey, // derived validation key

@ -1,9 +1,9 @@
define([
'/common/cryptpad-common.js',
'/common/cryptget.js',
'/common/userObject.js',
'/common/common-hash.js',
], function (Cryptpad, Crypt, FO, Hash) {
'/common/outer/local-store.js',
], function (Crypt, FO, Hash, LocalStore) {
var exp = {};
var getType = function (el) {
@ -86,7 +86,7 @@ define([
exp.anonDriveIntoUser = function (proxyData, fsHash, cb) {
// Make sure we have an FS_hash and we don't use it, otherwise just stop the migration and cb
if (!fsHash || !Cryptpad.isLoggedIn()) {
if (!fsHash || !LocalStore.isLoggedIn()) {
if (typeof(cb) === "function") { return void cb(); }
}
// Get the content of FS_hash and then merge the objects, remove the migration key and cb
@ -105,7 +105,7 @@ define([
if (parsed) {
var proxy = proxyData.proxy;
var oldFo = FO.init(parsed.drive, {
loggedIn: Cryptpad.isLoggedIn()
loggedIn: LocalStore.isLoggedIn()
});
var onMigrated = function () {
oldFo.fixFiles();

@ -1,10 +1,10 @@
define([], function () {
define(['/common/common-feedback.js'], function (Feedback) {
// Start migration check
// Versions:
// 1: migrate pad attributes
// 2: migrate indent settings (codemirror)
return function (userObject, Cryptpad) {
return function (userObject) {
var version = userObject.version || 0;
// DEPRECATED
@ -46,7 +46,7 @@ define([], function () {
};
if (version < 2) {
migrateAttributes();
Cryptpad.feedback('Migrate-2', true);
Feedback.send('Migrate-2', true);
userObject.version = version = 2;
}
@ -60,7 +60,7 @@ define([], function () {
};
if (version < 3) {
migrateLanguage();
Cryptpad.feedback('Migrate-3', true);
Feedback.send('Migrate-3', true);
userObject.version = version = 3;
}
@ -77,7 +77,7 @@ define([], function () {
};
if (version < 4) {
migrateFeedback();
Cryptpad.feedback('Migrate-4', true);
Feedback.send('Migrate-4', true);
userObject.version = version = 4;
}
@ -99,7 +99,7 @@ define([], function () {
};
if (version < 5) {
migrateDates();
Cryptpad.feedback('Migrate-5', true);
Feedback.send('Migrate-5', true);
userObject.version = version = 5;
}
};

@ -0,0 +1,125 @@
define([
'/common/common-constants.js',
'/common/common-hash.js',
'/bower_components/localforage/dist/localforage.min.js',
], function (Constants, Hash, localForage) {
var LocalStore = {};
LocalStore.setThumbnail = function (key, value, cb) {
localForage.setItem(key, value, cb);
};
LocalStore.getThumbnail = function (key, cb) {
localForage.getItem(key, cb);
};
LocalStore.clearThumbnail = function (cb) {
cb = cb || function () {};
localForage.clear(cb);
};
LocalStore.setFSHash = function (hash) {
var sHash = Hash.serializeHash(hash);
localStorage[Constants.fileHashKey] = sHash;
};
LocalStore.getFSHash = function () {
var hash = localStorage[Constants.fileHashKey];
if (['undefined', 'undefined/'].indexOf(hash) !== -1) {
localStorage.removeItem(Constants.fileHashKey);
return;
}
if (hash) {
var sHash = Hash.serializeHash(hash);
if (sHash !== hash) { localStorage[Constants.fileHashKey] = sHash; }
}
return hash;
};
var getUserHash = LocalStore.getUserHash = function () {
var hash = localStorage[Constants.userHashKey];
if (['undefined', 'undefined/'].indexOf(hash) !== -1) {
localStorage.removeItem(Constants.userHashKey);
return;
}
if (hash) {
var sHash = Hash.serializeHash(hash);
if (sHash !== hash) { localStorage[Constants.userHashKey] = sHash; }
}
return hash;
};
LocalStore.getAccountName = function () {
return localStorage[Constants.userNameKey];
};
LocalStore.isLoggedIn = function () {
return typeof getUserHash() === "string";
};
LocalStore.login = function (hash, name, cb) {
if (!hash) { throw new Error('expected a user hash'); }
if (!name) { throw new Error('expected a user name'); }
hash = Hash.serializeHash(hash);
localStorage.setItem(Constants.userHashKey, hash);
localStorage.setItem(Constants.userNameKey, name);
if (cb) { cb(); }
};
var eraseTempSessionValues = LocalStore.eraseTempSessionValues = function () {
// delete sessionStorage values that might have been left over
// from the main page's /user redirect
[
'login',
'login_user',
'login_pass',
'login_rmb',
'register'
].forEach(function (k) {
delete sessionStorage[k];
});
};
var logoutHandlers = [];
LocalStore.logout = function (cb) {
[
Constants.userNameKey,
Constants.userHashKey,
'loginToken',
'plan',
].forEach(function (k) {
sessionStorage.removeItem(k);
localStorage.removeItem(k);
delete localStorage[k];
delete sessionStorage[k];
});
LocalStore.clearThumbnail();
// Make sure we have an FS_hash in localStorage before reloading all the tabs
// so that we don't end up with tabs using different anon hashes
if (!LocalStore.getFSHash()) {
LocalStore.setFSHash(Hash.createRandomHash());
}
eraseTempSessionValues();
logoutHandlers.forEach(function (h) {
if (typeof (h) === "function") { h(); }
});
if (cb) { cb(); }
};
LocalStore.onLogout = function (h) {
if (typeof (h) !== "function") { return; }
if (logoutHandlers.indexOf(h) !== -1) { return; }
logoutHandlers.push(h);
};
return LocalStore;
});

@ -0,0 +1,19 @@
define([
'/api/config'
], function (ApiConfig) {
var Config = {};
Config.getWebsocketURL = function () {
if (!ApiConfig.websocketPath) { return ApiConfig.websocketURL; }
var path = ApiConfig.websocketPath;
if (/^ws{1,2}:\/\//.test(path)) { return path; }
var protocol = window.location.protocol.replace(/http/, 'ws');
var host = window.location.host;
var url = protocol + '//' + host + path;
return url;
};
return Config;
});

@ -11,6 +11,7 @@ define([
'/common/common-util.js',
'/common/common-interface.js',
'/common/common-thumbnail.js',
'/common/common-feedback.js',
'/customize/application_config.js',
'/bower_components/file-saver/FileSaver.min.js',
@ -30,6 +31,7 @@ define([
Util,
UI,
Thumb,
Feedback,
AppConfig)
{
var SaveAs = window.saveAs;
@ -330,7 +332,7 @@ define([
var feedback = function (action, force) {
if (state === STATE.DISCONNECTED || state === STATE.INITIALIZING) { return; }
common.feedback(action, force);
Feedback.send(action, force);
};
var createFilePicker = function () {

@ -212,6 +212,7 @@ define([
left: true, // Open to the left of the button
isSelect: true,
feedback: 'CODE_LANGUAGE',
common: Common
};
var $block = exp.$language = UIElements.createDropdown(dropdownConfig);
$block.find('button').attr('title', Messages.languageButtonTitle);
@ -249,6 +250,7 @@ define([
isSelect: true,
initialValue: lastTheme,
feedback: 'CODE_THEME',
common: Common
};
var $block = exp.$theme = UIElements.createDropdown(dropdownConfig);
$block.find('button').attr('title', Messages.themeButtonTitle);

@ -38,8 +38,12 @@ define([
'/common/common-hash.js',
'/common/common-util.js',
'/common/common-realtime.js',
'/common/common-constants.js',
'/common/common-feedback.js',
'/common/outer/local-store.js',
], waitFor(function (_CpNfOuter, _Cryptpad, _Crypto, _Cryptget, _SFrameChannel,
_FilePicker, _Messenger, _Messaging, _Notifier, _Hash, _Util, _Realtime) {
_FilePicker, _Messenger, _Messaging, _Notifier, _Hash, _Util, _Realtime,
_Constants, _Feedback, _LocalStore) {
CpNfOuter = _CpNfOuter;
Cryptpad = _Cryptpad;
Crypto = _Crypto;
@ -52,6 +56,9 @@ define([
Utils.Hash = _Hash;
Utils.Util = _Util;
Utils.Realtime = _Realtime;
Utils.Constants = _Constants;
Utils.Feedback = _Feedback;
Utils.LocalStore = _LocalStore;
if (localStorage.CRYPTPAD_URLARGS !== ApiConfig.requireConf.urlArgs) {
console.log("New version, flushing cache");
@ -135,14 +142,14 @@ define([
},
priv: {
edPublic: proxy.edPublic,
accountName: Cryptpad.getAccountName(),
accountName: Utils.LocalStore.getAccountName(),
origin: window.location.origin,
pathname: window.location.pathname,
fileHost: ApiConfig.fileHost,
readOnly: readOnly,
availableHashes: hashes,
isTemplate: Cryptpad.isTemplate(window.location.href),
feedbackAllowed: Cryptpad.isFeedbackAllowed(),
feedbackAllowed: Utils.Feedback.state,
friends: proxy.friends || {},
settings: proxy.settings || {},
isPresent: parsed.hashData && parsed.hashData.present,
@ -164,7 +171,7 @@ define([
sframeChan.onReg('EV_METADATA_UPDATE', updateMeta);
proxy.on('change', 'settings', updateMeta);
Cryptpad.onLogout(function () {
Utils.LocalStore.onLogout(function () {
sframeChan.event('EV_LOGOUT');
});
@ -187,7 +194,7 @@ define([
});
sframeChan.on('Q_THUMBNAIL_GET', function (data, cb) {
Cryptpad.getThumbnail(data.key, function (e, data) {
Utils.LocalStore.getThumbnail(data.key, function (e, data) {
cb({
error: e,
data: data
@ -195,7 +202,7 @@ define([
});
});
sframeChan.on('Q_THUMBNAIL_SET', function (data, cb) {
Cryptpad.setThumbnail(data.key, data.value, function (e) {
Utils.LocalStore.setThumbnail(data.key, data.value, function (e) {
cb({error:e});
});
});
@ -240,7 +247,7 @@ define([
});
sframeChan.on('Q_LOGOUT', function (data, cb) {
Cryptpad.logout(cb);
Utils.LocalStore.logout(cb);
});
sframeChan.on('EV_NOTIFY', function () {
@ -415,7 +422,8 @@ define([
config.addCommonRpc = addCommonRpc;
config.modules = {
Cryptpad: Cryptpad,
SFrameChannel: SFrameChannel
SFrameChannel: SFrameChannel,
Utils: Utils
};
FP.$iframe = $('<iframe>', {id: 'sbox-filePicker-iframe'}).appendTo($('body'));
FP.picker = FilePicker.create(config);
@ -602,7 +610,7 @@ define([
sframeChan.ready();
Cryptpad.reportAppUsage();
Utils.Feedback.reportAppUsage();
if (!realtime) { return; }

@ -17,6 +17,7 @@ define([
'/common/common-hash.js',
'/common/common-thumbnail.js',
'/common/common-interface.js',
'/common/common-feedback.js',
'/bower_components/localforage/dist/localforage.min.js'
], function (
$,
@ -36,6 +37,7 @@ define([
Hash,
Thumb,
UI,
Feedback,
localForage
) {
// Chainpad Netflux Inner
@ -271,27 +273,12 @@ define([
};
// Feedback
funcs.feedback = function (action, force) {
if (force !== true) {
if (!action) { return; }
try {
if (!ctx.metadataMgr.getPrivateData().feedbackAllowed) { return; }
} catch (e) { return void console.error(e); }
}
var randomToken = Math.random().toString(16).replace(/0./, '');
//var origin = ctx.metadataMgr.getPrivateData().origin;
var href = /*origin +*/ '/common/feedback.html?' + action + '=' + randomToken;
$.ajax({
type: "HEAD",
url: href,
});
};
funcs.prepareFeedback = function (key) {
if (typeof(key) !== 'string') { return $.noop; }
var type = ctx.metadataMgr.getMetadata().type;
return function () {
funcs.feedback((key + (type? '_' + type: '')).toUpperCase());
Feedback.send((key + (type? '_' + type: '')).toUpperCase());
};
};
@ -394,6 +381,13 @@ define([
UI.log(data.logText);
});
ctx.metadataMgr.onChange(function () {
try {
var feedback = ctx.metadataMgr.getPrivateData().feedbackAllowed;
Feedback.init(feedback);
} catch (e) { Feedback.init(false); }
});
ctx.sframeChan.ready();
cb(funcs);
});

@ -5,9 +5,10 @@ define([
'/common/common-ui-elements.js',
'/common/common-interface.js',
'/common/common-hash.js',
'/common/common-feedback.js',
'/customize/messages.js',
'/common/clipboard.js',
], function ($, Config, ApiConfig, UIElements, UI, Hash, Messages, Clipboard) {
], function ($, Config, ApiConfig, UIElements, UI, Hash, Feedback, Messages, Clipboard) {
var Common;
var Bar = {
@ -419,7 +420,7 @@ define([
else { show(); }
visible = !visible;
Common.setAttribute(['toolbar', 'userlist-drawer'], visible);
Common.feedback(visible?'USERLIST_SHOW': 'USERLIST_HIDE');
Feedback.send(visible?'USERLIST_SHOW': 'USERLIST_HIDE');
});
show();
Common.getAttribute(['toolbar', 'userlist-drawer'], function (err, val) {
@ -498,6 +499,7 @@ define([
text: $('<div>').append($shareIcon).html(),
options: options,
feedback: 'SHARE_MENU',
common: Common
};
var $shareBlock = UIElements.createDropdown(dropdownConfigShare);
$shareBlock.find('.cp-dropdown-content').addClass(SHARE_CLS).addClass(EDITSHARE_CLS).addClass(VIEWSHARE_CLS);
@ -583,6 +585,7 @@ define([
text: $('<div>').append($shareIcon).html(),
options: options,
feedback: 'FILESHARE_MENU',
common: Common
};
var $shareBlock = UIElements.createDropdown(dropdownConfigShare);
$shareBlock.find('.cp-dropdown-content').addClass(SHARE_CLS);
@ -868,6 +871,7 @@ define([
left: true,
feedback: /drive/.test(window.location.pathname)?
'DRIVE_NEWPAD': 'NEWPAD',
common: Common
};
var $newPadBlock = UIElements.createDropdown(dropdownConfig);
$newPadBlock.find('button').attr('title', Messages.newButtonTitle);
@ -909,7 +913,7 @@ define([
UI.prompt(Messages.changeNamePrompt, lastName || '', function (newName) {
if (newName === null && typeof(lastName) === "string") { return; }
if (newName === null) { newName = ''; }
else { Common.feedback('NAME_CHANGED'); }
else { Feedback.send('NAME_CHANGED'); }
setDisplayName(newName);
});
});

@ -8,7 +8,7 @@ define([
'/common/common-ui-elements.js',
'/common/common-interface.js',
'/common/common-constants.js',
'/common/cryptget.js',
'/common/common-feedback.js',
'/bower_components/nthen/index.js',
'/common/sframe-common.js',
'/common/common-realtime.js',
@ -30,7 +30,7 @@ define([
UIElements,
UI,
Constants,
Cryptget,
Feedback,
nThen,
SFCommon,
CommonRealtime,
@ -1417,7 +1417,7 @@ define([
setViewMode('list');
$('#' + FOLDER_CONTENT_ID).removeClass('cp-app-drive-content-grid');
$('#' + FOLDER_CONTENT_ID).addClass('cp-app-drive-content-list');
common.feedback('DRIVE_LIST_MODE');
Feedback.send('DRIVE_LIST_MODE');
});
$gridButton.click(function () {
$listButton.removeClass('cp-app-drive-toolbar-active');
@ -1425,7 +1425,7 @@ define([
setViewMode('grid');
$('#' + FOLDER_CONTENT_ID).addClass('cp-app-drive-content-grid');
$('#' + FOLDER_CONTENT_ID).removeClass('cp-app-drive-content-list');
common.feedback('DRIVE_GRID_MODE');
Feedback.send('DRIVE_GRID_MODE');
});
if (getViewMode() === 'list') {
@ -1548,6 +1548,7 @@ define([
text: $plusIcon.html() + '<span>'+Messages.fm_newButton+'</span>',
options: options,
feedback: 'DRIVE_NEWPAD_LOCALFOLDER',
common: common
};
var $block = UIElements.createDropdown(dropdownConfig);
@ -2946,7 +2947,7 @@ define([
}).nThen(function (/* waitFor */) {
APP.loggedIn = common.isLoggedIn();
APP.SFCommon = common;
if (!APP.loggedIn) { common.feedback('ANONYMOUS_DRIVE'); }
if (!APP.loggedIn) { Feedback.send('ANONYMOUS_DRIVE'); }
APP.$body = $('body');
APP.$bar = $('#cp-toolbar');

@ -5,9 +5,9 @@ define([
'jquery',
'/common/requireconfig.js',
'/common/sframe-common-outer.js',
'/common/cryptpad-common.js',
'/common/outer/network-config.js',
'/bower_components/netflux-websocket/netflux-client.js',
], function (nThen, ApiConfig, $, RequireConfig, SFCommonO, Cryptpad, Netflux) {
], function (nThen, ApiConfig, $, RequireConfig, SFCommonO, NetConfig, Netflux) {
var requireConfig = RequireConfig();
// Loaded in load #2
@ -39,10 +39,11 @@ define([
window.addEventListener('message', onMsg);
}).nThen(function (/*waitFor*/) {
var getSecrets = function (Cryptpad, Utils) {
var hash = window.location.hash.slice(1) || Cryptpad.getUserHash() || localStorage.FS_hash;
var hash = window.location.hash.slice(1) || Utils.LocalStore.getUserHash() ||
Utils.LocalStore.getFSHash();
return Utils.Hash.getSecrets('drive', hash);
};
Netflux.connect(Cryptpad.getWebsocketURL()).then(function (network) {
Netflux.connect(NetConfig.getWebsocketURL()).then(function (network) {
SFCommonO.start({
getSecrets: getSecrets,
newNetwork: network,

@ -37,10 +37,10 @@ define([
};
window.addEventListener('message', onMsg);
}).nThen(function (/*waitFor*/) {
var Cryptpad;
var Cryptpad = config.modules.Cryptpad;
var Utils = config.modules.Utils;
nThen(function (waitFor) {
Cryptpad = config.modules.Cryptpad;
config.modules.SFrameChannel.create($('#sbox-filePicker-iframe')[0].contentWindow,
waitFor(function (sfc) {
sframeChan = sfc;
@ -67,10 +67,10 @@ define([
netfluxId: Cryptpad.getNetwork().webChannels[0].myID,
},
priv: {
accountName: Cryptpad.getAccountName(),
accountName: Utils.LocalStore.getAccountName(),
origin: window.location.origin,
pathname: window.location.pathname,
feedbackAllowed: Cryptpad.isFeedbackAllowed(),
feedbackAllowed: Utils.Feedback.state,
friends: proxy.friends || {},
settings: proxy.settings || {},
types: config.types

@ -81,7 +81,6 @@ define([
APP.$container = $('#container');
Cryptpad.ready(function () {
Cryptpad.reportAppUsage();
andThen();
});
});

@ -4,9 +4,11 @@ define([
'/common/login.js',
'/common/common-interface.js',
'/common/common-realtime.js',
'/common/common-feedback.js',
'/common/outer/local-store.js',
'less!/bower_components/components-font-awesome/css/font-awesome.min.css',
], function ($, Cryptpad, Login, UI, Realtime) {
], function ($, Cryptpad, Login, UI, Realtime, Feedback, LocalStore) {
$(function () {
var $main = $('#mainBlock');
var Messages = Cryptpad.Messages;
@ -17,7 +19,7 @@ define([
// Make sure we don't display non-translated content (empty button)
$main.find('#data').removeClass('hidden');
if (Cryptpad.isLoggedIn()) {
if (LocalStore.isLoggedIn()) {
// already logged in, redirect to drive
document.location.href = '/drive/';
return;
@ -83,9 +85,9 @@ define([
proxy.curvePrivate = result.curvePrivate;
proxy.curvePublic = result.curvePublic;
Cryptpad.feedback('LOGIN', true);
Feedback.send('LOGIN', true);
Realtime.whenRealtimeSyncs(result.realtime, function() {
Cryptpad.login(result.userHash, result.userName, function () {
LocalStore.login(result.userHash, result.userName, function () {
hashing = false;
if (sessionStorage.redirectTo) {
var h = sessionStorage.redirectTo;

@ -48,7 +48,7 @@ define([
return Hash.getSecrets('profile', obj.profile.edit);
}
// 3rd case: profile creation (create a new random hash, store it later if needed)
if (!Cryptpad.isLoggedIn()) { return; }
if (!Utils.LocalStore.isLoggedIn()) { return; }
var hash = Hash.createRandomHash();
var secret = Hash.getSecrets('profile', hash);
Cryptpad.pinPads([secret.channel], function (e) {

@ -8,9 +8,11 @@ define([
'/common/common-util.js',
'/common/common-realtime.js',
'/common/common-constants.js',
'/common/common-feedback.js',
'/common/outer/local-store.js',
'less!/bower_components/components-font-awesome/css/font-awesome.min.css',
], function ($, Login, Cryptpad, Test, Cred, UI, Util, Realtime, Constants) {
], function ($, Login, Cryptpad, Test, Cred, UI, Util, Realtime, Constants, Feedback, LocalStore) {
var Messages = Cryptpad.Messages;
$(function () {
@ -22,7 +24,7 @@ define([
// Make sure we don't display non-translated content (empty button)
$main.find('#data').removeClass('hidden');
if (Cryptpad.isLoggedIn()) {
if (LocalStore.isLoggedIn()) {
// already logged in, redirect to drive
document.location.href = '/drive/';
return;
@ -66,10 +68,10 @@ define([
proxy.curvePublic = result.curvePublic;
proxy.curvePrivate = result.curvePrivate;
Cryptpad.feedback('REGISTRATION', true);
Feedback.send('REGISTRATION', true);
Realtime.whenRealtimeSyncs(result.realtime, function () {
Cryptpad.login(result.userHash, result.userName, function () {
LocalStore.login(result.userHash, result.userName, function () {
registering = false;
if (sessionStorage.redirectTo) {
var h = sessionStorage.redirectTo;
@ -178,7 +180,7 @@ define([
if (!proxy[Constants.displayNameKey]) {
proxy[Constants.displayNameKey] = uname;
}
Cryptpad.eraseTempSessionValues();
LocalStore.eraseTempSessionValues();
logMeIn(result);
});
});
@ -192,7 +194,7 @@ define([
if (Test.testing) { return void logMeIn(result); }
Cryptpad.eraseTempSessionValues();
LocalStore.eraseTempSessionValues();
if (shouldImport) {
sessionStorage.migrateAnonDrive = 1;
}

@ -38,7 +38,7 @@ define([
}).nThen(function (/*waitFor*/) {
var addRpc = function (sframeChan, Cryptpad, Utils) {
sframeChan.on('Q_THUMBNAIL_CLEAR', function (d, cb) {
Cryptpad.clearThumbnail(function (err, data) {
Utils.LocalStore.clearThumbnail(function (err, data) {
cb({err:err, data:data});
});
});
@ -49,9 +49,8 @@ define([
var sjson = JSON.stringify(data);
require([
'/common/cryptget.js',
'/common/common-constants.js'
], function (Crypt, Constants) {
var k = Cryptpad.getUserHash() || localStorage[Constants.fileHashKey];
], function (Crypt) {
var k = Utils.LocalStore.getUserHash() || Utils.LocalStore.getFSHash();
Crypt.put(k, sjson, function (err) {
cb(err);
});
@ -75,9 +74,8 @@ define([
var proxyData = Cryptpad.getStore().getProxy();
require([
'/common/mergeDrive.js',
'/common/common-constants.js'
], function (Merge, Constants) {
Merge.anonDriveIntoUser(proxyData, localStorage[Constants.fileHashKey], cb);
], function (Merge) {
Merge.anonDriveIntoUser(proxyData, Utils.LocalStore.getFSHash(), cb);
});
});
};

@ -32,16 +32,7 @@ define([
APP.$container = $('#container');
Cryptpad.ready(function () {
//if (!Cryptpad.getUserHash()) { return redirectToMain(); }
//var storeObj = Cryptpad.getStore().getProxy && Cryptpad.getStore().getProxy().proxy
// ? Cryptpad.getStore().getProxy() : undefined;
//andThen(storeObj);
andThen();
Cryptpad.reportAppUsage();
});
andThen();
});
});

Loading…
Cancel
Save