2021-06-12 06:55:08 +08:00
|
|
|
import {Router} from "express";
|
|
|
|
import {markdownParser, urlencodedParser, wrap} from "./utils";
|
2020-01-05 05:59:57 +08:00
|
|
|
|
2021-06-12 06:55:08 +08:00
|
|
|
// load controller
|
|
|
|
import * as indexController from "./homepage";
|
|
|
|
import * as errorPageController from "./errorPage";
|
|
|
|
import * as statusController from "./status";
|
|
|
|
import * as historyController from "./history";
|
|
|
|
import * as userController from "./user";
|
|
|
|
import * as noteController from "./note";
|
2020-01-05 05:59:57 +08:00
|
|
|
|
2021-06-12 06:55:08 +08:00
|
|
|
import * as response from "./response";
|
|
|
|
import * as bodyParser from "body-parser";
|
2020-01-05 05:59:57 +08: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
|
2021-06-12 10:08:49 +08:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
2020-01-05 05:59:57 +08:00
|
|
|
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
|
2021-06-12 10:08:49 +08:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
2020-01-05 05:59:57 +08:00
|
|
|
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-05 07:17:55 +08:00
|
|
|
appRouter.get('/s/:shortid', noteController.showPublishNote)
|
2020-01-05 05:59:57 +08: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 18:30:21 +08:00
|
|
|
// gey my note list
|
2020-07-14 15:27:04 +08:00
|
|
|
appRouter.get('/api/notes/myNotes', noteController.listMyNotes)
|
2020-07-21 00:09:44 +08:00
|
|
|
// delete note by id
|
|
|
|
appRouter.delete('/api/notes/:noteId', noteController.deleteNote)
|
2020-07-21 09:14:02 +08:00
|
|
|
// update note content by id
|
2020-07-30 18:13:35 +08:00
|
|
|
appRouter.put('/api/notes/:noteId', bodyParser.json(), noteController.updateNote)
|
2020-01-05 05:59:57 +08:00
|
|
|
// get note by id
|
2020-01-05 06:58:40 +08:00
|
|
|
appRouter.get('/:noteId', wrap(noteController.showNote))
|
2020-01-05 05:59:57 +08:00
|
|
|
// note actions
|
2020-01-05 07:38:19 +08:00
|
|
|
appRouter.get('/:noteId/:action', noteController.noteActions)
|
2020-01-05 05:59:57 +08:00
|
|
|
// note actions with action id
|
2020-01-05 07:38:19 +08:00
|
|
|
appRouter.get('/:noteId/:action/:actionId', noteController.noteActions)
|
2020-01-05 05:59:57 +08:00
|
|
|
|
|
|
|
exports.router = appRouter
|