Fix more async store issues

pull/1/head
yflory 7 years ago
parent d1277d7026
commit 664625a6ef

@ -67,7 +67,7 @@ define([
key: [Constants.tokenKey],
value: token
}, function (obj) {
if (obj.error) { return void cb(obj.error); }
if (obj && obj.error) { return void cb(obj.error); }
cb();
});
};
@ -402,29 +402,36 @@ define([
common.clearOwnedChannel = function (channel, cb) {
postMessage("CLEAR_OWNED_CHANNEL", {channel: channel}, function (obj) {
if (obj.error) { return void cb(obj.error); }
cb();
if (obj && obj.error) { return void cb(obj.error); }
cb(null, obj);
});
};
common.uploadChunk = function (data, cb) {
postMessage("UPLOAD_CHUNK", {chunk: data}, function (obj) {
if (obj && obj.error) { return void cb(obj.error); }
cb(null, obj);
});
};
common.uploadComplete = function (cb) {
postMessage("UPLOAD_COMPLETE", null, function (obj) {
if (obj.error) { return void cb(obj.error); }
cb();
if (obj && obj.error) { return void cb(obj.error); }
cb(null, obj);
});
};
common.uploadStatus = function (size, cb) {
postMessage("UPLOAD_STATUS", {size: size}, function (obj) {
if (obj.error) { return void cb(obj.error); }
cb();
if (obj && obj.error) { return void cb(obj.error); }
cb(null, obj);
});
};
common.uploadCancel = function (cb) {
postMessage("UPLOAD_CANCEL", null, function (obj) {
if (obj.error) { return void cb(obj.error); }
cb();
if (obj && obj.error) { return void cb(obj.error); }
cb(null, obj);
});
};
@ -434,7 +441,7 @@ define([
netfluxId: netfluxId,
href: window.location.href
}, function (obj) {
if (obj.error) { return void cb(obj.error); }
if (obj && obj.error) { return void cb(obj.error); }
cb();
});
};

@ -29,7 +29,7 @@ define([
Store.get = function (key, cb) {
cb({result: Util.find(store.proxy, key)});
cb(Util.find(store.proxy, key));
};
Store.set = function (data, cb) {
var path = data.key.slice();
@ -164,22 +164,34 @@ define([
Store.clearOwnedChannel = function (data, cb) {
if (!store.rpc) { return void cb({error: 'RPC_NOT_READY'}); }
store.rpc.clearOwnedChannel(data.channel, cb);
store.rpc.clearOwnedChannel(data.channel, function (err, res) {
if (err) { return void cb({error:err}); }
cb(res);
});
};
Store.uploadComplete = function (data, cb) {
if (!store.rpc) { return void cb({error: 'RPC_NOT_READY'}); }
store.rpc.uploadComplete(cb);
store.rpc.uploadComplete(function (err, res) {
if (err) { return void cb({error:err}); }
cb(res);
});
};
Store.uploadStatus = function (data, cb) {
if (!store.rpc) { return void cb({error: 'RPC_NOT_READY'}); }
store.rpc.uploadStatus(data.size, cb);
store.rpc.uploadStatus(data.size, function (err, res) {
if (err) { return void cb({error:err}); }
cb(res);
});
};
Store.uploadCancel = function (data, cb) {
if (!store.rpc) { return void cb({error: 'RPC_NOT_READY'}); }
store.rpc.uploadCancel(cb);
store.rpc.uploadCancel(function (err, res) {
if (err) { return void cb({error:err}); }
cb(res);
});
};
var arePinsSynced = function (cb) {
@ -203,6 +215,15 @@ define([
});
};
Store.uploadChunk = function (data, cb) {
store.rpc.send.unauthenticated('UPLOAD', data.chunk, function (e, msg) {
cb({
error: e,
msg: msg
});
});
};
Store.initRpc = function (data, cb) {
require(['/common/pinpad.js'], function (Pinpad) {
Pinpad.create(store.network, store.proxy, function (e, call) {
@ -692,7 +713,7 @@ define([
postMessage("UPDATE_METADATA");
});
proxy.on('change', [Constants.tokenKey], function () {
postMessage("UPDATE_TOKEN", { data: proxy[Constants.tokenKey] });
postMessage("UPDATE_TOKEN", { token: proxy[Constants.tokenKey] });
});
};
userObject.migrate(todo);

@ -31,6 +31,9 @@ define([
case 'CLEAR_OWNED_CHANNEL': {
Store.clearOwnedChannel(data, cb); break;
}
case 'UPLOAD_CHUNK': {
Store.uploadChunk(data, cb); break;
}
case 'UPLOAD_COMPLETE': {
Store.uploadComplete(data, cb); break;
}

@ -20,7 +20,7 @@ define([
var sendChunk = function (box, cb) {
var enc = Nacl.util.encodeBase64(box);
common.rpc.send.unauthenticated('UPLOAD', enc, function (e, msg) {
common.uploadChunk(enc, function (e, msg) {
cb(e, msg);
});
};

@ -114,8 +114,13 @@ define([
});
if (cfg.getSecrets) {
var w = waitFor();
cfg.getSecrets(Cryptpad, Utils, waitFor(function (err, s) {
secret = s;
Cryptpad.getShareHashes(secret, function (err, h) {
hashes = h;
w();
});
}));
} else {
secret = Utils.Hash.getSecrets();
@ -123,8 +128,8 @@ define([
// New pad: create a new random channel id
secret.channel = Utils.Hash.createChannelId();
}
Cryptpad.getShareHashes(secret, waitFor(function (err, h) { hashes = h; }));
}
Cryptpad.getShareHashes(secret, waitFor(function (err, h) { hashes = h; }));
}).nThen(function () {
var readOnly = secret.keys && !secret.keys.editKeyStr;
@ -247,7 +252,7 @@ define([
cb('ERROR');
return;
}
Cryptpad.changeDisplayName(newName, true);
Cryptpad.changeMetadata();
cb();
});
});

@ -1,10 +1,8 @@
define([
'jquery',
'/bower_components/chainpad-crypto/crypto.js',
'/bower_components/textpatcher/TextPatcher.js',
'/common/toolbar3.js',
'json.sortify',
'/bower_components/chainpad-json-validator/json-ot.js',
'/common/common-util.js',
'/bower_components/nthen/index.js',
'/common/sframe-common.js',
@ -22,10 +20,8 @@ define([
], function (
$,
Crypto,
TextPatcher,
Toolbar,
JSONSortify,
JsonOT,
Util,
nThen,
SFCommon,
@ -61,7 +57,6 @@ define([
var config = APP.config = {
readOnly: readOnly,
transformFunction: JsonOT.validate,
// cryptpad debug logging (default is 1)
// logLevel: 0,
validateContent: function (content) {
@ -123,11 +118,7 @@ define([
config.onReady = function (info) {
if (APP.realtime !== info.realtime) {
var realtime = APP.realtime = info.realtime;
APP.patchText = TextPatcher.create({
realtime: realtime,
//logging: true
});
APP.realtime = info.realtime;
}
var userDoc = APP.realtime.getUserDoc();

@ -49,7 +49,7 @@ define([
editHash = hash;
}));
}).nThen(function () {
if (!editHash) {
if (editHash) {
return void cb(null, Hash.getSecrets('profile', editHash));
}
// 3rd case: profile creation (create a new random hash, store it later if needed)

Loading…
Cancel
Save