From eb5873a94d55528e944371c8fbae77a93201c8af Mon Sep 17 00:00:00 2001 From: Cheng-Han, Wu Date: Mon, 16 May 2016 18:16:45 +0800 Subject: Update to move gitlab api path to sub path and fix its find user method for PR #121 --- lib/response.js | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) (limited to 'lib/response.js') 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) { -- cgit v1.2.3