* 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:
@@ -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
|
||||
})
|
||||
|
||||
|
||||
|
@@ -143,6 +143,7 @@ User.getCounts = (userId) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
let countTotals = {}
|
||||
const userHash = cs.hash(String(userId)).toString('base64')
|
||||
|
||||
db.promise().query(
|
||||
`SELECT
|
||||
@@ -169,8 +170,6 @@ User.getCounts = (userId) => {
|
||||
.then( (rows, fields) => {
|
||||
|
||||
Object.assign(countTotals, rows[0][0]) //combine results
|
||||
|
||||
const userHash = cs.hash(String(userId)).toString('base64')
|
||||
|
||||
return db.promise().query(
|
||||
`SELECT count(id) as activeSessions FROM user_active_session WHERE user_hash = ?`, [userHash]
|
||||
@@ -199,6 +198,8 @@ User.getCounts = (userId) => {
|
||||
countTotals[key] = count ? count : 0
|
||||
})
|
||||
|
||||
countTotals['currentVersion'] = '3.0.0'
|
||||
|
||||
resolve(countTotals)
|
||||
})
|
||||
|
||||
@@ -206,8 +207,9 @@ User.getCounts = (userId) => {
|
||||
}
|
||||
|
||||
//Log out user by deleting login token for that active session
|
||||
User.logout = (tokenId) => {
|
||||
return db.promise().query('DELETE FROM user_active_session WHERE (id = ?)', [tokenId])
|
||||
User.logout = (sessionId) => {
|
||||
console.log('Terminate Session -> ', sessionId)
|
||||
return db.promise().query('DELETE FROM user_active_session WHERE (session_id = ?)', [sessionId])
|
||||
}
|
||||
|
||||
User.generateMasterKey = (userId, password) => {
|
||||
|
Reference in New Issue
Block a user