diff --git a/lib/response.js b/lib/response.js index 63099b8..2114c99 100644 --- a/lib/response.js +++ b/lib/response.js @@ -321,17 +321,6 @@ function actionGist(req, res, note) { res.redirect("https://github.com/login/oauth/authorize?" + query); } -function actionSnippet(req, res, note) { - var data = { - client_id: config.gitlab.clientID, - redirect_uri: config.serverurl + '/auth/github/callback/' + LZString.compressToBase64(note.id) + '/gist', - scope: "snippet", - state: shortId.generate() - }; - var query = querystring.stringify(data); - res.redirect(config.gitlab.baseURL + "/login/oauth/authorize?" + query); -} - function noteActions(req, res, next) { var noteId = req.params.noteId; findNote(req, res, function (note) { @@ -389,21 +378,6 @@ function githubActions(req, res, next) { }); } -function gitlabActions(req, res, next) { - var noteId = req.params.noteId; - findNote(req, res, function (note) { - var action = req.params.action; - switch (action) { - case "gist": - gitlabActionSnippet(req, res, note); - break; - default: - res.redirect(config.serverurl + '/' + noteId); - break; - } - }); -} - function githubActionGist(req, res, note) { var code = req.query.code; var state = req.query.state; @@ -461,63 +435,6 @@ function githubActionGist(req, res, note) { } } -function gitlabActionSnippet(req, res, note) { - var code = req.query.code; - var state = req.query.state; - if (!code || !state) { - return response.errorForbidden(res); - } else { - var data = { - client_id: config.gitlab.clientID, - client_secret: config.gitlab.clientSecret, - code: code, - state: state - } - var auth_url = config.gitlab.baseURL + '/login/oauth/access_token'; - request({ - url: auth_url, - method: "POST", - json: data - }, function (error, httpResponse, body) { - if (!error && httpResponse.statusCode == 200) { - var access_token = body.access_token; - if (access_token) { - var content = LZString.decompressFromBase64(note.content); - var title = models.Note.decodeTitle(note.title); - var filename = title.replace('/', ' ') + '.md'; - var gist = { - "files": {} - }; - gist.files[filename] = { - "content": content - }; - var gist_url = "https://api.gitlab.com/snippets"; - request({ - url: gist_url, - headers: { - 'User-Agent': 'HackMD', - 'Authorization': 'token ' + access_token - }, - method: "POST", - json: gist - }, function (error, httpResponse, body) { - if (!error && httpResponse.statusCode == 201) { - res.setHeader('referer', ''); - res.redirect(body.html_url); - } else { - return response.errorForbidden(res); - } - }); - } else { - return response.errorForbidden(res); - } - } else { - return response.errorForbidden(res); - } - }) - } -} - function showPublishSlide(req, res, next) { findNote(req, res, function (note) { note.increment('viewcount').then(function (note) {