Changeset View
Changeset View
Standalone View
Standalone View
web/database/worker/db-worker.js
Show All 18 Lines | |||||
} from '../../types/worker-types.js'; | } from '../../types/worker-types.js'; | ||||
import { getSQLiteDBVersion, setupSQLiteDB } from '../queries/db-queries.js'; | import { getSQLiteDBVersion, setupSQLiteDB } from '../queries/db-queries.js'; | ||||
import { | import { | ||||
getAllDrafts, | getAllDrafts, | ||||
moveDraft, | moveDraft, | ||||
removeAllDrafts, | removeAllDrafts, | ||||
updateDraft, | updateDraft, | ||||
} from '../queries/draft-queries.js'; | } from '../queries/draft-queries.js'; | ||||
import { SQLITE_CONTENT, SQLITE_ENCRYPTION_KEY } from '../utils/constants.js'; | import { getMetadata, setMetadata } from '../queries/metadata-queries.js'; | ||||
import { | |||||
CURRENT_USER_ID_KEY, | |||||
SQLITE_CONTENT, | |||||
SQLITE_ENCRYPTION_KEY, | |||||
} from '../utils/constants.js'; | |||||
import { generateDatabaseCryptoKey } from '../utils/worker-crypto-utils.js'; | import { generateDatabaseCryptoKey } from '../utils/worker-crypto-utils.js'; | ||||
const localforageConfig: PartialConfig = { | const localforageConfig: PartialConfig = { | ||||
driver: localforage.INDEXEDDB, | driver: localforage.INDEXEDDB, | ||||
name: 'comm', | name: 'comm', | ||||
storeName: 'commStorage', | storeName: 'commStorage', | ||||
description: 'Comm encrypted database storage', | description: 'Comm encrypted database storage', | ||||
version: '1.0', | version: '1.0', | ||||
▲ Show 20 Lines • Show All 83 Lines • ▼ Show 20 Lines | if (draftStoreOperations) { | ||||
processDraftStoreOperations(draftStoreOperations); | processDraftStoreOperations(draftStoreOperations); | ||||
} | } | ||||
return; | return; | ||||
} else if (message.type === workerRequestMessageTypes.GET_CLIENT_STORE) { | } else if (message.type === workerRequestMessageTypes.GET_CLIENT_STORE) { | ||||
return { | return { | ||||
type: workerResponseMessageTypes.CLIENT_STORE, | type: workerResponseMessageTypes.CLIENT_STORE, | ||||
store: getClientStore(), | store: getClientStore(), | ||||
}; | }; | ||||
} else if (message.type === workerRequestMessageTypes.SET_CURRENT_USER_ID) { | |||||
if (!sqliteDb) { | |||||
throw new Error('Database not initialized'); | |||||
} | |||||
setMetadata(sqliteDb, CURRENT_USER_ID_KEY, message.userID); | |||||
return; | |||||
} else if (message.type === workerRequestMessageTypes.GET_CURRENT_USER_ID) { | |||||
if (!sqliteDb) { | |||||
throw new Error('Database not initialized'); | |||||
} | |||||
const userID = getMetadata(sqliteDb, CURRENT_USER_ID_KEY); | |||||
return { | |||||
type: workerResponseMessageTypes.GET_CURRENT_USER_ID, | |||||
userID, | |||||
}; | |||||
} | } | ||||
throw new Error('Request type not supported'); | throw new Error('Request type not supported'); | ||||
} | } | ||||
function connectHandler(event: SharedWorkerMessageEvent) { | function connectHandler(event: SharedWorkerMessageEvent) { | ||||
if (!event.ports.length) { | if (!event.ports.length) { | ||||
return; | return; | ||||
Show All 30 Lines |