27 lines
848 B
TypeScript
27 lines
848 B
TypeScript
import { initDb } from '../db';
|
|
import { putNewGpx, existsGpx, pruneAndSaveImportedGpx } from '../db/gpx';
|
|
import { putNewTrk } from '../db/trk';
|
|
|
|
const self = globalThis as unknown as SharedWorkerGlobalScope;
|
|
|
|
const actions = { initDb, putNewGpx, putNewTrk, existsGpx, pruneAndSaveImportedGpx };
|
|
|
|
self.onconnect = function (e) {
|
|
var port = e.ports[0];
|
|
|
|
port.onmessage = async function (e) {
|
|
console.log(`Worker received ${JSON.stringify(e.data)}`);
|
|
const { id, payload } = e.data;
|
|
console.log(`payload.action in actions: ${payload.action in actions}`);
|
|
var returnValue: any = 'unknownAction';
|
|
if (payload.action in actions) {
|
|
returnValue = await actions[<keyof typeof actions>payload.action](
|
|
payload.params
|
|
);
|
|
}
|
|
port.postMessage({ id: id, payload: returnValue });
|
|
};
|
|
};
|
|
|
|
export default self;
|