diff options
author | Christoph (Sheogorath) Kern | 2018-03-18 15:13:06 +0100 |
---|---|---|
committer | GitHub | 2018-03-18 15:13:06 +0100 |
commit | f6df2deb8439dda4576ee70691c98c1ab53c965d (patch) | |
tree | 6a56c539e86058cf89a50636b451167fc3a75f83 /lib/history.js | |
parent | 6b30f662725b54d9c0ef3954fdb5a463da697cc2 (diff) | |
parent | 8bfe51940f2eff035394b7713cbbce5b9b446842 (diff) |
Merge pull request #743 from hackmdio/fix-to-use-url-safe-base64
Fix to use url-safe base64 in note url
Diffstat (limited to '')
-rw-r--r-- | lib/history.js | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/lib/history.js b/lib/history.js index f46ff49f..c7d2472c 100644 --- a/lib/history.js +++ b/lib/history.js @@ -1,6 +1,7 @@ 'use strict' // history // external modules +var LZString = require('lz-string') // core var config = require('./config') @@ -27,7 +28,20 @@ function getHistory (userid, callback) { } var 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++) { + try { + let id = LZString.decompressFromBase64(history[i].id) + if (id && models.Note.checkNoteIdValid(id)) { + history[i].id = models.Note.encodeNoteId(id) + } + } catch (err) { + // most error here comes from LZString, ignore + logger.error(err) + } + } + history = parseHistoryToObject(history) } if (config.debug) { logger.info('read history success: ' + user.id) |