summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorCheng-Han, Wu2016-05-16 18:16:45 +0800
committerCheng-Han, Wu2016-05-16 18:16:45 +0800
commiteb5873a94d55528e944371c8fbae77a93201c8af (patch)
tree36680ab106d5185e7abe93b4be3e4610d9931305 /lib
parent5bb4423309ddfd3a161c3ec2472e79067125553e (diff)
Update to move gitlab api path to sub path and fix its find user method for PR #121
Diffstat (limited to 'lib')
-rw-r--r--lib/response.js50
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) {