Linter: Fix all lint errors

Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
Philip Molares 2021-02-15 09:42:51 +01:00
parent b0a45bdf9c
commit 136d895d15
51 changed files with 2245 additions and 1539 deletions

View file

@ -1,15 +1,15 @@
'use strict'
// history
// external modules
var LZString = require('lz-string')
const LZString = require('lz-string')
// core
var logger = require('./logger')
var models = require('./models')
const logger = require('./logger')
const models = require('./models')
const errors = require('./errors')
// public
var History = {
const History = {
historyGet: historyGet,
historyPost: historyPost,
historyDelete: historyDelete,
@ -25,7 +25,7 @@ function getHistory (userid, callback) {
if (!user) {
return callback(null, null)
}
var history = {}
let history = {}
if (user.history) {
history = JSON.parse(user.history)
// migrate LZString encoded note id to base64url encoded note id
@ -40,7 +40,7 @@ function getHistory (userid, callback) {
continue
}
try {
let id = LZString.decompressFromBase64(history[i].id)
const id = LZString.decompressFromBase64(history[i].id)
if (id && models.Note.checkNoteIdValid(id)) {
history[i].id = models.Note.encodeNoteId(id)
}
@ -85,8 +85,8 @@ function updateHistory (userid, noteId, document, time) {
if (!history[noteId]) {
history[noteId] = {}
}
var noteHistory = history[noteId]
var noteInfo = models.Note.parseNoteInfo(document)
const noteHistory = history[noteId]
const noteInfo = models.Note.parseNoteInfo(document)
noteHistory.id = noteId
noteHistory.text = noteInfo.title
noteHistory.time = time || Date.now()
@ -101,18 +101,18 @@ function updateHistory (userid, noteId, document, time) {
}
function parseHistoryToArray (history) {
var _history = []
const _history = []
Object.keys(history).forEach(function (key) {
var item = history[key]
const item = history[key]
_history.push(item)
})
return _history
}
function parseHistoryToObject (history) {
var _history = {}
for (var i = 0, l = history.length; i < l; i++) {
var item = history[i]
const _history = {}
for (let i = 0, l = history.length; i < l; i++) {
const item = history[i]
_history[item.id] = item
}
return _history
@ -134,25 +134,25 @@ function historyGet (req, res) {
function historyPost (req, res) {
if (req.isAuthenticated()) {
var noteId = req.params.noteId
const noteId = req.params.noteId
if (!noteId) {
if (typeof req.body['history'] === 'undefined') return errors.errorBadRequest(res)
if (typeof req.body.history === 'undefined') return errors.errorBadRequest(res)
logger.debug(`SERVER received history from [${req.user.id}]: ${req.body.history}`)
try {
var history = JSON.parse(req.body.history)
const history = JSON.parse(req.body.history)
if (Array.isArray(history)) {
setHistory(req.user.id, history, function (err, count) {
if (err) return errors.errorInternalError(res)
res.end()
})
} else {
return errors.errorBadRequest(res)
}
} catch (err) {
return errors.errorBadRequest(res)
}
if (Array.isArray(history)) {
setHistory(req.user.id, history, function (err, count) {
if (err) return errors.errorInternalError(res)
res.end()
})
} else {
return errors.errorBadRequest(res)
}
} else {
if (typeof req.body['pinned'] === 'undefined') return errors.errorBadRequest(res)
if (typeof req.body.pinned === 'undefined') return errors.errorBadRequest(res)
getHistory(req.user.id, function (err, history) {
if (err) return errors.errorInternalError(res)
if (!history) return errors.errorNotFound(res)
@ -175,7 +175,7 @@ function historyPost (req, res) {
function historyDelete (req, res) {
if (req.isAuthenticated()) {
var noteId = req.params.noteId
const noteId = req.params.noteId
if (!noteId) {
setHistory(req.user.id, [], function (err, count) {
if (err) return errors.errorInternalError(res)