diff options
Diffstat (limited to '')
-rw-r--r-- | lib/response.js | 50 |
1 files changed, 49 insertions, 1 deletions
diff --git a/lib/response.js b/lib/response.js index 99cd080a..9c710751 100644 --- a/lib/response.js +++ b/lib/response.js @@ -51,7 +51,8 @@ var response = { showIndex: showIndex, noteActions: noteActions, publishNoteActions: publishNoteActions, - githubActions: githubActions + githubActions: githubActions, + gitlabActions: gitlabActions }; function responseError(res, code, detail, msg) { @@ -435,6 +436,53 @@ function githubActionGist(req, res, note) { } } +function gitlabActions(req, res, next) { + var noteId = req.params.noteId; + findNote(req, res, function (note) { + var action = req.params.action; + switch (action) { + case "projects": + gitlabActionProjects(req, res, note); + break; + default: + res.redirect(config.serverurl + '/' + noteId); + break; + } + }); +} + +function gitlabActionProjects(req, res, note) { + if (req.isAuthenticated()) { + models.User.findOne({ + where: { + id: req.user.id + } + }).then(function (user) { + if (!user) + return response.errorNotFound(res); + var ret = { baseURL: config.gitlab.baseURL }; + ret.accesstoken = user.accessToken; + ret.profileid = user.profileid; + request( + config.gitlab.baseURL + '/api/v3/projects?access_token=' + user.accessToken, + function(error, httpResponse, body) { + if (!error && httpResponse.statusCode == 200) { + ret.projects = JSON.parse(body); + return res.send(ret); + } else { + return res.send(ret); + } + } + ); + }).catch(function (err) { + logger.error('gitlab action projects failed: ' + err); + return response.errorInternalError(res); + }); + } else { + return response.errorForbidden(res); + } +} + function showPublishSlide(req, res, next) { findNote(req, res, function (note) { note.increment('viewcount').then(function (note) { |