First working version with the account dialog.
This commit is contained in:
parent
8a4396fb20
commit
ad9b70173f
|
@ -1,6 +1,7 @@
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import PouchDB from 'pouchdb';
|
import PouchDB from 'pouchdb';
|
||||||
import uri from '../lib/ids';
|
import uri from '../lib/ids';
|
||||||
|
import { toHex } from '../lib/to-hex';
|
||||||
import {
|
import {
|
||||||
getAccountById,
|
getAccountById,
|
||||||
getAccounts,
|
getAccounts,
|
||||||
|
@ -81,38 +82,47 @@ export const initDb = async (params: any) => {
|
||||||
}
|
}
|
||||||
//await await db.compact();
|
//await await db.compact();
|
||||||
|
|
||||||
// const sync = PouchDB.sync(
|
if (currentAccount.remoteDbServer) {
|
||||||
// 'dyomedea',
|
const url = `${currentAccount.remoteDbServer}/userdb-${toHex(
|
||||||
// 'http://admin:password@localhost:5984/dyomedea',
|
currentAccount.remoteDbUser
|
||||||
// {
|
)}`;
|
||||||
// live: true,
|
|
||||||
// retry: true,
|
const remoteDb = new PouchDB(url, {
|
||||||
// }
|
auth: {
|
||||||
// )
|
username: currentAccount.remoteDbUser,
|
||||||
// .on('change', function (info) {
|
password: currentAccount.remoteDbPassword,
|
||||||
// // handle change
|
},
|
||||||
// console.log({ caller: 'Sync / change', info });
|
skip_setup: true,
|
||||||
// })
|
});
|
||||||
// .on('paused', function (err) {
|
const sync = PouchDB.sync(db, remoteDb, {
|
||||||
// // replication paused (e.g. replication up to date, user went offline)
|
live: true,
|
||||||
// console.log({ caller: 'Sync / paused', err });
|
retry: true,
|
||||||
// })
|
})
|
||||||
// .on('active', function () {
|
.on('change', function (info) {
|
||||||
// // replicate resumed (e.g. new changes replicating, user went back online)
|
// handle change
|
||||||
// console.log({ caller: 'Sync / active' });
|
console.log({ caller: 'Sync / change', info });
|
||||||
// })
|
})
|
||||||
// .on('denied', function (err) {
|
.on('paused', function (err) {
|
||||||
// // a document failed to replicate (e.g. due to permissions)
|
// replication paused (e.g. replication up to date, user went offline)
|
||||||
// console.error({ caller: 'Sync / denied', err });
|
console.log({ caller: 'Sync / paused', err });
|
||||||
// })
|
})
|
||||||
// .on('complete', function (info) {
|
.on('active', function () {
|
||||||
// // handle complete
|
// replicate resumed (e.g. new changes replicating, user went back online)
|
||||||
// console.log({ caller: 'Sync / complete', info });
|
console.log({ caller: 'Sync / active' });
|
||||||
// })
|
})
|
||||||
// .on('error', function (err) {
|
.on('denied', function (err) {
|
||||||
// // handle error
|
// a document failed to replicate (e.g. due to permissions)
|
||||||
// console.error({ caller: 'Sync / error', err });
|
console.error({ caller: 'Sync / denied', err });
|
||||||
// });
|
})
|
||||||
|
.on('complete', function (info) {
|
||||||
|
// handle complete
|
||||||
|
console.log({ caller: 'Sync / complete', info });
|
||||||
|
})
|
||||||
|
.on('error', function (err) {
|
||||||
|
// handle error
|
||||||
|
console.error({ caller: 'Sync / error', err });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// console.log({ caller: 'initDb / before db.changes' });
|
// console.log({ caller: 'initDb / before db.changes' });
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
// see https://9to5answer.com/javascript-unicode-string-to-hex
|
||||||
|
|
||||||
|
export const toHex = (str: string) => {
|
||||||
|
let hex;
|
||||||
|
try {
|
||||||
|
hex = unescape(encodeURIComponent(str))
|
||||||
|
.split('')
|
||||||
|
.map(function (v) {
|
||||||
|
return v.charCodeAt(0).toString(16);
|
||||||
|
})
|
||||||
|
.join('');
|
||||||
|
} catch (e) {
|
||||||
|
hex = str;
|
||||||
|
console.log('invalid text input: ' + str);
|
||||||
|
}
|
||||||
|
return hex;
|
||||||
|
};
|
Loading…
Reference in New Issue