diff --git a/src/lib/web/note/actions.ts b/src/lib/web/note/actions.ts index 7d90fe196..a1f3bfa11 100644 --- a/src/lib/web/note/actions.ts +++ b/src/lib/web/note/actions.ts @@ -1,4 +1,4 @@ -import { Response } from 'express' +import { Request, Response } from 'express' import { Note, Revision } from '../../models' import { logger } from '../../logger' @@ -8,7 +8,7 @@ import shortId from 'shortid' import moment from 'moment' import querystring from 'querystring' -export function getInfo (req: any, res: Response, note: Note): void { +export function getInfo (req: Request, res: Response, note: Note): void { const body = note.content const extracted = Note.extractMeta(body) const markdown = extracted.markdown @@ -31,7 +31,7 @@ export function getInfo (req: any, res: Response, note: Note): void { res.send(data) } -export function createGist (req: any, res: Response, note: Note): void { +export function createGist (req: Request, res: Response, note: Note): void { const data = { // eslint-disable-next-line @typescript-eslint/camelcase client_id: config.github.clientID, @@ -44,7 +44,7 @@ export function createGist (req: any, res: Response, note: Note): void { res.redirect('https://github.com/login/oauth/authorize?' + query) } -export function getRevision (req: any, res: Response, note: Note): void { +export function getRevision (req: Request, res: Response, note: Note): void { const actionId = req.params.actionId if (actionId) { const time = moment(parseInt(actionId)) diff --git a/src/lib/web/note/controller.ts b/src/lib/web/note/controller.ts index 79711af85..55de8943a 100644 --- a/src/lib/web/note/controller.ts +++ b/src/lib/web/note/controller.ts @@ -1,4 +1,4 @@ -import { NextFunction, Request, Response } from 'express' +import { Request, Response } from 'express' import { config } from '../../config' import { errors } from '../../errors' import { logger } from '../../logger' @@ -6,7 +6,7 @@ import { Note, User } from '../../models' import * as ActionController from './actions' import * as NoteUtils from './util' -export function publishNoteActions (req: any, res: Response, next: NextFunction) { +export function publishNoteActions (req: Request, res: Response): void { NoteUtils.findNoteOrCreate(req, res, function (note) { const action = req.params.action switch (action) { @@ -23,7 +23,7 @@ export function publishNoteActions (req: any, res: Response, next: NextFunction) }) } -export function showPublishNote (req: any, res: Response, next: NextFunction) { +export function showPublishNote (req: Request, res: Response): void { const include = [{ model: User, as: 'owner' @@ -51,10 +51,10 @@ export function showPublishNote (req: any, res: Response, next: NextFunction) { logger.error(err) return errors.errorInternalError(res) }) - }, include) + }) } -export function showNote (req: any, res: Response, next: NextFunction) { +export function showNote (req: Request, res: Response): void { NoteUtils.findNoteOrCreate(req, res, function (note) { // force to use note id const noteId = req.params.noteId @@ -79,7 +79,7 @@ export function showNote (req: any, res: Response, next: NextFunction) { }) } -export function createFromPOST (req: any, res: Response, next: NextFunction) { +export function createFromPOST (req: Request, res: Response): void { let body = '' if (req.body && req.body.length > config.documentMaxLength) { return errors.errorTooLong(res) @@ -90,7 +90,7 @@ export function createFromPOST (req: any, res: Response, next: NextFunction) { return NoteUtils.newNote(req, res, body) } -export function doAction (req: any, res: Response, next: NextFunction) { +export function doAction (req: Request, res: Response): void { const noteId = req.params.noteId NoteUtils.findNoteOrCreate(req, res, (note) => { const action = req.params.action @@ -121,7 +121,7 @@ export function doAction (req: any, res: Response, next: NextFunction) { }) } -export function downloadMarkdown (req: Request, res: Response, note: any) { +export function downloadMarkdown (req: Request, res: Response, note): void { const body = note.content let filename = Note.decodeTitle(note.title) filename = encodeURIComponent(filename) diff --git a/src/lib/web/note/slide.ts b/src/lib/web/note/slide.ts index 5008295f1..850c00f08 100644 --- a/src/lib/web/note/slide.ts +++ b/src/lib/web/note/slide.ts @@ -5,7 +5,7 @@ import { logger } from '../../logger' import { Note, User } from '../../models' import * as NoteUtils from './util' -export function publishSlideActions (req: any, res: Response, next: NextFunction) { +export function publishSlideActions (req: any, res: Response) { NoteUtils.findNoteOrCreate(req, res, function (note) { const action = req.params.action if (action === 'edit') { @@ -16,7 +16,7 @@ export function publishSlideActions (req: any, res: Response, next: NextFunction }) } -export function showPublishSlide (req: any, res: Response, next: NextFunction) { +export function showPublishSlide (req: any, res: Response) { const include = [{ model: User, as: 'owner' @@ -44,5 +44,5 @@ export function showPublishSlide (req: any, res: Response, next: NextFunction) { logger.error(err) return errors.errorInternalError(res) }) - }, include) + }) } diff --git a/src/lib/web/note/util.ts b/src/lib/web/note/util.ts index e26d3235e..7c367fd74 100644 --- a/src/lib/web/note/util.ts +++ b/src/lib/web/note/util.ts @@ -1,4 +1,4 @@ -import { Response } from 'express' +import { Request, Response } from 'express' import fs from 'fs' import path from 'path' @@ -8,7 +8,7 @@ import { errors } from '../../errors' import { logger } from '../../logger' import { Note, User } from '../../models' -export function newNote (req: any, res: Response, body: string | null) { +export function newNote (req, res: Response, body: string | null): void { let owner = null const noteId = req.params.noteId ? req.params.noteId : null if (req.isAuthenticated()) { @@ -33,7 +33,7 @@ export function newNote (req: any, res: Response, body: string | null) { }) } -export function checkViewPermission (req: any, note: any) { +export function checkViewPermission (req, note: any): boolean { if (note.permission === 'private') { return req.isAuthenticated() && note.ownerId === req.user.id } else if (note.permission === 'limited' || note.permission === 'protected') { @@ -43,7 +43,7 @@ export function checkViewPermission (req: any, note: any) { } } -export function findNoteOrCreate (req, res, callback: (note: any) => void, include?: Includeable[]) { +export function findNoteOrCreate (req: Request, res: Response, callback: (note: Note) => void): void { const id = req.params.noteId || req.params.shortid Note.parseNoteId(id, function (err, _id) { if (err) { @@ -70,14 +70,14 @@ export function findNoteOrCreate (req, res, callback: (note: any) => void, inclu }) } -function isRevealTheme (theme: string) { +function isRevealTheme (theme: string): string | undefined { if (fs.existsSync(path.join(__dirname, '..', '..', '..', '..', 'public', 'build', 'reveal.js', 'css', 'theme', theme + '.css'))) { return theme } return undefined } -export function getPublishData (req: any, res: Response, note: any, callback: (data: any) => void) { +export function getPublishData (req: Request, res: Response, note, callback: (data) => void): void { const body = note.content const extracted = Note.extractMeta(body) const markdown = extracted.markdown