fix merge conflicts
This commit is contained in:
commit
acfc27f5c5
@ -1,59 +1,87 @@
|
|||||||
define([
|
define([
|
||||||
'/customize/messages.js?app=read',
|
'/customize/messages.js?app=cryptget',
|
||||||
'/bower_components/chainpad-crypto/crypto.js',
|
'/bower_components/chainpad-crypto/crypto.js',
|
||||||
'/bower_components/chainpad-netflux/chainpad-netflux.js',
|
'/bower_components/chainpad-netflux/chainpad-netflux.js',
|
||||||
'/common/cryptpad-common.js',
|
'/common/cryptpad-common.js',
|
||||||
], function (Messages, Crypto, Realtime, Cryptpad) {
|
'/bower_components/textpatcher/TextPatcher.js',
|
||||||
var Crypt = {};
|
'/bower_components/jquery/dist/jquery.min.js',
|
||||||
|
], function (Messages, Crypto, Realtime, Cryptpad, TextPatcher) {
|
||||||
|
var noop = function () {};
|
||||||
|
var finish = function (S, err, doc) {
|
||||||
|
if (S.done) { return; }
|
||||||
|
S.cb(err, doc);
|
||||||
|
S.done = true;
|
||||||
|
|
||||||
var finish = function (Session, err, doc) {
|
var abort = Cryptpad.find(S, ['realtime', 'realtime', 'abort']);
|
||||||
if (Session.done) { return; }
|
if (typeof(abort) === 'function') {
|
||||||
Session.cb(err, doc);
|
S.realtime.realtime.sync();
|
||||||
Session.done = true;
|
abort();
|
||||||
|
}
|
||||||
var abort = Cryptpad.find(Session,
|
|
||||||
['realtime', 'realtime', 'abort']);
|
|
||||||
if (typeof(abort) === 'function') { abort(); }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var get = Crypt.get = function (hash, cb, opt) {
|
var makeConfig = function (hash) {
|
||||||
if (typeof(cb) !== 'function') {
|
var secret = Cryptpad.getSecrets(hash);
|
||||||
throw new Error('Crypt.get expects a callback');
|
if (!secret.keys) { secret.keys = secret.key; } // support old hashses
|
||||||
}
|
|
||||||
|
|
||||||
var Session = {
|
|
||||||
cb: cb,
|
|
||||||
};
|
|
||||||
opt = opt || {};
|
|
||||||
var secret = Session.secret = Cryptpad.getSecrets(hash);
|
|
||||||
|
|
||||||
var config = {
|
var config = {
|
||||||
websocketURL: Cryptpad.getWebsocketURL(),
|
websocketURL: Cryptpad.getWebsocketURL(),
|
||||||
channel: secret.channel,
|
channel: secret.channel,
|
||||||
|
validateKey: secret.keys.validateKey || undefined,
|
||||||
crypto: Crypto.createEncryptor(secret.keys),
|
crypto: Crypto.createEncryptor(secret.keys),
|
||||||
logLevel: 0,
|
logLevel: 0,
|
||||||
};
|
};
|
||||||
|
return config;
|
||||||
var onError = config.onError = function () {
|
|
||||||
finish(Session, Messages.websocketError);
|
|
||||||
};
|
|
||||||
var onAbort = config.onAbort = function () {
|
|
||||||
finish(Session, Messages.disconnectAlert);
|
|
||||||
};
|
|
||||||
|
|
||||||
var onReady = config.onReady = function (info) {
|
|
||||||
var realtime = Session.realtime = info.realtime;
|
|
||||||
finish(Session, void 0, realtime.getUserDoc());
|
|
||||||
};
|
|
||||||
|
|
||||||
var onConnectionChange = config.onConnectionChange = function (info) {
|
|
||||||
if (info.state) { return; }
|
|
||||||
finish(Session, Messages.disconnectAlert);
|
|
||||||
};
|
|
||||||
Object.keys(opt).forEach(function (k) { config[k] = opt[k]; });
|
|
||||||
|
|
||||||
return (Session.realtime = Realtime.start(config));
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return Crypt;
|
var isObject = function (o) {
|
||||||
|
return typeof(o) === 'object';
|
||||||
|
};
|
||||||
|
|
||||||
|
var overwrite = function (a, b) {
|
||||||
|
if (!(isObject(a) && isObject(b))) { return; }
|
||||||
|
Object.keys(b).forEach(function (k) { a[k] = b[k]; });
|
||||||
|
};
|
||||||
|
|
||||||
|
var get = function (hash, cb, opt) {
|
||||||
|
if (typeof(cb) !== 'function') {
|
||||||
|
throw new Error('Cryptget expects a callback');
|
||||||
|
}
|
||||||
|
var Session = { cb: cb, };
|
||||||
|
var config = makeConfig(hash);
|
||||||
|
|
||||||
|
var onReady = config.onReady = function (info) {
|
||||||
|
var rt = Session.session = info.realtime;
|
||||||
|
finish(Session, void 0, rt.getUserDoc());
|
||||||
|
};
|
||||||
|
overwrite(config, opt);
|
||||||
|
|
||||||
|
var realtime = Session.realtime = Realtime.start(config);
|
||||||
|
};
|
||||||
|
|
||||||
|
var put = function (hash, doc, cb, opt) {
|
||||||
|
if (typeof(cb) !== 'function') {
|
||||||
|
throw new Error('Cryptput expects a callback');
|
||||||
|
}
|
||||||
|
|
||||||
|
var config = makeConfig(hash);
|
||||||
|
var Session = { cb: cb, };
|
||||||
|
config.onReady = function (info) {
|
||||||
|
var realtime = Session.session = info.realtime;
|
||||||
|
|
||||||
|
TextPatcher.create({
|
||||||
|
realtime: realtime,
|
||||||
|
})(doc);
|
||||||
|
realtime.sync();
|
||||||
|
realtime.abort();
|
||||||
|
|
||||||
|
finish(Session, void 0);
|
||||||
|
};
|
||||||
|
overwrite(config, opt);
|
||||||
|
|
||||||
|
var realtime = Session.session = Realtime.start(config);
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
get: get,
|
||||||
|
put: put,
|
||||||
|
};
|
||||||
});
|
});
|
||||||
|
|||||||
@ -6,12 +6,10 @@ define([
|
|||||||
'/bower_components/alertifyjs/dist/js/alertify.js',
|
'/bower_components/alertifyjs/dist/js/alertify.js',
|
||||||
'/bower_components/spin.js/spin.min.js',
|
'/bower_components/spin.js/spin.min.js',
|
||||||
'/common/clipboard.js',
|
'/common/clipboard.js',
|
||||||
|
|
||||||
'/customize/fsStore.js',
|
'/customize/fsStore.js',
|
||||||
'/customize/user.js',
|
|
||||||
|
|
||||||
'/bower_components/jquery/dist/jquery.min.js',
|
'/bower_components/jquery/dist/jquery.min.js',
|
||||||
], function (Config, Messages, Store, Crypto, Alertify, Spinner, Clipboard, FS, User) {
|
], function (Config, Messages, Store, Crypto, Alertify, Spinner, Clipboard, FS) {
|
||||||
/* This file exposes functionality which is specific to Cryptpad, but not to
|
/* This file exposes functionality which is specific to Cryptpad, but not to
|
||||||
any particular pad type. This includes functions for committing metadata
|
any particular pad type. This includes functions for committing metadata
|
||||||
about pads to your local storage for future use and improved usability.
|
about pads to your local storage for future use and improved usability.
|
||||||
@ -26,14 +24,11 @@ define([
|
|||||||
|
|
||||||
var storeToUse = USE_FS_STORE ? FS : Store;
|
var storeToUse = USE_FS_STORE ? FS : Store;
|
||||||
|
|
||||||
var common = {
|
var common = window.Cryptpad = {
|
||||||
User: User,
|
|
||||||
Messages: Messages,
|
Messages: Messages,
|
||||||
};
|
};
|
||||||
var store;
|
var store;
|
||||||
var fsStore;
|
var fsStore;
|
||||||
var userProxy;
|
|
||||||
var userStore;
|
|
||||||
|
|
||||||
var find = common.find = function (map, path) {
|
var find = common.find = function (map, path) {
|
||||||
return (map && path.reduce(function (p, n) {
|
return (map && path.reduce(function (p, n) {
|
||||||
@ -42,7 +37,6 @@ define([
|
|||||||
};
|
};
|
||||||
|
|
||||||
var getStore = common.getStore = function (legacy) {
|
var getStore = common.getStore = function (legacy) {
|
||||||
if (!legacy && userStore) { return userStore; }
|
|
||||||
if ((!USE_FS_STORE || legacy) && store) { return store; }
|
if ((!USE_FS_STORE || legacy) && store) { return store; }
|
||||||
if (USE_FS_STORE && !legacy && fsStore) { return fsStore; }
|
if (USE_FS_STORE && !legacy && fsStore) { return fsStore; }
|
||||||
throw new Error("Store is not ready!");
|
throw new Error("Store is not ready!");
|
||||||
@ -60,42 +54,6 @@ define([
|
|||||||
return url;
|
return url;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
|
||||||
* cb(err, proxy);
|
|
||||||
*/
|
|
||||||
var authorize = common.authorize = function (cb) {
|
|
||||||
console.log("Authorizing");
|
|
||||||
|
|
||||||
User.session(void 0, function (err, secret) {
|
|
||||||
if (!secret) {
|
|
||||||
// user is not authenticated
|
|
||||||
cb('user is not authenticated', void 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// for now we assume that things always work
|
|
||||||
User.connect(secret, function (err, proxy) {
|
|
||||||
cb(void 0, proxy);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
// HERE
|
|
||||||
var deauthorize = common.deauthorize = function (cb) {
|
|
||||||
console.log("Deauthorizing");
|
|
||||||
|
|
||||||
// erase session data from storage
|
|
||||||
User.session(null, function (err) {
|
|
||||||
if (err) {
|
|
||||||
console.error(err);
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
TODO better abort for this stuff...
|
|
||||||
*/
|
|
||||||
userStore = undefined;
|
|
||||||
userProxy = undefined;
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
var userHashKey = common.userHashKey = 'User_hash';
|
var userHashKey = common.userHashKey = 'User_hash';
|
||||||
var fileHashKey = common.fileHashKey = 'FS_hash';
|
var fileHashKey = common.fileHashKey = 'FS_hash';
|
||||||
|
|
||||||
@ -677,48 +635,6 @@ define([
|
|||||||
}
|
}
|
||||||
cb();
|
cb();
|
||||||
});
|
});
|
||||||
return;
|
|
||||||
/*
|
|
||||||
authorize(function (err, proxy) {
|
|
||||||
/*
|
|
||||||
TODO
|
|
||||||
listen for log(in|out) events
|
|
||||||
update information accordingly
|
|
||||||
* /
|
|
||||||
|
|
||||||
store.change(function (data) {
|
|
||||||
if (data.key === User.localKey) {
|
|
||||||
// HERE
|
|
||||||
if (!data.newValue) {
|
|
||||||
deauthorize(function (err) {
|
|
||||||
console.log("Deauthorized!!");
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
authorize(function (err, proxy) {
|
|
||||||
if (err) {
|
|
||||||
// not logged in
|
|
||||||
}
|
|
||||||
if (!proxy) {
|
|
||||||
userProxy = proxy;
|
|
||||||
userStore = User.prepareStore(proxy);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (err) {
|
|
||||||
// not logged in
|
|
||||||
}
|
|
||||||
if (!proxy) {
|
|
||||||
cb();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
userProxy = env.proxy = proxy;
|
|
||||||
userStore = env.userStore = User.prepareStore(proxy);
|
|
||||||
cb();
|
|
||||||
|
|
||||||
}); */
|
|
||||||
}, common);
|
}, common);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -220,7 +220,6 @@ define([
|
|||||||
$logoutBox.slideDown();
|
$logoutBox.slideDown();
|
||||||
} else {
|
} else {
|
||||||
revealLogin();
|
revealLogin();
|
||||||
//$logoutBox.hide();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$login.click(function () {
|
$login.click(function () {
|
||||||
|
|||||||
@ -30,6 +30,9 @@ pre {
|
|||||||
<body>
|
<body>
|
||||||
<input id="target" type="text" value="/1/edit/xvhI6k6n7qYEtNL8cAv5zw/a4KKGGDY0S8GDj6m9iumX5E4"></input>
|
<input id="target" type="text" value="/1/edit/xvhI6k6n7qYEtNL8cAv5zw/a4KKGGDY0S8GDj6m9iumX5E4"></input>
|
||||||
<button id="get">get</button>
|
<button id="get">get</button>
|
||||||
<!-- <p>/1/edit/xvhI6k6n7qYEtNL8cAv5zw/a4KKGGDY0S8GDj6m9iumX5E4</p> -->
|
<hr />
|
||||||
<pre id="dest"></pre>
|
|
||||||
|
|
||||||
|
<textarea id="putter" type="text"></textarea>
|
||||||
|
<button id="put">put</button>
|
||||||
|
|
||||||
|
<button id="open">open</button>
|
||||||
|
|||||||
@ -9,8 +9,8 @@ define([
|
|||||||
|
|
||||||
var useDoc = function (err, doc) {
|
var useDoc = function (err, doc) {
|
||||||
if (err) { return console.error(err); }
|
if (err) { return console.error(err); }
|
||||||
console.log(doc);
|
//console.log(doc);
|
||||||
$dest.text(doc);
|
$('#putter').val(doc);
|
||||||
};
|
};
|
||||||
|
|
||||||
$('#get').click(function () {
|
$('#get').click(function () {
|
||||||
@ -19,5 +19,17 @@ define([
|
|||||||
Crypt.get(val, useDoc);
|
Crypt.get(val, useDoc);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$('#put').click(function () {
|
||||||
|
var hash = $target.val().trim();
|
||||||
|
Crypt.put(hash, $('#putter').val(), function (e) {
|
||||||
|
if (e) { console.error(e); }
|
||||||
|
$('#get').click();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#open').click(function () {
|
||||||
|
window.open('/code/#' + $target.val());
|
||||||
|
});
|
||||||
|
|
||||||
if (window.location.hash) { Crypt.get(void 0, useDoc); }
|
if (window.location.hash) { Crypt.get(void 0, useDoc); }
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user