Skip to content

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

feat: add content compression before encryption

thecodrrbd31ef8d9bf9
diff --git a/packages/core/api/sync/collector.js b/packages/core/api/sync/collector.js
index dfc86d9e3..a8cfebe83 100644
--- a/packages/core/api/sync/collector.js
+++ b/packages/core/api/sync/collector.js
@@ -28,6 +28,10 @@ class Collector {
};
}
+ shouldCompress(itemType) {
+ return itemType === "tiny";
+ }
+
async collect(lastSyncedTimestamp, force) {
this._lastSyncedTimestamp = lastSyncedTimestamp;
this.key = await this._db.user.getEncryptionKey();
@@ -44,7 +48,11 @@ class Collector {
_serialize(item) {
if (!item) return;
- return this._db.context.encrypt(this.key, JSON.stringify(item));
+ return this._db.context.encrypt(
+ this.key,
+ JSON.stringify(item),
+ shouldCompress(item.type)
+ );
}
_collect(array) {
diff --git a/packages/core/database/storage.js b/packages/core/database/storage.js
index 1c45ff120..a0baf727f 100644
--- a/packages/core/database/storage.js
+++ b/packages/core/database/storage.js
@@ -2,27 +2,35 @@ export default class Storage {
constructor(context) {
this.storage = context;
}
+
write(key, data) {
return this.storage.write(key, data);
}
+
readMulti(keys) {
return this.storage.readMulti(keys);
}
+
read(key, isArray = false) {
return this.storage.read(key, isArray);
}
+
clear() {
return this.storage.clear();
}
+
remove(key) {
return this.storage.remove(key);
}
+
getAllKeys() {
return this.storage.getAllKeys();
}
- encrypt(password, data) {
- return this.storage.encrypt(password, data);
+
+ encrypt(password, data, compress) {
+ return this.storage.encrypt(password, data, compress);
}
+
decrypt(password, cipher) {
return this.storage.decrypt(password, cipher);
}