File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11'use strict'
22// history
33// external modules
4+ var LZString = require ( 'lz-string' )
45
56// core
67var 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 )
You can’t perform that action at this time.
0 commit comments