2020-01-04 21:59:57 +00:00
|
|
|
'use strict'
|
|
|
|
|
|
|
|
const { Router } = require('express')
|
|
|
|
|
|
|
|
const { wrap, urlencodedParser, markdownParser } = require('./utils')
|
|
|
|
|
|
|
|
// load controller
|
|
|
|
const indexController = require('./homepage')
|
|
|
|
const errorPageController = require('./errorPage')
|
|
|
|
const statusController = require('./status')
|
|
|
|
const historyController = require('./history')
|
|
|
|
const userController = require('./user')
|
2020-01-04 22:58:40 +00:00
|
|
|
const noteController = require('./note')
|
2020-01-04 22:30:23 +00:00
|
|
|
const response = require('./response')
|
2020-07-30 10:13:35 +00:00
|
|
|
const bodyParser = require('body-parser')
|
2020-01-04 21:59:57 +00:00
|
|
|
const appRouter = Router()
|
|
|
|
|
|
|
|
// register route
|
|
|
|
|
|
|
|
// get index
|
|
|
|
appRouter.get('/', wrap(indexController.showIndex))
|
|
|
|
|
|
|
|
// ----- error page -----
|
|
|
|
// get 403 forbidden
|
|
|
|
appRouter.get('/403', errorPageController.errorForbidden)
|
|
|
|
// get 404 not found
|
|
|
|
appRouter.get('/404', errorPageController.errorNotFound)
|
|
|
|
// get 500 internal error
|
|
|
|
appRouter.get('/500', errorPageController.errorInternalError)
|
|
|
|
|
|
|
|
appRouter.get('/config', statusController.getConfig)
|
|
|
|
|
|
|
|
// register auth module
|
|
|
|
appRouter.use(require('./auth'))
|
|
|
|
|
|
|
|
// get history
|
|
|
|
appRouter.get('/history', historyController.historyGet)
|
|
|
|
// post history
|
|
|
|
appRouter.post('/history', urlencodedParser, historyController.historyPost)
|
|
|
|
// post history by note id
|
|
|
|
appRouter.post('/history/:noteId', urlencodedParser, historyController.historyPost)
|
|
|
|
// delete history
|
|
|
|
appRouter.delete('/history', historyController.historyDelete)
|
|
|
|
// delete history by note id
|
|
|
|
appRouter.delete('/history/:noteId', historyController.historyDelete)
|
|
|
|
|
|
|
|
// user
|
|
|
|
// get me info
|
|
|
|
appRouter.get('/me', wrap(userController.getMe))
|
|
|
|
|
|
|
|
// delete the currently authenticated user
|
|
|
|
appRouter.get('/me/delete/:token?', wrap(userController.deleteUser))
|
|
|
|
|
|
|
|
// export the data of the authenticated user
|
|
|
|
appRouter.get('/me/export', userController.exportMyData)
|
|
|
|
|
|
|
|
appRouter.get('/user/:username/avatar.svg', userController.getMyAvatar)
|
|
|
|
|
|
|
|
// register image upload module
|
|
|
|
appRouter.use(require('./imageRouter'))
|
|
|
|
|
|
|
|
// get new note
|
|
|
|
appRouter.get('/new', response.newNote)
|
|
|
|
// post new note with content
|
|
|
|
appRouter.post('/new', markdownParser, response.newNote)
|
|
|
|
// get publish note
|
2020-01-04 23:17:55 +00:00
|
|
|
appRouter.get('/s/:shortid', noteController.showPublishNote)
|
2020-01-04 21:59:57 +00:00
|
|
|
// publish note actions
|
|
|
|
appRouter.get('/s/:shortid/:action', response.publishNoteActions)
|
|
|
|
// get publish slide
|
|
|
|
appRouter.get('/p/:shortid', response.showPublishSlide)
|
|
|
|
// publish slide actions
|
|
|
|
appRouter.get('/p/:shortid/:action', response.publishSlideActions)
|
2020-06-30 10:30:21 +00:00
|
|
|
// gey my note list
|
2020-07-14 07:27:04 +00:00
|
|
|
appRouter.get('/api/notes/myNotes', noteController.listMyNotes)
|
2020-07-20 16:09:44 +00:00
|
|
|
// delete note by id
|
|
|
|
appRouter.delete('/api/notes/:noteId', noteController.deleteNote)
|
2020-07-21 01:14:02 +00:00
|
|
|
// update note content by id
|
2020-07-30 10:13:35 +00:00
|
|
|
appRouter.put('/api/notes/:noteId', bodyParser.json(), noteController.updateNote)
|
2020-01-04 21:59:57 +00:00
|
|
|
// get note by id
|
2020-01-04 22:58:40 +00:00
|
|
|
appRouter.get('/:noteId', wrap(noteController.showNote))
|
2020-01-04 21:59:57 +00:00
|
|
|
// note actions
|
2020-01-04 23:38:19 +00:00
|
|
|
appRouter.get('/:noteId/:action', noteController.noteActions)
|
2020-01-04 21:59:57 +00:00
|
|
|
// note actions with action id
|
2020-01-04 23:38:19 +00:00
|
|
|
appRouter.get('/:noteId/:action/:actionId', noteController.noteActions)
|
2020-01-04 21:59:57 +00:00
|
|
|
|
|
|
|
exports.router = appRouter
|