mirror of
https://github.com/misskey-dev/misskey.git
synced 2026-05-02 17:55:52 +02:00
Use node-fetch instead of request (#6228)
* requestをnode-fetchになど * format * fix error * t * Fix test
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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<any>((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<any>((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');
|
||||
|
||||
Reference in New Issue
Block a user