Merge pull request #907 from SISheogorath/fix/historyLZString
Some minor improvements for LZString handling
This commit is contained in:
commit
93a3ce1164
2 changed files with 19 additions and 2 deletions
|
@ -31,6 +31,15 @@ function getHistory (userid, callback) {
|
||||||
history = JSON.parse(user.history)
|
history = JSON.parse(user.history)
|
||||||
// migrate LZString encoded note id to base64url encoded note id
|
// migrate LZString encoded note id to base64url encoded note id
|
||||||
for (let i = 0, l = history.length; i < l; i++) {
|
for (let i = 0, l = history.length; i < l; i++) {
|
||||||
|
// Calculate minimal string length for an UUID that is encoded
|
||||||
|
// base64 encoded and optimize comparsion by using -1
|
||||||
|
// this should make a lot of LZ-String parsing errors obsolete
|
||||||
|
// as we can assume that a nodeId that is 48 chars or longer is a
|
||||||
|
// noteID.
|
||||||
|
const base64UuidLength = ((4 * 36) / 3) - 1
|
||||||
|
if (!(history[i].id.length > base64UuidLength)) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
let id = LZString.decompressFromBase64(history[i].id)
|
let id = LZString.decompressFromBase64(history[i].id)
|
||||||
if (id && models.Note.checkNoteIdValid(id)) {
|
if (id && models.Note.checkNoteIdValid(id)) {
|
||||||
|
@ -38,9 +47,13 @@ function getHistory (userid, callback) {
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// most error here comes from LZString, ignore
|
// most error here comes from LZString, ignore
|
||||||
|
if (err.message === 'Cannot read property \'charAt\' of undefined') {
|
||||||
|
logger.warning('Looks like we can not decode "' + history[i].id + '" with LZString. Can be ignored.')
|
||||||
|
} else {
|
||||||
logger.error(err)
|
logger.error(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
history = parseHistoryToObject(history)
|
history = parseHistoryToObject(history)
|
||||||
}
|
}
|
||||||
if (config.debug) {
|
if (config.debug) {
|
||||||
|
|
|
@ -227,7 +227,11 @@ module.exports = function (sequelize, DataTypes) {
|
||||||
var id = LZString.decompressFromBase64(noteId)
|
var id = LZString.decompressFromBase64(noteId)
|
||||||
if (id && Note.checkNoteIdValid(id)) { return callback(null, id) } else { return _callback(null, null) }
|
if (id && Note.checkNoteIdValid(id)) { return callback(null, id) } else { return _callback(null, null) }
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
if (err.message === 'Cannot read property \'charAt\' of undefined') {
|
||||||
|
logger.warning('Looks like we can not decode "' + noteId + '" with LZString. Can be ignored.')
|
||||||
|
} else {
|
||||||
logger.error(err)
|
logger.error(err)
|
||||||
|
}
|
||||||
return _callback(null, null)
|
return _callback(null, null)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue