Skip to content

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

fix(vault): data is not defined (change to content)

thecodrrc0abed0aedab
diff --git a/packages/core/__tests__/vault.test.js b/packages/core/__tests__/vault.test.js
index 9a88f18e3..c4185143b 100644
--- a/packages/core/__tests__/vault.test.js
+++ b/packages/core/__tests__/vault.test.js
@@ -100,8 +100,8 @@ test("save an edited locked note", () =>
const note = db.notes.note(id).data;
await db.vault.save({
- note,
- data: { type: "delta", data: [{ insert: "hello world\n" }] },
+ ...note,
+ content: { type: "delta", data: [{ insert: "hello world\n" }] },
});
const content = await db.content.raw(note.contentId);
diff --git a/packages/core/api/vault.js b/packages/core/api/vault.js
index 036f264a5..599b55a43 100644
--- a/packages/core/api/vault.js
+++ b/packages/core/api/vault.js
@@ -141,13 +141,13 @@ export default class Vault {
}
/** @private */
- async _encryptContent(contentId, content) {
+ async _encryptContent(contentId, content, type) {
let encryptedContent = await this._context.encrypt(
{ password: this._password },
JSON.stringify(content)
);
- await this._db.content.add({ id: contentId, data: encryptedContent });
+ await this._db.content.add({ id: contentId, data: encryptedContent, type });
}
/** @private */
@@ -164,16 +164,18 @@ export default class Vault {
/** @private */
async _lockNote(note) {
- let { id, data: content, contentId } = note;
+ let { id, content: { type, data } = {}, contentId } = note;
- if (!content) {
+ if (!data || !type || !contentId) {
note = this._db.notes.note(id);
if (note.data.locked) return;
- content = await note.content();
contentId = note.data.contentId;
+ let content = await this._db.content.raw(contentId);
+ data = content.data;
+ type = content.type;
}
- await this._encryptContent(contentId, content);
+ await this._encryptContent(contentId, data, type);
return await this._db.notes.add({
id,