Update to move gitlab api path to sub path and fix its find user method for PR #121

This commit is contained in:
Cheng-Han, Wu 2016-05-16 18:16:45 +08:00
parent 5bb4423309
commit eb5873a94d
3 changed files with 52 additions and 32 deletions

View file

@ -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) {