From 21a3e59b5d2714808c89f1edf63eb42bd912fc77 Mon Sep 17 00:00:00 2001 From: "xiaoqi.cxq" Date: Sun, 2 Oct 2022 00:20:01 +0800 Subject: [PATCH] =?UTF-8?q?gitea=E6=94=AF=E6=8C=81=E5=90=AF=E5=8A=A8?= =?UTF-8?q?=E6=97=B6=E6=8C=87=E5=AE=9AclientId=E5=92=8C=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E5=9C=B0=E5=9D=80=E7=AD=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chart/values.yaml | 3 + config/dev.env.js | 3 + server/conf.js | 8 +++ server/gitea.js | 41 ++++++++++++ server/index.js | 2 + .../modals/providers/GiteaAccountModal.vue | 57 +++++++++------- src/services/providers/helpers/giteaHelper.js | 66 ++++++++++++++----- 7 files changed, 142 insertions(+), 38 deletions(-) create mode 100644 server/gitea.js diff --git a/chart/values.yaml b/chart/values.yaml index 3fddafb8..ce054d9f 100644 --- a/chart/values.yaml +++ b/chart/values.yaml @@ -15,6 +15,9 @@ wordpressSecret: "" paypalReceiverEmail: "" awsAccessKeyId: "" awsSecretAccessKey: "" +giteaClientId: "" +giteaClientSecret: "" +giteaUrl: "" replicaCount: 1 diff --git a/config/dev.env.js b/config/dev.env.js index f31dba18..363113d9 100644 --- a/config/dev.env.js +++ b/config/dev.env.js @@ -9,4 +9,7 @@ module.exports = merge(prodEnv, { GITEE_CLIENT_ID: '"925ba7c78b85dec984f7877e4aca5cab10ae333c6d68e761bdb0b9dfb8f55672"', GITEE_CLIENT_SECRET: '"f05731066e42d307339dc8ebbb037a103881dafc7207a359a393b87749f1c562"', CLIENT_ID: '"thF3qCGLN39OtafjGnqHyj6n02WwE6xD"', + // GITEA_CLIENT_ID: '"fe30f8f9-b1e8-4531-8f72-c1a5d3912805"', + // GITEA_CLIENT_SECRET: '"lus7oMnb3H6M1hsChndphArE20Txr7erwJLf7SDBQWTw"', + // GITEA_URL: '"https://gitea.test.com"', }) \ No newline at end of file diff --git a/server/conf.js b/server/conf.js index f86e1f54..748621d3 100644 --- a/server/conf.js +++ b/server/conf.js @@ -13,6 +13,9 @@ const giteeClientSecret = process.env.GITEE_CLIENT_SECRET; const googleClientId = process.env.GOOGLE_CLIENT_ID; const googleApiKey = process.env.GOOGLE_API_KEY; const wordpressClientId = process.env.WORDPRESS_CLIENT_ID; +const giteaClientId = process.env.GITEA_CLIENT_ID; +const giteaClientSecret = process.env.GITEA_CLIENT_SECRET; +const giteaUrl = process.env.GITEA_URL; exports.values = { pandocPath, @@ -29,6 +32,9 @@ exports.values = { googleClientId, googleApiKey, wordpressClientId, + giteaClientId, + giteaClientSecret, + giteaUrl, }; exports.publicValues = { @@ -39,4 +45,6 @@ exports.publicValues = { googleApiKey, wordpressClientId, allowSponsorship: !!paypalReceiverEmail, + giteaClientId, + giteaUrl, }; diff --git a/server/gitea.js b/server/gitea.js new file mode 100644 index 00000000..ea7c5b5a --- /dev/null +++ b/server/gitea.js @@ -0,0 +1,41 @@ +const qs = require('qs'); +const request = require('request'); +const conf = require('./conf'); + +function giteaToken(queryParam) { + return new Promise((resolve, reject) => { + request({ + method: 'POST', + url: `${conf.values.giteaUrl}/login/oauth/access_token`, + headers: { + 'content-type': 'application/json', + }, + json: true, + body: { + ...queryParam, + client_id: conf.values.giteaClientId, + client_secret: conf.values.giteaClientSecret, + }, + }, (err, res, body) => { + if (err) { + reject(err); + } + const token = body.access_token; + if (token) { + resolve(body); + } else { + reject(res.statusCode + ',body:' + JSON.stringify(body)); + } + }); + }); +} + +exports.giteaToken = (req, res) => { + giteaToken(req.query) + .then( + tokenBody => res.send(tokenBody), + err => res + .status(400) + .send(err ? err.message || err.toString() : 'bad_code'), + ); +}; diff --git a/server/index.js b/server/index.js index b3ced48e..f6fc873c 100644 --- a/server/index.js +++ b/server/index.js @@ -5,6 +5,7 @@ const path = require('path'); const user = require('./user'); const github = require('./github'); const gitee = require('./gitee'); +const gitea = require('./gitea'); const pdf = require('./pdf'); const pandoc = require('./pandoc'); const conf = require('./conf'); @@ -27,6 +28,7 @@ module.exports = (app) => { app.get('/oauth2/githubToken', github.githubToken); app.get('/oauth2/giteeToken', gitee.giteeToken); + app.get('/oauth2/giteaToken', gitea.giteaToken); app.get('/conf', (req, res) => res.send(conf.publicValues)); app.get('/userInfo', user.userInfo); app.post('/pdfExport', pdf.generate); diff --git a/src/components/modals/providers/GiteaAccountModal.vue b/src/components/modals/providers/GiteaAccountModal.vue index 2bb3f4ea..f22d7b38 100644 --- a/src/components/modals/providers/GiteaAccountModal.vue +++ b/src/components/modals/providers/GiteaAccountModal.vue @@ -5,28 +5,30 @@

将您的Gitea链接到StackEdit中文版

- - - - - - - - - - - -
- 更多信息 -
-
+