Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

web: add support for bulk writes

Abdullah Attabc465971be95
diff --git a/apps/web/src/interfaces/key-value.ts b/apps/web/src/interfaces/key-value.ts
index a0a7f401f..b8fe13987 100644
--- a/apps/web/src/interfaces/key-value.ts
+++ b/apps/web/src/interfaces/key-value.ts
@@ -33,7 +33,7 @@ export interface IKVStore {
* @param key
* @param value
*/
- set(key: string, value: any): Promise<void>;
+ set<T>(key: string, value: T): Promise<void>;
/**
* Set multiple values at once. This is faster than calling set() multiple times.
@@ -41,7 +41,7 @@ export interface IKVStore {
*
* @param entries Array of entries, where each entry is an array of `[key, value]`.
*/
- setMany(entries: [string, any][]): Promise<void>;
+ setMany<T>(entries: [string, T][]): Promise<void>;
/**
* Get multiple values by their keys
diff --git a/apps/web/src/interfaces/storage.ts b/apps/web/src/interfaces/storage.ts
index 2974f7b73..bd216dca2 100644
--- a/apps/web/src/interfaces/storage.ts
+++ b/apps/web/src/interfaces/storage.ts
@@ -58,6 +58,10 @@ export class NNStorage {
return this.database.getMany(keys.sort());
}
+ writeMulti<T>(entries: [string, T][]) {
+ return this.database.setMany(entries);
+ }
+
write<T>(key: string, data: T) {
return this.database.set(key, data);
}
@@ -144,8 +148,17 @@ export class NNStorage {
): Promise<string | undefined> {
const crypto = await getNNCrypto();
cipherData.format = "base64";
- const result = await crypto.decrypt(key, cipherData);
- if (typeof result.data === "string") return result.data;
+ return await crypto.decrypt(key, cipherData, "text");
+ }
+
+ async decryptMulti(
+ key: SerializedKey,
+ items: Cipher[]
+ ): Promise<string[] | undefined> {
+ const crypto = await getNNCrypto();
+
+ items.forEach((c) => (c.format = "base64"));
+ return await crypto.decryptMulti(key, items, "text");
}
}