diff --git a/lib/web/note/router.ts b/lib/web/note/router.ts index a200c59dd..713c1c9e7 100644 --- a/lib/web/note/router.ts +++ b/lib/web/note/router.ts @@ -1,6 +1,6 @@ import {markdownParser} from "../utils"; -import slide from "./slide"; +import {SlideController} from "./slide"; import {NoteController} from "./controller"; import {Router} from "express"; @@ -16,9 +16,9 @@ router.get('/s/:shortid', NoteController.showPublishNote); // publish note actions router.get('/s/:shortid/:action', NoteController.publishNoteActions); // get publish slide -router.get('/p/:shortid', slide.showPublishSlide); +router.get('/p/:shortid', SlideController.showPublishSlide); // publish slide actions -router.get('/p/:shortid/:action', slide.publishSlideActions); +router.get('/p/:shortid/:action', SlideController.publishSlideActions); // get note by id router.get('/:noteId', NoteController.showNote); // note actions diff --git a/lib/web/note/slide.js b/lib/web/note/slide.js deleted file mode 100644 index d2d2ccfc5..000000000 --- a/lib/web/note/slide.js +++ /dev/null @@ -1,45 +0,0 @@ -const noteUtil = require('./util') -const models = require('../../models') -const errors = require('../../errors') -const logger = require('../../logger') -const config = require('../../config') - -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) - } - noteUtil.getPublishData(req, res, note, (data) => { - res.set({ - 'Cache-Control': 'private' // only cache by client - }) - return res.render('slide.ejs', data) - }) - }).catch(function (err) { - logger.error(err) - return errors.errorInternalError(res) - }) - }, include) -} diff --git a/lib/web/note/slide.ts b/lib/web/note/slide.ts new file mode 100644 index 000000000..948ac7a5e --- /dev/null +++ b/lib/web/note/slide.ts @@ -0,0 +1,51 @@ +import {NextFunction, Response} from "express"; +import {NoteUtils} from "./util"; +import models from '../../models'; +import errors from '../../errors'; +import logger from '../../logger'; +import config from '../../config'; + + +export module SlideController{ + export function publishSlideActions (req: any, res: Response, next: NextFunction) { + NoteUtils.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) } + }) + } + + + + export function showPublishSlide(req: any, res: Response, next: NextFunction) { + const include = [{ + model: models.User, + as: 'owner' + }, { + model: models.User, + as: 'lastchangeuser' + }] + NoteUtils.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) + } + NoteUtils.getPublishData(req, res, note, (data) => { + res.set({ + 'Cache-Control': 'private' // only cache by client + }) + return res.render('slide.ejs', data) + }) + }).catch(function (err) { + logger.error(err) + return errors.errorInternalError(res) + }) + }, include) + } +}