Created
March 31, 2018 16:00
-
-
Save jackkleeman/8070687fd8527fcef66676e3c0af0083 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function init(m, email, password) { | |
// generate the database encryption key | |
vendor.nCrypto | |
.pbkdf2( | |
Buffer.from(m.mnemonic, "utf8"), | |
Buffer.from(databaseKeySeed, "utf8"), | |
2048, | |
64, | |
"sha512" | |
) | |
.then(function(buffer) { | |
dbKey = buffer.slice(0, 32); | |
// setup unencrypted local DB changefeed | |
PouchDB.plugin(vendor.cryptoPouch); | |
db = new PouchDB(localDBPrefix + m.dbName); | |
db.crypto({ | |
key: dbKey | |
}); | |
db | |
.changes({ | |
since: "now", | |
live: true, | |
include_docs: true | |
}) | |
.on("change", function(change) { | |
if (change.doc && change.doc.message) { | |
changefeed(change.doc); | |
} | |
}) | |
.on("error", console.log); | |
}); | |
// setup remote DB | |
var remoteDB = new PouchDB(remoteDBAddress); | |
// setup local DB | |
var localDB = new PouchDB(localDBPrefix + m.dbName); | |
localDB.replicate | |
.from(remoteDB) | |
.on("complete", function() { | |
localDB | |
.sync(remoteDB, { | |
live: true, | |
retry: true | |
}) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am not sure If I understood. Can you create 2 localDBPrefix + m.dbName PouchDBs?
What does changefeed does?