mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-18 09:04:44 -04:00
ESLint fixes for Notes
Signed-off-by: David Mehren <dmehren1@gmail.com>
This commit is contained in:
parent
acdd627027
commit
5cda02590b
5 changed files with 269 additions and 277 deletions
|
@ -6,7 +6,7 @@ import fs from 'fs'
|
|||
|
||||
import { logger } from './logger'
|
||||
|
||||
import { NoteUtils } from './web/note/util'
|
||||
import * as NoteUtils from './web/note/util'
|
||||
|
||||
import { errors } from './errors'
|
||||
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
import { NextFunction, Request, Response } from 'express'
|
||||
import { NoteUtils } from './util'
|
||||
import * as ActionController from './actions'
|
||||
import { errors } from '../../errors'
|
||||
import { config } from '../../config'
|
||||
import { errors } from '../../errors'
|
||||
import { logger } from '../../logger'
|
||||
import { User, Note } from '../../models'
|
||||
import { Note, User } from '../../models'
|
||||
import * as ActionController from './actions'
|
||||
import * as NoteUtils from './util'
|
||||
|
||||
export module NoteController {
|
||||
export function publishNoteActions (req: any, res: Response, next: NextFunction) {
|
||||
export function publishNoteActions (req: any, res: Response, next: NextFunction) {
|
||||
NoteUtils.findNoteOrCreate(req, res, function (note) {
|
||||
const action = req.params.action
|
||||
switch (action) {
|
||||
|
@ -22,9 +21,9 @@ export module NoteController {
|
|||
break
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export function showPublishNote (req: any, res: Response, next: NextFunction) {
|
||||
export function showPublishNote (req: any, res: Response, next: NextFunction) {
|
||||
const include = [{
|
||||
model: User,
|
||||
as: 'owner'
|
||||
|
@ -53,9 +52,9 @@ export module NoteController {
|
|||
return errors.errorInternalError(res)
|
||||
})
|
||||
}, include)
|
||||
}
|
||||
}
|
||||
|
||||
export function showNote (req: any, res: Response, next: NextFunction) {
|
||||
export function showNote (req: any, res: Response, next: NextFunction) {
|
||||
NoteUtils.findNoteOrCreate(req, res, function (note) {
|
||||
// force to use note id
|
||||
const noteId = req.params.noteId
|
||||
|
@ -78,9 +77,9 @@ export module NoteController {
|
|||
opengraph: opengraph
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export function createFromPOST (req: any, res: Response, next: NextFunction) {
|
||||
export function createFromPOST (req: any, res: Response, next: NextFunction) {
|
||||
let body = ''
|
||||
if (req.body && req.body.length > config.documentMaxLength) {
|
||||
return errors.errorTooLong(res)
|
||||
|
@ -89,9 +88,9 @@ export module NoteController {
|
|||
}
|
||||
body = body.replace(/[\r]/g, '')
|
||||
return NoteUtils.newNote(req, res, body)
|
||||
}
|
||||
}
|
||||
|
||||
export function doAction (req: any, res: Response, next: NextFunction) {
|
||||
export function doAction (req: any, res: Response, next: NextFunction) {
|
||||
const noteId = req.params.noteId
|
||||
NoteUtils.findNoteOrCreate(req, res, (note) => {
|
||||
const action = req.params.action
|
||||
|
@ -120,9 +119,9 @@ export module NoteController {
|
|||
return res.redirect(config.serverURL + '/' + noteId)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export function downloadMarkdown (req: Request, res: Response, note: any) {
|
||||
export function downloadMarkdown (req: Request, res: Response, note: any) {
|
||||
const body = note.content
|
||||
let filename = Note.decodeTitle(note.title)
|
||||
filename = encodeURIComponent(filename)
|
||||
|
@ -136,5 +135,4 @@ export module NoteController {
|
|||
'X-Robots-Tag': 'noindex, nofollow' // prevent crawling
|
||||
})
|
||||
res.send(body)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import { markdownParser } from '../utils'
|
||||
|
||||
import { SlideController } from './slide'
|
||||
import { NoteController } from './controller'
|
||||
import { Router } from 'express'
|
||||
import { markdownParser } from '../utils'
|
||||
import * as NoteController from './controller'
|
||||
|
||||
import * as SlideController from './slide'
|
||||
|
||||
const NoteRouter = Router()
|
||||
// get new note
|
||||
|
|
|
@ -1,25 +1,22 @@
|
|||
import { NextFunction, Response } from "express";
|
||||
import { NoteUtils } from "./util";
|
||||
import { NextFunction, Response } from 'express'
|
||||
import { config } from '../../config'
|
||||
import { errors } from '../../errors'
|
||||
import { logger } from '../../logger'
|
||||
import { config } from '../../config'
|
||||
import { User } from "../../models/user";
|
||||
import { Note } from "../../models/note";
|
||||
import { Note, User } from '../../models'
|
||||
import * as NoteUtils from './util'
|
||||
|
||||
|
||||
export module SlideController {
|
||||
export function publishSlideActions(req: any, res: Response, next: NextFunction) {
|
||||
export function publishSlideActions (req: any, res: Response, next: NextFunction) {
|
||||
NoteUtils.findNoteOrCreate(req, res, function (note) {
|
||||
const action = req.params.action
|
||||
if (action === 'edit') {
|
||||
res.redirect(config.serverURL + '/' + (note.alias ? note.alias : Note.encodeNoteId(note.id)) + '?both')
|
||||
} else { res.redirect(config.serverURL + '/p/' + note.shortid) }
|
||||
})
|
||||
} else {
|
||||
res.redirect(config.serverURL + '/p/' + note.shortid)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
|
||||
export function showPublishSlide(req: any, res: Response, next: NextFunction) {
|
||||
export function showPublishSlide (req: any, res: Response, next: NextFunction) {
|
||||
const include = [{
|
||||
model: User,
|
||||
as: 'owner'
|
||||
|
@ -48,5 +45,4 @@ export module SlideController {
|
|||
return errors.errorInternalError(res)
|
||||
})
|
||||
}, include)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,14 @@
|
|||
import { Includeable } from 'sequelize'
|
||||
import { Response } from 'express'
|
||||
import fs from 'fs'
|
||||
|
||||
import path from 'path'
|
||||
import fs from 'fs'
|
||||
import { errors } from '../../errors'
|
||||
import { Includeable } from 'sequelize'
|
||||
import { config } from '../../config'
|
||||
import { errors } from '../../errors'
|
||||
import { logger } from '../../logger'
|
||||
import { Note , User } from '../../models'
|
||||
import { Note, User } from '../../models'
|
||||
|
||||
export module NoteUtils {
|
||||
export function findNoteOrCreate(req, res, callback: (note: any) => void, include?: Includeable[]) {
|
||||
export function findNoteOrCreate (req, res, callback: (note: any) => void, include?: Includeable[]) {
|
||||
const id = req.params.noteId || req.params.shortid
|
||||
Note.parseNoteId(id, function (err, _id) {
|
||||
if (err) {
|
||||
|
@ -34,9 +33,9 @@ export module NoteUtils {
|
|||
return errors.errorInternalError(res)
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export function checkViewPermission (req: any, note: any) {
|
||||
export function checkViewPermission (req: any, note: any) {
|
||||
if (note.permission === 'private') {
|
||||
return req.isAuthenticated() && note.ownerId === req.user.id
|
||||
} else if (note.permission === 'limited' || note.permission === 'protected') {
|
||||
|
@ -44,9 +43,9 @@ export module NoteUtils {
|
|||
} else {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function newNote (req: any, res: Response, body: string | null) {
|
||||
export function newNote (req: any, res: Response, body: string | null) {
|
||||
let owner = null
|
||||
const noteId = req.params.noteId ? req.params.noteId : null
|
||||
if (req.isAuthenticated()) {
|
||||
|
@ -69,9 +68,9 @@ export module NoteUtils {
|
|||
logger.error(err)
|
||||
return errors.errorInternalError(res)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export function getPublishData (req: any, res: Response, note: any, callback: (data: any) => void) {
|
||||
export function getPublishData (req: any, res: Response, note: any, callback: (data: any) => void) {
|
||||
const body = note.content
|
||||
const extracted = Note.extractMeta(body)
|
||||
const markdown = extracted.markdown
|
||||
|
@ -102,12 +101,11 @@ export module NoteUtils {
|
|||
opengraph: ogdata
|
||||
}
|
||||
callback(data)
|
||||
}
|
||||
}
|
||||
|
||||
function isRevealTheme (theme: string) {
|
||||
function isRevealTheme (theme: string) {
|
||||
if (fs.existsSync(path.join(__dirname, '..', '..', '..', 'public', 'build', 'reveal.js', 'css', 'theme', theme + '.css'))) {
|
||||
return theme
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue