mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 15:09:33 +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
|
* @param {string} password The password to unlock note with
|
||||||
*/
|
*/
|
||||||
async remove(noteId, password) {
|
async remove(noteId, password) {
|
||||||
const note = this._db.notes.note(noteId).data;
|
const note = this._db.notes.note(noteId);
|
||||||
await this._unlockNote(note, password, true);
|
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
|
* @param {string} password The password to open note with
|
||||||
*/
|
*/
|
||||||
async open(noteId, password) {
|
async open(noteId, password) {
|
||||||
const note = this._db.notes.note(noteId).data;
|
const note = this._db.notes.note(noteId);
|
||||||
const unlockedNote = await this._unlockNote(note, password, false);
|
if (!note) return;
|
||||||
|
|
||||||
|
const unlockedNote = await this._unlockNote(note.data, password, false);
|
||||||
this._password = password;
|
this._password = password;
|
||||||
return unlockedNote;
|
return unlockedNote;
|
||||||
}
|
}
|
||||||
@@ -271,7 +274,10 @@ export default class Vault {
|
|||||||
async _lockNote(note, password) {
|
async _lockNote(note, password) {
|
||||||
let { id, content: { type, data } = {}, sessionId, title } = note;
|
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;
|
const contentId = note.contentId;
|
||||||
if (!contentId) throw new Error("Cannot lock note because it is empty.");
|
if (!contentId) throw new Error("Cannot lock note because it is empty.");
|
||||||
|
|
||||||
|
|||||||
@@ -183,7 +183,7 @@ export default class Attachments extends Collection {
|
|||||||
|
|
||||||
async detach(attachment) {
|
async detach(attachment) {
|
||||||
await this._db.notes.init();
|
await this._db.notes.init();
|
||||||
for (let noteId of attachment.noteIds) {
|
for (const noteId of attachment.noteIds) {
|
||||||
const note = this._db.notes.note(noteId);
|
const note = this._db.notes.note(noteId);
|
||||||
if (!note) continue;
|
if (!note) continue;
|
||||||
const contentId = note.data.contentId;
|
const contentId = note.data.contentId;
|
||||||
@@ -195,9 +195,9 @@ export default class Attachments extends Collection {
|
|||||||
|
|
||||||
async _canDetach(attachment) {
|
async _canDetach(attachment) {
|
||||||
await this._db.notes.init();
|
await this._db.notes.init();
|
||||||
for (let noteId of attachment.noteIds) {
|
for (const noteId of attachment.noteIds) {
|
||||||
const note = this._db.notes.note(noteId).data;
|
const note = this._db.notes.note(noteId);
|
||||||
if (note.locked) return false;
|
if (note && note.data.locked) return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -85,7 +85,6 @@ export default class NoteHistory extends Collection {
|
|||||||
if (!noteId || !dateEdited || !content) return;
|
if (!noteId || !dateEdited || !content) return;
|
||||||
let sessionId = `${noteId}_${dateEdited}`;
|
let sessionId = `${noteId}_${dateEdited}`;
|
||||||
let oldSession = await this._collection.getItem(sessionId);
|
let oldSession = await this._collection.getItem(sessionId);
|
||||||
let locked = this._db.notes.note(noteId)?.data?.locked;
|
|
||||||
|
|
||||||
let session = {
|
let session = {
|
||||||
type: "session",
|
type: "session",
|
||||||
@@ -96,7 +95,8 @@ export default class NoteHistory extends Collection {
|
|||||||
localOnly: true
|
localOnly: true
|
||||||
};
|
};
|
||||||
|
|
||||||
if (locked) {
|
const note = this._db.notes.note(noteId);
|
||||||
|
if (note && note.data.locked) {
|
||||||
session.locked = true;
|
session.locked = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -178,12 +178,14 @@ export default class NoteHistory extends Collection {
|
|||||||
/**
|
/**
|
||||||
* @type {Session}
|
* @type {Session}
|
||||||
*/
|
*/
|
||||||
let session = await this._collection.getItem(sessionId);
|
const session = await this._collection.getItem(sessionId);
|
||||||
let content = await this.sessionContent.get(session.sessionContentId);
|
const content = await this.sessionContent.get(session.sessionContentId);
|
||||||
let note = this._db.notes.note(session.noteId).data;
|
const note = this._db.notes.note(session.noteId);
|
||||||
|
if (!note) return;
|
||||||
|
|
||||||
if (session.locked) {
|
if (session.locked) {
|
||||||
await this._db.content.add({
|
await this._db.content.add({
|
||||||
id: note.contentId,
|
id: note.data.contentId,
|
||||||
data: content.data,
|
data: content.data,
|
||||||
type: content.type
|
type: content.type
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -133,9 +133,12 @@ export default class Relations extends Collection {
|
|||||||
case "reminder":
|
case "reminder":
|
||||||
item = this._db.reminders.reminder(reference.id);
|
item = this._db.reminders.reminder(reference.id);
|
||||||
break;
|
break;
|
||||||
case "note":
|
case "note": {
|
||||||
item = this._db.notes.note(reference.id)?.data;
|
const note = this._db.notes.note(reference.id);
|
||||||
|
if (!note) continue;
|
||||||
|
item = note.data;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (item) items.push(item);
|
if (item) items.push(item);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user