mirror of
https://github.com/streetwriters/notesnook.git
synced 2026-09-01 19:49:54 +02:00
core: fix error on locking notes
This commit is contained in:
committed by
Abdullah Atta
parent
bc428dd11f
commit
c452e1524d
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user