mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-19 01:35:18 -04:00
history.ts: Fix 🚑 getHistory
Signed-off-by: David Mehren <dmehren1@gmail.com>
This commit is contained in:
parent
2408aef54c
commit
e0192b5652
1 changed files with 6 additions and 5 deletions
|
@ -14,6 +14,7 @@ type HistoryObject = {
|
||||||
text: string;
|
text: string;
|
||||||
time: number;
|
time: number;
|
||||||
tags: string[];
|
tags: string[];
|
||||||
|
pinned?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseHistoryMapToArray (historyMap: Map<string, HistoryObject>): HistoryObject[] {
|
function parseHistoryMapToArray (historyMap: Map<string, HistoryObject>): HistoryObject[] {
|
||||||
|
@ -42,9 +43,8 @@ function getHistory (userId, callback: (err: any, history: any) => void): void {
|
||||||
if (!user) {
|
if (!user) {
|
||||||
return callback(null, null)
|
return callback(null, null)
|
||||||
}
|
}
|
||||||
let history
|
|
||||||
if (user.history) {
|
if (user.history) {
|
||||||
history = JSON.parse(user.history)
|
const history = JSON.parse(user.history)
|
||||||
// migrate LZString encoded note id to base64url encoded note id
|
// migrate LZString encoded note id to base64url encoded note id
|
||||||
for (let i = 0, l = history.length; i < l; i++) {
|
for (let i = 0, l = history.length; i < l; i++) {
|
||||||
// Calculate minimal string length for an UUID that is encoded
|
// Calculate minimal string length for an UUID that is encoded
|
||||||
|
@ -70,10 +70,11 @@ function getHistory (userId, callback: (err: any, history: any) => void): void {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
history = parseHistoryArrayToMap(history)
|
|
||||||
}
|
|
||||||
logger.debug(`read history success: ${user.id}`)
|
logger.debug(`read history success: ${user.id}`)
|
||||||
return callback(null, history)
|
return callback(null, parseHistoryArrayToMap(history))
|
||||||
|
}
|
||||||
|
logger.debug(`read empty history: ${user.id}`)
|
||||||
|
return callback(null, [])
|
||||||
}).catch(function (err) {
|
}).catch(function (err) {
|
||||||
logger.error('read history failed: ' + err)
|
logger.error('read history failed: ' + err)
|
||||||
return callback(err, null)
|
return callback(err, null)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue