summaryrefslogtreecommitdiff
path: root/src/server
diff options
context:
space:
mode:
authorMeiMei <30769358+mei23@users.noreply.github.com>2020-04-09 23:42:23 +0900
committerGitHub <noreply@github.com>2020-04-09 23:42:23 +0900
commitd3c0f3c251e8371d78d953f32f7311a38f4a1bdb (patch)
treeef746ec79b4cc53ad15da2680b2e5d6280d39867 /src/server
parentCreate aiscript.ja-JP.md (diff)
downloadsharkey-d3c0f3c251e8371d78d953f32f7311a38f4a1bdb.tar.gz
sharkey-d3c0f3c251e8371d78d953f32f7311a38f4a1bdb.tar.bz2
sharkey-d3c0f3c251e8371d78d953f32f7311a38f4a1bdb.zip
Use node-fetch instead of request (#6228)
* requestをnode-fetchになど * format * fix error * t * Fix test
Diffstat (limited to 'src/server')
-rw-r--r--src/server/api/service/discord.ts37
-rw-r--r--src/server/api/service/github.ts37
-rw-r--r--src/server/web/url-preview.ts15
3 files changed, 19 insertions, 70 deletions
diff --git a/src/server/api/service/discord.ts b/src/server/api/service/discord.ts
index c2bb02453b..a5ad18d99c 100644
--- a/src/server/api/service/discord.ts
+++ b/src/server/api/service/discord.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';
@@ -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;
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<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');
diff --git a/src/server/web/url-preview.ts b/src/server/web/url-preview.ts
index 2526ed0f83..4dae6baafb 100644
--- a/src/server/web/url-preview.ts
+++ b/src/server/web/url-preview.ts
@@ -1,10 +1,10 @@
import * as Koa from 'koa';
-import * as request from 'request-promise-native';
import summaly from 'summaly';
import { fetchMeta } from '../../misc/fetch-meta';
import Logger from '../../services/logger';
import config from '../../config';
import { query } from '../../prelude/url';
+import { getJson } from '../../misc/fetch';
const logger = new Logger('url-preview');
@@ -16,15 +16,10 @@ module.exports = async (ctx: Koa.Context) => {
: `Getting preview of ${ctx.query.url}@${ctx.query.lang} ...`);
try {
- const summary = meta.summalyProxy ? await request.get({
- url: meta.summalyProxy,
- qs: {
- url: ctx.query.url,
- lang: ctx.query.lang || 'ja-JP'
- },
- forever: true,
- json: true
- }) : await summaly(ctx.query.url, {
+ const summary = meta.summalyProxy ? await getJson(`${meta.summalyProxy}?${query({
+ url: ctx.query.url,
+ lang: ctx.query.lang || 'ja-JP'
+ })}`) : await summaly(ctx.query.url, {
followRedirects: false,
lang: ctx.query.lang || 'ja-JP'
});