@@ -51,7 +51,8 @@ var response = {
5151 showIndex : showIndex ,
5252 noteActions : noteActions ,
5353 publishNoteActions : publishNoteActions ,
54- githubActions : githubActions
54+ githubActions : githubActions ,
55+ gitlabActions : gitlabActions
5556} ;
5657
5758function responseError ( res , code , detail , msg ) {
@@ -435,6 +436,53 @@ function githubActionGist(req, res, note) {
435436 }
436437}
437438
439+ function gitlabActions ( req , res , next ) {
440+ var noteId = req . params . noteId ;
441+ findNote ( req , res , function ( note ) {
442+ var action = req . params . action ;
443+ switch ( action ) {
444+ case "projects" :
445+ gitlabActionProjects ( req , res , note ) ;
446+ break ;
447+ default :
448+ res . redirect ( config . serverurl + '/' + noteId ) ;
449+ break ;
450+ }
451+ } ) ;
452+ }
453+
454+ function gitlabActionProjects ( req , res , note ) {
455+ if ( req . isAuthenticated ( ) ) {
456+ models . User . findOne ( {
457+ where : {
458+ id : req . user . id
459+ }
460+ } ) . then ( function ( user ) {
461+ if ( ! user )
462+ return response . errorNotFound ( res ) ;
463+ var ret = { baseURL : config . gitlab . baseURL } ;
464+ ret . accesstoken = user . accessToken ;
465+ ret . profileid = user . profileid ;
466+ request (
467+ config . gitlab . baseURL + '/api/v3/projects?access_token=' + user . accessToken ,
468+ function ( error , httpResponse , body ) {
469+ if ( ! error && httpResponse . statusCode == 200 ) {
470+ ret . projects = JSON . parse ( body ) ;
471+ return res . send ( ret ) ;
472+ } else {
473+ return res . send ( ret ) ;
474+ }
475+ }
476+ ) ;
477+ } ) . catch ( function ( err ) {
478+ logger . error ( 'gitlab action projects failed: ' + err ) ;
479+ return response . errorInternalError ( res ) ;
480+ } ) ;
481+ } else {
482+ return response . errorForbidden ( res ) ;
483+ }
484+ }
485+
438486function showPublishSlide ( req , res , next ) {
439487 findNote ( req , res , function ( note ) {
440488 note . increment ( 'viewcount' ) . then ( function ( note ) {
0 commit comments