mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-23 10:16:32 -05:00
More ESLint fixes
Signed-off-by: David Mehren <dmehren1@gmail.com>
This commit is contained in:
parent
b65ae091bd
commit
64d14bff10
2 changed files with 41 additions and 39 deletions
|
@ -21,6 +21,8 @@ const debugConfig = {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get version string from package.json
|
// Get version string from package.json
|
||||||
|
// TODO: There are other ways to geht the current version
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||||
const { version, repository } = require(path.join(appRootPath, 'package.json'))
|
const { version, repository } = require(path.join(appRootPath, 'package.json'))
|
||||||
|
|
||||||
const commitID = getGitCommit(appRootPath)
|
const commitID = getGitCommit(appRootPath)
|
||||||
|
|
|
@ -8,6 +8,41 @@ import { errors } from '../../errors'
|
||||||
import { logger } from '../../logger'
|
import { logger } from '../../logger'
|
||||||
import { Note, User } from '../../models'
|
import { Note, User } from '../../models'
|
||||||
|
|
||||||
|
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()) {
|
||||||
|
owner = req.user.id
|
||||||
|
} else if (!config.allowAnonymous) {
|
||||||
|
return errors.errorForbidden(res)
|
||||||
|
}
|
||||||
|
if (config.allowFreeURL && noteId && !config.forbiddenNoteIDs.includes(noteId)) {
|
||||||
|
req.alias = noteId
|
||||||
|
} else if (noteId) {
|
||||||
|
return req.method === 'POST' ? errors.errorForbidden(res) : errors.errorNotFound(res)
|
||||||
|
}
|
||||||
|
Note.create({
|
||||||
|
ownerId: owner,
|
||||||
|
alias: req.alias ? req.alias : null,
|
||||||
|
content: body
|
||||||
|
}).then(function (note) {
|
||||||
|
return res.redirect(config.serverURL + '/' + (note.alias ? note.alias : Note.encodeNoteId(note.id)))
|
||||||
|
}).catch(function (err) {
|
||||||
|
logger.error(err)
|
||||||
|
return errors.errorInternalError(res)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
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') {
|
||||||
|
return req.isAuthenticated()
|
||||||
|
} else {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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) {
|
||||||
|
@ -35,39 +70,11 @@ export function findNoteOrCreate (req, res, callback: (note: any) => void, inclu
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export function checkViewPermission (req: any, note: any) {
|
function isRevealTheme (theme: string) {
|
||||||
if (note.permission === 'private') {
|
if (fs.existsSync(path.join(__dirname, '..', '..', '..', 'public', 'build', 'reveal.js', 'css', 'theme', theme + '.css'))) {
|
||||||
return req.isAuthenticated() && note.ownerId === req.user.id
|
return theme
|
||||||
} else if (note.permission === 'limited' || note.permission === 'protected') {
|
|
||||||
return req.isAuthenticated()
|
|
||||||
} else {
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
}
|
return undefined
|
||||||
|
|
||||||
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()) {
|
|
||||||
owner = req.user.id
|
|
||||||
} else if (!config.allowAnonymous) {
|
|
||||||
return errors.errorForbidden(res)
|
|
||||||
}
|
|
||||||
if (config.allowFreeURL && noteId && !config.forbiddenNoteIDs.includes(noteId)) {
|
|
||||||
req.alias = noteId
|
|
||||||
} else if (noteId) {
|
|
||||||
return req.method === 'POST' ? errors.errorForbidden(res) : errors.errorNotFound(res)
|
|
||||||
}
|
|
||||||
Note.create({
|
|
||||||
ownerId: owner,
|
|
||||||
alias: req.alias ? req.alias : null,
|
|
||||||
content: body
|
|
||||||
}).then(function (note) {
|
|
||||||
return res.redirect(config.serverURL + '/' + (note.alias ? note.alias : Note.encodeNoteId(note.id)))
|
|
||||||
}).catch(function (err) {
|
|
||||||
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) {
|
||||||
|
@ -102,10 +109,3 @@ export function getPublishData (req: any, res: Response, note: any, callback: (d
|
||||||
}
|
}
|
||||||
callback(data)
|
callback(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
function isRevealTheme (theme: string) {
|
|
||||||
if (fs.existsSync(path.join(__dirname, '..', '..', '..', 'public', 'build', 'reveal.js', 'css', 'theme', theme + '.css'))) {
|
|
||||||
return theme
|
|
||||||
}
|
|
||||||
return undefined
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue