mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 06:59:31 +01:00
core: add checks when accessing a note using this._db.notes.note
This commit is contained in:
committed by
Abdullah Atta
parent
ffacb8818c
commit
a62ca2aada
@@ -176,8 +176,9 @@ export default class Vault {
|
||||
* @param {string} password The password to unlock note with
|
||||
*/
|
||||
async remove(noteId, password) {
|
||||
const note = this._db.notes.note(noteId).data;
|
||||
await this._unlockNote(note, password, true);
|
||||
const note = this._db.notes.note(noteId);
|
||||
if (!note) return;
|
||||
await this._unlockNote(note.data, password, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -186,8 +187,10 @@ export default class Vault {
|
||||
* @param {string} password The password to open note with
|
||||
*/
|
||||
async open(noteId, password) {
|
||||
const note = this._db.notes.note(noteId).data;
|
||||
const unlockedNote = await this._unlockNote(note, password, false);
|
||||
const note = this._db.notes.note(noteId);
|
||||
if (!note) return;
|
||||
|
||||
const unlockedNote = await this._unlockNote(note.data, password, false);
|
||||
this._password = password;
|
||||
return unlockedNote;
|
||||
}
|
||||
@@ -271,7 +274,10 @@ export default class Vault {
|
||||
async _lockNote(note, password) {
|
||||
let { id, content: { type, data } = {}, sessionId, title } = note;
|
||||
|
||||
note = this._db.notes.note(id).data;
|
||||
note = this._db.notes.note(id);
|
||||
if (!note) return;
|
||||
|
||||
note = note.data;
|
||||
const contentId = note.contentId;
|
||||
if (!contentId) throw new Error("Cannot lock note because it is empty.");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user