* Added Much better session Management, key updating and deleting

* Force reload of JS if app numbers dont match
* Added cool tag display on side of note
* Cleaned up a bunch of code and tweaked little things to be better
This commit is contained in:
Max G committed 2020-06-15 09:02:20 +00:00
1 parent d2624628d8
commit 071aaf22cd
18 files changed
+333 -270

No files matched your search

+46 -25
View File
@@ -454,9 +454,12 @@ Note.update = (userId, noteId, noteText, noteTitle, color, pinned, archived, has
}
let encryptedNoteText = ''
//Create encrypted snippet
const snippet = JSON.stringify([noteTitle, noteText.substring(0, 500)])
noteSnippet = cs.encrypt(masterKey, snippetSalt, snippet)
//Create encrypted snippet if its a long note
let snippet = ''
if(noteText.length > 500){
snippet = JSON.stringify([noteTitle, noteText.substring(0, 500)])
noteSnippet = cs.encrypt(masterKey, snippetSalt, snippet)
}
//Encrypt note text
const textObject = JSON.stringify([noteTitle, noteText])
@@ -946,9 +949,11 @@ Note.search = (userId, searchQuery, searchTags, fastFilters, masterKey) => {
let searchParams = [userId]
let noteSearchQuery = `
SELECT note.id,
note.snippet as snippet,
note.snippet_salt as salt,
note_raw_text.updated as updated,
note.snippet as snippetText,
note.snippet_salt as snippetSalt,
note_raw_text.text as noteText,
note_raw_text.salt as noteSalt,
note_raw_text.updated as updated,
opened,
color,
count(distinct note_tag.id) as tag_count,
@@ -1092,26 +1097,39 @@ Note.search = (userId, searchQuery, searchTags, fastFilters, masterKey) => {
}
//Decrypt note text
if(note.snippet && note.salt){
const decipheredText = cs.decrypt(currentNoteKey, note.salt, note.snippet)
const textObject = JSON.parse(decipheredText)
if(textObject != null && textObject.length == 2){
note.title = textObject[0]
note.text = textObject[1]
}
//Only long notes have snippets, decipher it if present
let displayTitle = ''
let displayText = ''
let encryptedText = note.noteText
let relatedSalt = note.noteSalt
//Default to note text, use snippet if set
if(note.snippetSalt && note.snippetText && note.snippetSalt.length > 0 && note.snippetText.length > 0){
encryptedText = note.snippetText
relatedSalt = note.snippetSalt
}
//Deduce note title
const textData = ProcessText.deduceNoteTitle(note.title, note.text)
note.title = textData.title
note.subtext = textData.sub
try {
const decipheredText = cs.decrypt(currentNoteKey, relatedSalt, encryptedText)
const textObject = JSON.parse(decipheredText)
if(textObject != null && textObject.length == 2){
if(textObject[0] && textObject[0] != null && textObject[0].length > 0){
displayTitle = textObject[0]
}
if(textObject[1] && textObject[1] != null && textObject[1].length > 0){
displayText = textObject[1]
}
}
} catch(err) {
console.log('Error opening note id -> ', note.id)
console.log(err)
}
//Remove these variables
note.note_highlights = []
note.attachment_highlights = []
note.tag_highlights = []
note.title = displayTitle
note.subtext = ProcessText.stripDoubleBlankLines(displayText)
//Limit number of attachment thumbs to 4
if(note.thumbs){
@@ -1123,9 +1141,12 @@ Note.search = (userId, searchQuery, searchTags, fastFilters, masterKey) => {
}
//Clear out note.text before sending it to front end, its being used in title and subtext
delete note.snippet
delete note.salt
delete note.snippetText
delete note.snippetSalt
delete note.noteText
delete note.noteSalt
delete note.encrypted_share_password_key
delete note.text //Passed back as title and subtext
})