diff --git a/src/db/gpx.ts b/src/db/gpx.ts index e4c8cf3..c90d966 100644 --- a/src/db/gpx.ts +++ b/src/db/gpx.ts @@ -373,16 +373,17 @@ export const getGpx = async (params: any) => { gpx = row.doc.doc; } //level 1 (extensions) - if (row.doc.type === 'extensions') { + if (target !== undefined && row.doc.type === 'extensions') { target.splice(1); appendToArray(target.at(-1), row.doc.type, row.doc.doc); target.push(row.doc.doc); } //level 1 (others) if ( - row.doc.type === 'wpt' || - row.doc.type === 'rte' || - row.doc.type === 'trk' + target !== undefined && + (row.doc.type === 'wpt' || + row.doc.type === 'rte' || + row.doc.type === 'trk') ) { target.splice(1); appendToArray(target.at(-1), row.doc.type, row.doc._id); diff --git a/src/db/index.ts b/src/db/index.ts index 945c587..30d5b45 100644 --- a/src/db/index.ts +++ b/src/db/index.ts @@ -51,6 +51,39 @@ export const initDb = async (params: any) => { globalThis.dbReady = true; + const sync = PouchDB.sync( + 'dyomedea', + 'http://admin:password@localhost:5984/dyomedea', + { + live: true, + retry: true, + } + ) + .on('change', function (info) { + // handle change + console.log({ caller: 'Sync / change', info }); + }) + .on('paused', function (err) { + // replication paused (e.g. replication up to date, user went offline) + console.log({ caller: 'Sync / paused', err }); + }) + .on('active', function () { + // replicate resumed (e.g. new changes replicating, user went back online) + console.log({ caller: 'Sync / active' }); + }) + .on('denied', function (err) { + // a document failed to replicate (e.g. due to permissions) + 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' }); const changes = db