2020-05-24 15:09:03 -04:00
|
|
|
import { Request, Response } from 'express'
|
2020-04-25 14:58:38 -04:00
|
|
|
import { config } from '../../config'
|
2020-04-12 11:39:00 -04:00
|
|
|
import { errors } from '../../errors'
|
2020-04-12 07:11:06 -04:00
|
|
|
import { logger } from '../../logger'
|
2020-05-24 15:09:03 -04:00
|
|
|
import { Note } from '../../models'
|
2020-04-25 14:58:38 -04:00
|
|
|
import * as NoteUtils from './util'
|
2020-02-26 08:21:00 -05:00
|
|
|
|
2020-05-24 15:09:03 -04:00
|
|
|
export function publishSlideActions (req: Request, res: Response): void {
|
2020-04-25 14:58:38 -04:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2020-02-26 08:21:00 -05:00
|
|
|
|
2020-05-24 15:09:03 -04:00
|
|
|
export function showPublishSlide (req: Request, res: Response): void {
|
2020-04-25 14:58:38 -04:00
|
|
|
NoteUtils.findNoteOrCreate(req, res, function (note) {
|
|
|
|
// force to use short id
|
|
|
|
const shortid = req.params.shortid
|
|
|
|
if ((note.alias && shortid !== note.alias) || (!note.alias && shortid !== note.shortid)) {
|
|
|
|
return res.redirect(config.serverURL + '/p/' + (note.alias || note.shortid))
|
|
|
|
}
|
|
|
|
note.increment('viewcount').then(function (note) {
|
|
|
|
if (!note) {
|
|
|
|
return errors.errorNotFound(res)
|
2020-02-26 08:21:00 -05:00
|
|
|
}
|
2020-04-25 14:58:38 -04:00
|
|
|
NoteUtils.getPublishData(req, res, note, (data) => {
|
|
|
|
res.set({
|
|
|
|
'Cache-Control': 'private' // only cache by client
|
2020-02-26 08:21:00 -05:00
|
|
|
})
|
2020-04-25 14:58:38 -04:00
|
|
|
return res.render('slide.ejs', data)
|
2020-02-26 08:21:00 -05:00
|
|
|
})
|
2020-04-25 14:58:38 -04:00
|
|
|
}).catch(function (err) {
|
|
|
|
logger.error(err)
|
|
|
|
return errors.errorInternalError(res)
|
|
|
|
})
|
2020-05-24 12:10:37 -04:00
|
|
|
})
|
2020-02-26 08:21:00 -05:00
|
|
|
}
|