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