From 1de6270f799155fb1dd6761a14324d503a12ae73 Mon Sep 17 00:00:00 2001 From: Michael Mainguy Date: Wed, 17 Jul 2024 15:29:57 -0500 Subject: [PATCH] updated encryption to only encrypt when password is set. --- index.html | 2 +- package.json | 2 +- src/integration/pouchdbPersistenceManager.ts | 28 +++++++++++++++++++- src/react/webApp.tsx | 19 +++++++++++-- src/util/customPhysics.ts | 3 ++- 5 files changed, 48 insertions(+), 6 deletions(-) diff --git a/index.html b/index.html index 5b2b55a..411afa6 100644 --- a/index.html +++ b/index.html @@ -3,7 +3,7 @@ - diff --git a/package.json b/package.json index 4fead70..bb85475 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "immersive", "private": true, - "version": "0.0.8-13", + "version": "0.0.8-15", "type": "module", "engines": { "node": ">=18.0.0" diff --git a/src/integration/pouchdbPersistenceManager.ts b/src/integration/pouchdbPersistenceManager.ts index 15d0775..4930dfc 100644 --- a/src/integration/pouchdbPersistenceManager.ts +++ b/src/integration/pouchdbPersistenceManager.ts @@ -17,6 +17,13 @@ import {Presence} from "./presence"; type PasswordEvent = { detail: string; +} +type PasswordEvent2 = { + + password: string; + id: string; + encrypted: boolean; + } export class PouchdbPersistenceManager { private _logger: Logger = log.getLogger('PouchdbPersistenceManager'); @@ -41,6 +48,24 @@ export class PouchdbPersistenceManager { } this._logger.debug(evt); }); + document.addEventListener('dbcreated', (evt) => { + const detail = ((evt as unknown) as PasswordEvent2); + const password = detail.password; + const id = detail.id; + if (detail.encrypted) { + this._encKey = password; + } else { + this._encKey = null; + } + //this._encKey = password; + this.db = new PouchDB(detail.id, {auto_compaction: true}); + this.setupMetadata(id).then(() => { + document.location.href = '/db/' + id; + }).catch((err) => { + console.log(err); + }) + + }); } public setDiagramManager(diagramManager: DiagramManager) { @@ -200,6 +225,7 @@ export class PouchdbPersistenceManager { if (doc && doc.friendly) { this._logger.info("Storing Document friendly name in local storage"); localStorage.setItem(current, doc.friendly); + this._encKey = null; } if (doc && doc.camera) { @@ -240,7 +266,7 @@ export class PouchdbPersistenceManager { current = 'localdb'; } this.db = new PouchDB(current, {auto_compaction: true}); - //await this.db.compact(); +//await this.db.compact(); if (sync) { if (await this.setupMetadata(current)) { await this.beginSync(current); diff --git a/src/react/webApp.tsx b/src/react/webApp.tsx index 374893c..71f1882 100644 --- a/src/react/webApp.tsx +++ b/src/react/webApp.tsx @@ -59,13 +59,19 @@ function CreateMenu({display, toggleCreateMenu}) { const onCreateClick = (evt) => { evt.preventDefault(); const name = (document.querySelector('#createName') as HTMLInputElement).value; - const password = (document.querySelector('#createPassword') as HTMLInputElement).value; + let password = (document.querySelector('#createPassword') as HTMLInputElement).value; const password2 = (document.querySelector('#createPassword2') as HTMLInputElement).value; if (password !== password2) { window.alert('Passwords do not match'); return; } + const id = window.crypto.randomUUID().replace(/-/g, '_'); + if (password.length == 0) { + password = id; + } + const encrypted = (password != id); + localStorage.setItem(id, name); if (name && name.length > 4) { axios.post(import.meta.env.VITE_CREATE_ENDPOINT, @@ -78,7 +84,16 @@ function CreateMenu({display, toggleCreateMenu}) { } ).then(response => { console.log(response); - document.location.href = '/db/' + id; + const evt = new CustomEvent('dbcreated', { + detail: { + id: id, + name: name, + password: password, + encrypted: encrypted + } + }); + document.dispatchEvent(evt); + }).catch(error => { console.error(error); }); diff --git a/src/util/customPhysics.ts b/src/util/customPhysics.ts index d9e49ae..f8b54ec 100644 --- a/src/util/customPhysics.ts +++ b/src/util/customPhysics.ts @@ -18,7 +18,8 @@ export class CustomPhysics { const havok = await HavokPhysics(); const havokPlugin = new HavokPlugin(true, havok); const scene = this.scene; - scene.enablePhysics(new Vector3(0, -9.8, 0), havokPlugin); + const physicsEnable = scene.enablePhysics(new Vector3(0, -9.8, 0), havokPlugin); + scene.collisionsEnabled = true; scene.onAfterPhysicsObservable.add(() => { scene.meshes.forEach((mesh) => {