Skip to content

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

core: fix error on locking notes

Abdullah Atta7c97db74dc9f
diff --git a/packages/core/src/api/vault.ts b/packages/core/src/api/vault.ts
index ec68344a8..615179964 100644
--- a/packages/core/src/api/vault.ts
+++ b/packages/core/src/api/vault.ts
@@ -129,7 +129,12 @@ export default class Vault {
}
for (const content of contentItems) {
- await this.encryptContent(content, newPassword, content.id);
+ await this.encryptContent(
+ content,
+ content.noteId,
+ newPassword,
+ content.id
+ );
}
await this.db.storage().remove("vaultKey");
@@ -223,6 +228,7 @@ export default class Vault {
private async encryptContent(
content: NoteContent<false>,
+ noteId: string,
password: string,
contentId?: string,
sessionId?: string
@@ -233,6 +239,7 @@ export default class Vault {
await this.db.content.add({
id: contentId,
+ noteId,
sessionId,
data: encryptedContent,
type: content.type
@@ -312,7 +319,13 @@ export default class Vault {
}
if (data && type)
- await this.encryptContent({ data, type }, password, contentId, sessionId);
+ await this.encryptContent(
+ { data, type },
+ id,
+ password,
+ contentId,
+ sessionId
+ );
return await this.db.notes.add({
id,
diff --git a/packages/core/src/collections/content.ts b/packages/core/src/collections/content.ts
index 977001d5c..0e32dee7c 100644
--- a/packages/core/src/collections/content.ts
+++ b/packages/core/src/collections/content.ts
@@ -75,15 +75,11 @@ export class Content implements ICollection {
const id = content.id || getId();
- if (!content.noteId)
- throw new Error("No noteId found to link the content to.");
- if (!content.type) throw new Error("Please specify content's type.");
-
const encryptedData = isCipher(content.data) ? content.data : undefined;
let unencryptedData =
typeof content.data === "string" ? content.data : undefined;
- if (unencryptedData)
+ if (unencryptedData && content.type && content.noteId)
unencryptedData = await this.extractAttachments({
type: content.type,
data: unencryptedData,
@@ -105,13 +101,13 @@ export class Content implements ICollection {
...contentData
});
- if (content.sessionId && contentData)
+ if (content.sessionId && contentData && content.type && content.noteId)
await this.db.noteHistory.add(content.sessionId, {
noteId: content.noteId,
type: content.type,
...contentData
});
- } else {
+ } else if (content.noteId) {
const contentItem: ContentItem = {
type: "tiptap",
noteId: content.noteId,
@@ -134,7 +130,7 @@ export class Content implements ICollection {
if (content.sessionId)
await this.db.noteHistory.add(content.sessionId, contentItem);
- }
+ } else return;
return id;
}
diff --git a/packages/core/src/collections/notes.ts b/packages/core/src/collections/notes.ts
index bb7156aef..64c1552e7 100644
--- a/packages/core/src/collections/notes.ts
+++ b/packages/core/src/collections/notes.ts
@@ -95,7 +95,7 @@ export class Notes implements ICollection {
if (oldNote) note.dateEdited = Date.now();
}
- if (item.localOnly !== undefined) {
+ if (note.contentId && item.localOnly !== undefined) {
await this.db.content.add({
id: note.contentId,
localOnly: !!item.localOnly