Storing the current track in pouchdb.
This commit is contained in:
1 parent
82997cd53f
commit
20ae635d3f
3 files changed
+77
-8
No files matched your search
+56
-1
@@ -4,6 +4,7 @@ import {
|
||||
string_to_bytes,
|
||||
bytes_to_base64,
|
||||
} from '@openpgp/asmcrypto.js';
|
||||
import { DBWrapper } from 'workbox-core/_private';
|
||||
|
||||
export const pushTrack = (db: any, payload: any) => {
|
||||
const sha = new Sha256();
|
||||
@@ -19,7 +20,61 @@ export const pushTrack = (db: any, payload: any) => {
|
||||
console.log(`Digest: ${_id}`);
|
||||
}
|
||||
const doc = { _id, type: 'Track', ...payload };
|
||||
// console.log(JSON.stringify(doc));
|
||||
// console.log(JSON.stringify(doc));
|
||||
db.put(doc);
|
||||
};
|
||||
|
||||
const CURRENT_TRACK = '---current track---';
|
||||
|
||||
const initialTrack = {
|
||||
_id: CURRENT_TRACK,
|
||||
type: 'Track',
|
||||
track: {
|
||||
$: {
|
||||
version: '1.1',
|
||||
creator: 'dyomedea version 0.000001',
|
||||
xmlns: 'http://www.topografix.com/GPX/1/1',
|
||||
'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance',
|
||||
'xsi:schemaLocation':
|
||||
'http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd http://www.garmin.com/xmlschemas/GpxExtensions/v3 http://www8.garmin.com/xmlschemas/GpxExtensionsv3.xsd http://www.garmin.com/xmlschemas/WaypointExtension/v1 http://www8.garmin.com/xmlschemas/WaypointExtensionv1.xsd http://www.garmin.com/xmlschemas/TrackPointExtension/v1 http://www.garmin.com/xmlschemas/TrackPointExtensionv1.xsd',
|
||||
'xmlns:gpxx': 'http://www.garmin.com/xmlschemas/GpxExtensions/v3',
|
||||
'xmlns:wptx1': 'http://www.garmin.com/xmlschemas/WaypointExtension/v1',
|
||||
'xmlns:gpxtpx': 'http://www.garmin.com/xmlschemas/TrackPointExtension/v1',
|
||||
},
|
||||
metadata: {
|
||||
name: 'Tbd',
|
||||
desc: 'Tbd',
|
||||
time: '2022-08-27T21:35:01.000Z',
|
||||
},
|
||||
trk: [
|
||||
{
|
||||
name: 'Tbd',
|
||||
trkseg: [
|
||||
{
|
||||
trkpt: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
metadata: {
|
||||
lastModified: '2022-08-27T21:35:02.000Z',
|
||||
},
|
||||
};
|
||||
|
||||
export const appendTrkpt = async (db: any, trkpt: any) => {
|
||||
var track: any;
|
||||
await db.get(CURRENT_TRACK)
|
||||
.then((result: any) => {
|
||||
track = result;
|
||||
})
|
||||
.catch(() => {
|
||||
track = initialTrack;
|
||||
});
|
||||
track.metadata.lastModified = trkpt.time;
|
||||
const currentTrkseg = track.track.trk.at(-1).trkseg.at(-1);
|
||||
currentTrkseg.trkpt.push(trkpt);
|
||||
db.put(track).then((response: any) => {
|
||||
console.log(`db.put(track), response: ${JSON.stringify(response)}`);
|
||||
});
|
||||
};
|
||||
Reference in new issue
Block a user