summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/response.js75
-rw-r--r--lib/utils.js9
-rw-r--r--lib/web/note/router.js5
-rw-r--r--lib/web/note/slide.js83
4 files changed, 87 insertions, 85 deletions
diff --git a/lib/response.js b/lib/response.js
index 033a83a6..934179fd 100644
--- a/lib/response.js
+++ b/lib/response.js
@@ -8,7 +8,6 @@ var request = require('request')
var config = require('./config')
var logger = require('./logger')
var models = require('./models')
-var utils = require('./utils')
const noteUtil = require('./web/note/util')
const noteActions = require('./web/note/actions')
const errors = require('./errors')
@@ -17,11 +16,9 @@ const errors = require('./errors')
var response = {
showNote: showNote,
showPublishNote: showPublishNote,
- showPublishSlide: showPublishSlide,
showIndex: showIndex,
postNote: postNote,
publishNoteActions: publishNoteActions,
- publishSlideActions: publishSlideActions,
githubActions: githubActions,
gitlabActions: gitlabActions
}
@@ -171,19 +168,7 @@ function publishNoteActions (req, res, next) {
})
}
-function publishSlideActions (req, res, next) {
- noteUtil.findNote(req, res, function (note) {
- var action = req.params.action
- switch (action) {
- case 'edit':
- res.redirect(config.serverURL + '/' + (note.alias ? note.alias : models.Note.encodeNoteId(note.id)) + '?both')
- break
- default:
- res.redirect(config.serverURL + '/p/' + note.shortid)
- break
- }
- })
-}
+
function githubActions (req, res, next) {
var noteId = req.params.noteId
@@ -303,62 +288,4 @@ function gitlabActionProjects (req, res, note) {
}
}
-function showPublishSlide (req, res, next) {
- var include = [{
- model: models.User,
- as: 'owner'
- }, {
- model: models.User,
- as: 'lastchangeuser'
- }]
- noteUtil.findNote(req, res, function (note) {
- // force to use short id
- var 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)
- }
- var body = note.content
- var extracted = models.Note.extractMeta(body)
- var markdown = extracted.markdown
- var meta = models.Note.parseMeta(extracted.meta)
- var createtime = note.createdAt
- var updatetime = note.lastchangeAt
- var title = models.Note.decodeTitle(note.title)
- title = models.Note.generateWebTitle(meta.title || title)
- var data = {
- title: title,
- description: meta.description || (markdown ? models.Note.generateDescription(markdown) : null),
- viewcount: note.viewcount,
- createtime: createtime,
- updatetime: updatetime,
- body: markdown,
- theme: meta.slideOptions && utils.isRevealTheme(meta.slideOptions.theme),
- meta: JSON.stringify(extracted.meta),
- owner: note.owner ? note.owner.id : null,
- ownerprofile: note.owner ? models.User.getProfile(note.owner) : null,
- lastchangeuser: note.lastchangeuser ? note.lastchangeuser.id : null,
- lastchangeuserprofile: note.lastchangeuser ? models.User.getProfile(note.lastchangeuser) : null,
- robots: meta.robots || false, // default allow robots
- GA: meta.GA,
- disqus: meta.disqus,
- cspNonce: res.locals.nonce,
- dnt: req.headers.dnt
- }
- return renderPublishSlide(data, res)
- }).catch(function (err) {
- logger.error(err)
- return errors.errorInternalError(res)
- })
- }, include)
-}
-
-function renderPublishSlide (data, res) {
- res.set({
- 'Cache-Control': 'private' // only cache by client
- })
- res.render('slide.ejs', data)
-}
-
module.exports = response
diff --git a/lib/utils.js b/lib/utils.js
index 1725f6e8..270cbd6a 100644
--- a/lib/utils.js
+++ b/lib/utils.js
@@ -1,6 +1,4 @@
'use strict'
-const fs = require('fs')
-const path = require('path')
exports.isSQLite = function isSQLite (sequelize) {
return sequelize.options.dialect === 'sqlite'
@@ -27,10 +25,3 @@ exports.getImageMimeType = function getImageMimeType (imagePath) {
return undefined
}
}
-
-exports.isRevealTheme = function isRevealTheme (theme) {
- if (fs.existsSync(path.join(__dirname, '..', 'public', 'build', 'reveal.js', 'css', 'theme', theme + '.css'))) {
- return theme
- }
- return undefined
-}
diff --git a/lib/web/note/router.js b/lib/web/note/router.js
index e23b7f64..2a6bf2aa 100644
--- a/lib/web/note/router.js
+++ b/lib/web/note/router.js
@@ -9,6 +9,7 @@ const { markdownParser } = require('../utils')
const router = module.exports = Router()
const noteActions = require('./actions')
+const slide = require('./slide')
// get new note
router.get('/new', response.postNote)
@@ -21,9 +22,9 @@ router.get('/s/:shortid', response.showPublishNote)
// publish note actions
router.get('/s/:shortid/:action', response.publishNoteActions)
// get publish slide
-router.get('/p/:shortid', response.showPublishSlide)
+router.get('/p/:shortid', slide.showPublishSlide)
// publish slide actions
-router.get('/p/:shortid/:action', response.publishSlideActions)
+router.get('/p/:shortid/:action', slide.publishSlideActions)
// get note by id
router.get('/:noteId', response.showNote)
// note actions
diff --git a/lib/web/note/slide.js b/lib/web/note/slide.js
new file mode 100644
index 00000000..58e46102
--- /dev/null
+++ b/lib/web/note/slide.js
@@ -0,0 +1,83 @@
+const noteUtil = require('./util')
+const models = require('../../models')
+const errors = require('../../errors')
+const logger = require('../../logger')
+const config = require('../../config')
+const fs = require('fs')
+const path = require('path')
+
+exports.publishSlideActions = function (req, res, next) {
+ noteUtil.findNote(req, res, function (note) {
+ const action = req.params.action
+ if (action === 'edit') {
+ res.redirect(config.serverURL + '/' + (note.alias ? note.alias : models.Note.encodeNoteId(note.id)) + '?both')
+ } else { res.redirect(config.serverURL + '/p/' + note.shortid) }
+ })
+}
+
+exports.showPublishSlide = function (req, res, next) {
+ const include = [{
+ model: models.User,
+ as: 'owner'
+ }, {
+ model: models.User,
+ as: 'lastchangeuser'
+ }]
+ noteUtil.findNote(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)
+ }
+ const body = note.content
+ const extracted = models.Note.extractMeta(body)
+ const markdown = extracted.markdown
+ const meta = models.Note.parseMeta(extracted.meta)
+ const createtime = note.createdAt
+ const updatetime = note.lastchangeAt
+ let title = models.Note.decodeTitle(note.title)
+ title = models.Note.generateWebTitle(meta.title || title)
+ const data = {
+ title: title,
+ description: meta.description || (markdown ? models.Note.generateDescription(markdown) : null),
+ viewcount: note.viewcount,
+ createtime: createtime,
+ updatetime: updatetime,
+ body: markdown,
+ theme: meta.slideOptions && isRevealTheme(meta.slideOptions.theme),
+ meta: JSON.stringify(extracted.meta),
+ owner: note.owner ? note.owner.id : null,
+ ownerprofile: note.owner ? models.User.getProfile(note.owner) : null,
+ lastchangeuser: note.lastchangeuser ? note.lastchangeuser.id : null,
+ lastchangeuserprofile: note.lastchangeuser ? models.User.getProfile(note.lastchangeuser) : null,
+ robots: meta.robots || false, // default allow robots
+ GA: meta.GA,
+ disqus: meta.disqus,
+ cspNonce: res.locals.nonce,
+ dnt: req.headers.dnt
+ }
+ return renderPublishSlide(data, res)
+ }).catch(function (err) {
+ logger.error(err)
+ return errors.errorInternalError(res)
+ })
+ }, include)
+}
+
+function renderPublishSlide (data, res) {
+ res.set({
+ 'Cache-Control': 'private' // only cache by client
+ })
+ res.render('slide.ejs', data)
+}
+
+function isRevealTheme (theme) {
+ if (fs.existsSync(path.join(__dirname, '..', 'public', 'build', 'reveal.js', 'css', 'theme', theme + '.css'))) {
+ return theme
+ }
+ return undefined
+}