Update to use buffer in encode/decode note id

Signed-off-by: Max Wu <jackymaxj@gmail.com>
This commit is contained in:
Max Wu 2018-02-27 20:57:31 +08:00
parent 44298baa93
commit fe429e9ac1
1 changed files with 4 additions and 2 deletions

View File

@ -117,11 +117,13 @@ module.exports = function (sequelize, DataTypes) {
}, },
encodeNoteId: function (id) { encodeNoteId: function (id) {
// remove dashes in UUID and encode in url-safe base64 // remove dashes in UUID and encode in url-safe base64
return base64url.encode(id.replace(/-/g, '')) let str = id.replace(/-/g, '')
let hexStr = Buffer.from(str, 'hex')
return base64url.encode(hexStr)
}, },
decodeNoteId: function (encodedId) { decodeNoteId: function (encodedId) {
// decode from url-safe base64 // decode from url-safe base64
let id = base64url.decode(encodedId) let id = base64url.toBuffer(encodedId).toString('hex')
// add dashes between the UUID string parts // add dashes between the UUID string parts
let idParts = [] let idParts = []
idParts.push(id.substr(0, 8)) idParts.push(id.substr(0, 8))