Skip to content

Commit 44298ba

Browse files
committed
Add migration for LZString compressed note id in history
Signed-off-by: Max Wu <jackymaxj@gmail.com>
1 parent baa0418 commit 44298ba

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

lib/history.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict'
22
// history
33
// external modules
4+
var LZString = require('lz-string')
45

56
// core
67
var config = require('./config')
@@ -27,7 +28,26 @@ function getHistory (userid, callback) {
2728
}
2829
var history = {}
2930
if (user.history) {
30-
history = parseHistoryToObject(JSON.parse(user.history))
31+
history = JSON.parse(user.history)
32+
// migrate LZString encoded note id to base64url encoded note id
33+
for (let i = 0, l = history.length; i < l; i++) {
34+
let item = history[i]
35+
// try to parse in base64url
36+
let id = models.Note.decodeNoteId(item.id)
37+
if (!id || !models.Note.checkNoteIdValid(id)) {
38+
// try to parse in LZString if it can't be parsed in base64url
39+
try {
40+
id = LZString.decompressFromBase64(item.id)
41+
} catch (err) {
42+
id = null
43+
}
44+
if (id && models.Note.checkNoteIdValid(id)) {
45+
// replace the note id to base64url encoded note id
46+
history[i].id = models.Note.encodeNoteId(id)
47+
}
48+
}
49+
}
50+
history = parseHistoryToObject(history)
3151
}
3252
if (config.debug) {
3353
logger.info('read history success: ' + user.id)

0 commit comments

Comments
 (0)