internal: incomplete vault systems behind feature flag (#2340)
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
import { ContentType } from '@standardnotes/common'
|
||||
import { Copy, extendArray, UuidGenerator } from '@standardnotes/utils'
|
||||
import { Copy, extendArray, UuidGenerator, Uuids } from '@standardnotes/utils'
|
||||
import { SNLog } from '../../Log'
|
||||
import { isErrorDecryptingParameters, SNRootKey } from '@standardnotes/encryption'
|
||||
import * as Encryption from '@standardnotes/encryption'
|
||||
import * as Services from '@standardnotes/services'
|
||||
import { DiagnosticInfo } from '@standardnotes/services'
|
||||
import {
|
||||
CreateDecryptedLocalStorageContextPayload,
|
||||
CreateDeletedLocalStorageContextPayload,
|
||||
@@ -252,7 +251,7 @@ export class DiskStorageService extends Services.AbstractService implements Serv
|
||||
return rawContent as Services.StorageValuesObject
|
||||
}
|
||||
|
||||
public setValue(key: string, value: unknown, mode = Services.StorageValueModes.Default): void {
|
||||
public setValue<T>(key: string, value: T, mode = Services.StorageValueModes.Default): void {
|
||||
this.setValueWithNoPersist(key, value, mode)
|
||||
|
||||
void this.persistValuesToDisk()
|
||||
@@ -292,6 +291,14 @@ export class DiskStorageService extends Services.AbstractService implements Serv
|
||||
return value != undefined ? (value as T) : (defaultValue as T)
|
||||
}
|
||||
|
||||
public getAllKeys(mode = Services.StorageValueModes.Default): string[] {
|
||||
if (!this.values) {
|
||||
throw Error('Attempting to get all keys before loading local storage.')
|
||||
}
|
||||
|
||||
return Object.keys(this.values[this.domainKeyForMode(mode)])
|
||||
}
|
||||
|
||||
public async removeValue(key: string, mode = Services.StorageValueModes.Default): Promise<void> {
|
||||
if (!this.values) {
|
||||
throw Error(`Attempting to remove storage key ${key} before loading local storage.`)
|
||||
@@ -370,20 +377,28 @@ export class DiskStorageService extends Services.AbstractService implements Serv
|
||||
const encryptable: DecryptedPayloadInterface[] = []
|
||||
const unencryptable: DecryptedPayloadInterface[] = []
|
||||
|
||||
const split = Encryption.SplitPayloadsByEncryptionType(decrypted)
|
||||
if (split.itemsKeyEncryption) {
|
||||
extendArray(encryptable, split.itemsKeyEncryption)
|
||||
const { rootKeyEncryption, keySystemRootKeyEncryption, itemsKeyEncryption } =
|
||||
Encryption.SplitPayloadsByEncryptionType(decrypted)
|
||||
|
||||
if (itemsKeyEncryption) {
|
||||
extendArray(encryptable, itemsKeyEncryption)
|
||||
}
|
||||
|
||||
if (split.rootKeyEncryption) {
|
||||
if (keySystemRootKeyEncryption) {
|
||||
extendArray(encryptable, keySystemRootKeyEncryption)
|
||||
}
|
||||
|
||||
if (rootKeyEncryption) {
|
||||
if (!rootKeyEncryptionAvailable) {
|
||||
extendArray(unencryptable, split.rootKeyEncryption)
|
||||
extendArray(unencryptable, rootKeyEncryption)
|
||||
} else {
|
||||
extendArray(encryptable, split.rootKeyEncryption)
|
||||
extendArray(encryptable, rootKeyEncryption)
|
||||
}
|
||||
}
|
||||
|
||||
await this.deletePayloads(discardable)
|
||||
if (discardable.length > 0) {
|
||||
await this.deletePayloads(discardable)
|
||||
}
|
||||
|
||||
const encryptableSplit = Encryption.SplitPayloadsByEncryptionType(encryptable)
|
||||
|
||||
@@ -406,16 +421,18 @@ export class DiskStorageService extends Services.AbstractService implements Serv
|
||||
}
|
||||
|
||||
public async deletePayloads(payloads: DeletedPayloadInterface[]) {
|
||||
await Promise.all(payloads.map((payload) => this.deletePayloadWithId(payload.uuid)))
|
||||
await this.deletePayloadsWithUuids(Uuids(payloads))
|
||||
}
|
||||
|
||||
public async forceDeletePayloads(payloads: FullyFormedPayloadInterface[]) {
|
||||
await Promise.all(payloads.map((payload) => this.deletePayloadWithId(payload.uuid)))
|
||||
public async deletePayloadsWithUuids(uuids: string[]): Promise<void> {
|
||||
await this.executeCriticalFunction(async () => {
|
||||
await Promise.all(uuids.map((uuid) => this.deviceInterface.removeDatabaseEntry(uuid, this.identifier)))
|
||||
})
|
||||
}
|
||||
|
||||
public async deletePayloadWithId(uuid: string) {
|
||||
public async deletePayloadWithUuid(uuid: string) {
|
||||
return this.executeCriticalFunction(async () => {
|
||||
return this.deviceInterface.removeDatabaseEntry(uuid, this.identifier)
|
||||
await this.deviceInterface.removeDatabaseEntry(uuid, this.identifier)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -437,17 +454,4 @@ export class DiskStorageService extends Services.AbstractService implements Serv
|
||||
await this.deviceInterface.removeRawStorageValue(this.getPersistenceKey())
|
||||
})
|
||||
}
|
||||
|
||||
override async getDiagnostics(): Promise<DiagnosticInfo | undefined> {
|
||||
return {
|
||||
storage: {
|
||||
storagePersistable: this.storagePersistable,
|
||||
persistencePolicy: Services.StoragePersistencePolicies[this.persistencePolicy],
|
||||
needsPersist: this.needsPersist,
|
||||
currentPersistPromise: this.currentPersistPromise != undefined,
|
||||
isStorageWrapped: this.isStorageWrapped(),
|
||||
allRawPayloadsCount: (await this.getAllRawPayloads()).length,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user