fix merge conflicts

pull/1/head
ansuz 2016-12-22 16:53:03 +01:00
commit acfc27f5c5
5 changed files with 92 additions and 134 deletions

View File

@ -1,59 +1,87 @@
define([
'/customize/messages.js?app=read',
'/customize/messages.js?app=cryptget',
'/bower_components/chainpad-crypto/crypto.js',
'/bower_components/chainpad-netflux/chainpad-netflux.js',
'/common/cryptpad-common.js',
], function (Messages, Crypto, Realtime, Cryptpad) {
var Crypt = {};
'/bower_components/textpatcher/TextPatcher.js',
'/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) {
if (Session.done) { return; }
Session.cb(err, doc);
Session.done = true;
var abort = Cryptpad.find(Session,
['realtime', 'realtime', 'abort']);
if (typeof(abort) === 'function') { abort(); }
var abort = Cryptpad.find(S, ['realtime', 'realtime', 'abort']);
if (typeof(abort) === 'function') {
S.realtime.realtime.sync();
abort();
}
};
var get = Crypt.get = function (hash, cb, opt) {
if (typeof(cb) !== 'function') {
throw new Error('Crypt.get expects a callback');
}
var Session = {
cb: cb,
};
opt = opt || {};
var secret = Session.secret = Cryptpad.getSecrets(hash);
var makeConfig = function (hash) {
var secret = Cryptpad.getSecrets(hash);
if (!secret.keys) { secret.keys = secret.key; } // support old hashses
var config = {
websocketURL: Cryptpad.getWebsocketURL(),
channel: secret.channel,
validateKey: secret.keys.validateKey || undefined,
crypto: Crypto.createEncryptor(secret.keys),
logLevel: 0,
};
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 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,
};
});

View File

@ -6,12 +6,10 @@ define([
'/bower_components/alertifyjs/dist/js/alertify.js',
'/bower_components/spin.js/spin.min.js',
'/common/clipboard.js',
'/customize/fsStore.js',
'/customize/user.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
any particular pad type. This includes functions for committing metadata
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 common = {
User: User,
var common = window.Cryptpad = {
Messages: Messages,
};
var store;
var fsStore;
var userProxy;
var userStore;
var find = common.find = function (map, path) {
return (map && path.reduce(function (p, n) {
@ -42,7 +37,6 @@ define([
};
var getStore = common.getStore = function (legacy) {
if (!legacy && userStore) { return userStore; }
if ((!USE_FS_STORE || legacy) && store) { return store; }
if (USE_FS_STORE && !legacy && fsStore) { return fsStore; }
throw new Error("Store is not ready!");
@ -60,42 +54,6 @@ define([
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 fileHashKey = common.fileHashKey = 'FS_hash';
@ -677,48 +635,6 @@ define([
}
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);
};

View File

@ -220,7 +220,6 @@ define([
$logoutBox.slideDown();
} else {
revealLogin();
//$logoutBox.hide();
}
$login.click(function () {

View File

@ -30,6 +30,9 @@ pre {
<body>
<input id="target" type="text" value="/1/edit/xvhI6k6n7qYEtNL8cAv5zw/a4KKGGDY0S8GDj6m9iumX5E4"></input>
<button id="get">get</button>
<!-- <p>/1/edit/xvhI6k6n7qYEtNL8cAv5zw/a4KKGGDY0S8GDj6m9iumX5E4</p> -->
<pre id="dest"></pre>
<hr />
<textarea id="putter" type="text"></textarea>
<button id="put">put</button>
<button id="open">open</button>

View File

@ -9,8 +9,8 @@ define([
var useDoc = function (err, doc) {
if (err) { return console.error(err); }
console.log(doc);
$dest.text(doc);
//console.log(doc);
$('#putter').val(doc);
};
$('#get').click(function () {
@ -19,5 +19,17 @@ define([
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); }
});