From d3c0f3c251e8371d78d953f32f7311a38f4a1bdb Mon Sep 17 00:00:00 2001 From: MeiMei <30769358+mei23@users.noreply.github.com> Date: Thu, 9 Apr 2020 23:42:23 +0900 Subject: Use node-fetch instead of request (#6228) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * requestをnode-fetchになど * format * fix error * t * Fix test --- src/server/api/service/github.ts | 37 +++++++------------------------------ 1 file changed, 7 insertions(+), 30 deletions(-) (limited to 'src/server/api/service/github.ts') diff --git a/src/server/api/service/github.ts b/src/server/api/service/github.ts index e36c43ee38..663c3cc754 100644 --- a/src/server/api/service/github.ts +++ b/src/server/api/service/github.ts @@ -1,6 +1,6 @@ import * as Koa from 'koa'; import * as Router from '@koa/router'; -import * as request from 'request'; +import { getJson } from '../../../misc/fetch'; import { OAuth2 } from 'oauth'; import config from '../../../config'; import { publishMainStream } from '../../../services/stream'; @@ -167,21 +167,9 @@ router.get('/gh/cb', async ctx => { } })); - const { login, id } = await new Promise((res, rej) => - request({ - url: 'https://api.github.com/user', - headers: { - 'Accept': 'application/vnd.github.v3+json', - 'Authorization': `bearer ${accessToken}`, - 'User-Agent': config.userAgent - } - }, (err, response, body) => { - if (err) - rej(err); - else - res(JSON.parse(body)); - })); - + const { login, id } = await getJson('https://api.github.com/user', 'application/vnd.github.v3+json', 10 * 1000, { + 'Authorization': `bearer ${accessToken}` + }); if (!login || !id) { ctx.throw(400, 'invalid session'); return; @@ -230,20 +218,9 @@ router.get('/gh/cb', async ctx => { res({ accessToken }); })); - const { login, id } = await new Promise((res, rej) => - request({ - url: 'https://api.github.com/user', - headers: { - 'Accept': 'application/vnd.github.v3+json', - 'Authorization': `bearer ${accessToken}`, - 'User-Agent': config.userAgent - } - }, (err, response, body) => { - if (err) - rej(err); - else - res(JSON.parse(body)); - })); + const { login, id } = await getJson('https://api.github.com/user', 'application/vnd.github.v3+json', 10 * 1000, { + 'Authorization': `bearer ${accessToken}` + }); if (!login || !id) { ctx.throw(400, 'invalid session'); -- cgit v1.2.3-freya