Use node-fetch instead of request (#6228)

* requestをnode-fetchになど

* format

* fix error

* t

* Fix test
This commit is contained in:
MeiMei
2020-04-09 23:42:23 +09:00
committed by GitHub
parent bb7edfee04
commit d3c0f3c251
12 changed files with 140 additions and 218 deletions

View File

@@ -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';
@@ -174,20 +174,9 @@ router.get('/dc/cb', async ctx => {
}
}));
const { id, username, discriminator } = await new Promise<any>((res, rej) =>
request({
url: 'https://discordapp.com/api/users/@me',
headers: {
'Authorization': `Bearer ${accessToken}`,
'User-Agent': config.userAgent
}
}, (err, response, body) => {
if (err) {
rej(err);
} else {
res(JSON.parse(body));
}
}));
const { id, username, discriminator } = await getJson('https://discordapp.com/api/users/@me', '*/*', 10 * 1000, {
'Authorization': `Bearer ${accessToken}`,
});
if (!id || !username || !discriminator) {
ctx.throw(400, 'invalid session');
@@ -256,21 +245,9 @@ router.get('/dc/cb', async ctx => {
}
}));
const { id, username, discriminator } = await new Promise<any>((res, rej) =>
request({
url: 'https://discordapp.com/api/users/@me',
headers: {
'Authorization': `Bearer ${accessToken}`,
'User-Agent': config.userAgent
}
}, (err, response, body) => {
if (err) {
rej(err);
} else {
res(JSON.parse(body));
}
}));
const { id, username, discriminator } = await getJson('https://discordapp.com/api/users/@me', '*/*', 10 * 1000, {
'Authorization': `Bearer ${accessToken}`,
});
if (!id || !username || !discriminator) {
ctx.throw(400, 'invalid session');
return;