Skip to content

Commit 6c968f9

Browse files
committed
fix: history api failed cause by circular dependency
Signed-off-by: BoHong Li <raccoon@hackmd.io>
1 parent 18abc20 commit 6c968f9

File tree

2 files changed

+38
-46
lines changed

2 files changed

+38
-46
lines changed

lib/history.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,6 @@ var logger = require('./logger')
99
var response = require('./response')
1010
var models = require('./models')
1111

12-
// public
13-
var History = {
14-
historyGet: historyGet,
15-
historyPost: historyPost,
16-
historyDelete: historyDelete,
17-
updateHistory: updateHistory
18-
}
19-
2012
function getHistory (userid, callback) {
2113
models.User.findOne({
2214
where: {
@@ -200,4 +192,8 @@ function historyDelete (req, res) {
200192
}
201193
}
202194

203-
module.exports = History
195+
// public
196+
exports.historyGet = historyGet
197+
exports.historyPost = historyPost
198+
exports.historyDelete = historyDelete
199+
exports.updateHistory = updateHistory

lib/response.js

Lines changed: 33 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -17,42 +17,40 @@ var utils = require('./utils')
1717
var history = require('./history')
1818

1919
// public
20-
var response = {
21-
errorForbidden: function (res) {
22-
const { req } = res
23-
if (req.user) {
24-
responseError(res, '403', 'Forbidden', 'oh no.')
25-
} else {
26-
req.flash('error', 'You are not allowed to access this page. Maybe try logging in?')
27-
res.redirect(config.serverURL + '/')
28-
}
29-
},
30-
errorNotFound: function (res) {
31-
responseError(res, '404', 'Not Found', 'oops.')
32-
},
33-
errorBadRequest: function (res) {
34-
responseError(res, '400', 'Bad Request', 'something not right.')
35-
},
36-
errorTooLong: function (res) {
37-
responseError(res, '413', 'Payload Too Large', 'Shorten your note!')
38-
},
39-
errorInternalError: function (res) {
40-
responseError(res, '500', 'Internal Error', 'wtf.')
41-
},
42-
errorServiceUnavailable: function (res) {
43-
res.status(503).send("I'm busy right now, try again later.")
44-
},
45-
newNote: newNote,
46-
showNote: showNote,
47-
showPublishNote: showPublishNote,
48-
showPublishSlide: showPublishSlide,
49-
showIndex: showIndex,
50-
noteActions: noteActions,
51-
publishNoteActions: publishNoteActions,
52-
publishSlideActions: publishSlideActions,
53-
githubActions: githubActions,
54-
gitlabActions: gitlabActions
20+
exports.errorForbidden = function (res) {
21+
const { req } = res
22+
if (req.user) {
23+
responseError(res, '403', 'Forbidden', 'oh no.')
24+
} else {
25+
req.flash('error', 'You are not allowed to access this page. Maybe try logging in?')
26+
res.redirect(config.serverURL + '/')
27+
}
28+
}
29+
exports.errorNotFound = function (res) {
30+
responseError(res, '404', 'Not Found', 'oops.')
5531
}
32+
exports.errorBadRequest = function (res) {
33+
responseError(res, '400', 'Bad Request', 'something not right.')
34+
}
35+
exports.errorTooLong = function (res) {
36+
responseError(res, '413', 'Payload Too Large', 'Shorten your note!')
37+
}
38+
exports.errorInternalError = function (res) {
39+
responseError(res, '500', 'Internal Error', 'wtf.')
40+
}
41+
exports.errorServiceUnavailable = function (res) {
42+
res.status(503).send("I'm busy right now, try again later.")
43+
}
44+
exports.newNote = newNote
45+
exports.showNote = showNote
46+
exports.showPublishNote = showPublishNote
47+
exports.showPublishSlide = showPublishSlide
48+
exports.showIndex = showIndex
49+
exports.noteActions = noteActions
50+
exports.publishNoteActions = publishNoteActions
51+
exports.publishSlideActions = publishSlideActions
52+
exports.githubActions = githubActions
53+
exports.gitlabActions = gitlabActions
5654

5755
function responseError (res, code, detail, msg) {
5856
res.status(code).render('error.ejs', {
@@ -635,5 +633,3 @@ function renderPublishSlide (data, res) {
635633
})
636634
res.render('slide.ejs', data)
637635
}
638-
639-
module.exports = response

0 commit comments

Comments
 (0)