diff --git a/src/lib/config/interfaces.ts b/src/lib/config/interfaces.ts index 5a9308676..8fa6023f9 100644 --- a/src/lib/config/interfaces.ts +++ b/src/lib/config/interfaces.ts @@ -36,7 +36,7 @@ export interface Config { forbiddenNoteIDs: string[]; defaultPermission: string; dbURL: string; - db: any; + db; sslKeyPath: string; sslCertPath: string; sslCAPath: string[]; @@ -153,5 +153,6 @@ export interface Config { linkifyHeaderStyle: string; // TODO: Remove escape hatch for dynamically added properties + // eslint-disable-next-line @typescript-eslint/no-explicit-any [propName: string]: any; } diff --git a/src/lib/history.ts b/src/lib/history.ts index 898b96a0f..694900a78 100644 --- a/src/lib/history.ts +++ b/src/lib/history.ts @@ -6,6 +6,7 @@ import LZString from 'lz-string' import { logger } from './logger' import { Note, User } from './models' import { errors } from './errors' +import { LogEntry } from 'winston' // public @@ -34,7 +35,7 @@ function parseHistoryArrayToMap (historyArray: HistoryObject[]): Map void): void { +function getHistory (userId, callback: (err: unknown, history: Map | null) => void): void { User.findOne({ where: { id: userId @@ -44,7 +45,7 @@ function getHistory (userId, callback: (err: any, history: any) => void): void { return callback(null, null) } if (user.history) { - const history = JSON.parse(user.history) + const history: HistoryObject[] = JSON.parse(user.history) // migrate LZString encoded note id to base64url encoded note id for (let i = 0, l = history.length; i < l; i++) { // Calculate minimal string length for an UUID that is encoded @@ -74,14 +75,14 @@ function getHistory (userId, callback: (err: any, history: any) => void): void { return callback(null, parseHistoryArrayToMap(history)) } logger.debug(`read empty history: ${user.id}`) - return callback(null, []) + return callback(null, new Map()) }).catch(function (err) { logger.error('read history failed: ' + err) return callback(err, null) }) } -function setHistory (userId: string, history: any[], callback: (err: any | null, count: [number, User[]] | null) => void): void { +function setHistory (userId: string, history: HistoryObject[], callback: (err: LogEntry | null, count: [number, User[]] | null) => void): void { User.update({ history: JSON.stringify(history) }, { @@ -109,7 +110,7 @@ function updateHistory (userId: string, noteId: string, document, time): void { noteHistory.text = noteInfo.title noteHistory.time = time || Date.now() noteHistory.tags = noteInfo.tags - setHistory(userId, history, function (err, _) { + setHistory(userId, parseHistoryMapToArray(history), function (err, _) { if (err) { logger.log(err) } @@ -118,7 +119,7 @@ function updateHistory (userId: string, noteId: string, document, time): void { } } -function historyGet (req, res): any { +function historyGet (req, res): void { if (req.isAuthenticated()) { getHistory(req.user.id, function (err, history) { if (err) return errors.errorInternalError(res) @@ -132,7 +133,7 @@ function historyGet (req, res): any { } } -function historyPost (req, res): any { +function historyPost (req, res): void { if (req.isAuthenticated()) { const noteId = req.params.noteId if (!noteId) { @@ -160,7 +161,7 @@ function historyPost (req, res): any { if (!history[noteId]) return errors.errorNotFound(res) if (req.body.pinned === 'true' || req.body.pinned === 'false') { history[noteId].pinned = (req.body.pinned === 'true') - setHistory(req.user.id, history, function (err, _) { + setHistory(req.user.id, parseHistoryMapToArray(history), function (err, _) { if (err) return errors.errorInternalError(res) res.end() }) @@ -174,7 +175,7 @@ function historyPost (req, res): any { } } -function historyDelete (req, res): any { +function historyDelete (req, res): void { if (req.isAuthenticated()) { const noteId = req.params.noteId if (!noteId) { @@ -187,7 +188,7 @@ function historyDelete (req, res): any { if (err) return errors.errorInternalError(res) if (!history) return errors.errorNotFound(res) delete history[noteId] - setHistory(req.user.id, history, function (err, _) { + setHistory(req.user.id, parseHistoryMapToArray(history), function (err, _) { if (err) return errors.errorInternalError(res) res.end() }) diff --git a/src/lib/library-ext.d.ts b/src/lib/library-ext.d.ts index fd2ec2d7a..e06789e84 100644 --- a/src/lib/library-ext.d.ts +++ b/src/lib/library-ext.d.ts @@ -3,6 +3,6 @@ import { User } from './models' declare module 'express' { export interface Request { user?: User; - flash (type: string, msg?: string): any; + flash (type: string, msg?: string): [] | object | number; } }