mirror of https://github.com/status-im/codimd.git
Add migration for LZString compressed note id in history
Signed-off-by: Max Wu <jackymaxj@gmail.com>
This commit is contained in:
parent
baa0418fb5
commit
44298baa93
|
@ -1,6 +1,7 @@
|
||||||
'use strict'
|
'use strict'
|
||||||
// history
|
// history
|
||||||
// external modules
|
// external modules
|
||||||
|
var LZString = require('lz-string')
|
||||||
|
|
||||||
// core
|
// core
|
||||||
var config = require('./config')
|
var config = require('./config')
|
||||||
|
@ -27,7 +28,26 @@ function getHistory (userid, callback) {
|
||||||
}
|
}
|
||||||
var history = {}
|
var history = {}
|
||||||
if (user.history) {
|
if (user.history) {
|
||||||
history = parseHistoryToObject(JSON.parse(user.history))
|
history = JSON.parse(user.history)
|
||||||
|
// migrate LZString encoded note id to base64url encoded note id
|
||||||
|
for (let i = 0, l = history.length; i < l; i++) {
|
||||||
|
let item = history[i]
|
||||||
|
// try to parse in base64url
|
||||||
|
let id = models.Note.decodeNoteId(item.id)
|
||||||
|
if (!id || !models.Note.checkNoteIdValid(id)) {
|
||||||
|
// try to parse in LZString if it can't be parsed in base64url
|
||||||
|
try {
|
||||||
|
id = LZString.decompressFromBase64(item.id)
|
||||||
|
} catch (err) {
|
||||||
|
id = null
|
||||||
|
}
|
||||||
|
if (id && models.Note.checkNoteIdValid(id)) {
|
||||||
|
// replace the note id to base64url encoded note id
|
||||||
|
history[i].id = models.Note.encodeNoteId(id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
history = parseHistoryToObject(history)
|
||||||
}
|
}
|
||||||
if (config.debug) {
|
if (config.debug) {
|
||||||
logger.info('read history success: ' + user.id)
|
logger.info('read history success: ' + user.id)
|
||||||
|
|
Loading…
Reference in New Issue