mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-19 01:35:18 -04:00
Move lib and test into src directory
Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
parent
241c418ea7
commit
fab2607e4d
98 changed files with 1 additions and 3 deletions
|
@ -1,95 +0,0 @@
|
|||
import { Response } from 'express'
|
||||
|
||||
import { Note, Revision } from '../../models'
|
||||
import { logger } from '../../logger'
|
||||
import { config } from '../../config'
|
||||
import { errors } from '../../errors'
|
||||
import shortId from 'shortid'
|
||||
import moment from 'moment'
|
||||
import querystring from 'querystring'
|
||||
|
||||
export function getInfo (req: any, res: Response, note: Note): void {
|
||||
const body = note.content
|
||||
const extracted = Note.extractMeta(body)
|
||||
const markdown = extracted.markdown
|
||||
const meta = Note.parseMeta(extracted.meta)
|
||||
const title = Note.decodeTitle(note.title)
|
||||
const data = {
|
||||
title: meta.title || title,
|
||||
description: meta.description || (markdown ? Note.generateDescription(markdown) : null),
|
||||
viewcount: note.viewcount,
|
||||
createtime: note.createdAt,
|
||||
updatetime: note.lastchangeAt
|
||||
}
|
||||
res.set({
|
||||
'Access-Control-Allow-Origin': '*', // allow CORS as API
|
||||
'Access-Control-Allow-Headers': 'Range',
|
||||
'Access-Control-Expose-Headers': 'Cache-Control, Content-Encoding, Content-Range',
|
||||
'Cache-Control': 'private', // only cache by client
|
||||
'X-Robots-Tag': 'noindex, nofollow' // prevent crawling
|
||||
})
|
||||
res.send(data)
|
||||
}
|
||||
|
||||
export function createGist (req: any, res: Response, note: Note): void {
|
||||
const data = {
|
||||
// eslint-disable-next-line @typescript-eslint/camelcase
|
||||
client_id: config.github.clientID,
|
||||
// eslint-disable-next-line @typescript-eslint/camelcase
|
||||
redirect_uri: config.serverURL + '/auth/github/callback/' + Note.encodeNoteId(note.id) + '/gist',
|
||||
scope: 'gist',
|
||||
state: shortId.generate()
|
||||
}
|
||||
const query = querystring.stringify(data)
|
||||
res.redirect('https://github.com/login/oauth/authorize?' + query)
|
||||
}
|
||||
|
||||
export function getRevision (req: any, res: Response, note: Note): void {
|
||||
const actionId = req.params.actionId
|
||||
if (actionId) {
|
||||
const time = moment(parseInt(actionId))
|
||||
if (time.isValid()) {
|
||||
Revision.getPatchedNoteRevisionByTime(note, time, function (err, content) {
|
||||
if (err) {
|
||||
logger.error(err)
|
||||
errors.errorInternalError(res)
|
||||
|
||||
return
|
||||
}
|
||||
if (!content) {
|
||||
errors.errorNotFound(res)
|
||||
return
|
||||
}
|
||||
res.set({
|
||||
'Access-Control-Allow-Origin': '*', // allow CORS as API
|
||||
'Access-Control-Allow-Headers': 'Range',
|
||||
'Access-Control-Expose-Headers': 'Cache-Control, Content-Encoding, Content-Range',
|
||||
'Cache-Control': 'private', // only cache by client
|
||||
'X-Robots-Tag': 'noindex, nofollow' // prevent crawling
|
||||
})
|
||||
res.send(content)
|
||||
})
|
||||
} else {
|
||||
errors.errorNotFound(res)
|
||||
}
|
||||
} else {
|
||||
Revision.getNoteRevisions(note, function (err, data) {
|
||||
if (err) {
|
||||
logger.error(err)
|
||||
errors.errorInternalError(res)
|
||||
return
|
||||
}
|
||||
const out = {
|
||||
revision: data
|
||||
}
|
||||
res.set({
|
||||
'Access-Control-Allow-Origin': '*', // allow CORS as API
|
||||
'Access-Control-Allow-Headers': 'Range',
|
||||
'Access-Control-Expose-Headers': 'Cache-Control, Content-Encoding, Content-Range',
|
||||
'Cache-Control': 'private', // only cache by client
|
||||
'X-Robots-Tag': 'noindex, nofollow' // prevent crawling
|
||||
})
|
||||
res.send(out)
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue