summaryrefslogtreecommitdiff
path: root/src/services/fetch-nodeinfo.ts
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/services/fetch-nodeinfo.ts
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/services/fetch-nodeinfo.ts')
-rw-r--r--src/services/fetch-nodeinfo.ts45
1 files changed, 13 insertions, 32 deletions
diff --git a/src/services/fetch-nodeinfo.ts b/src/services/fetch-nodeinfo.ts
index e5d652a6b3..0cf51e3377 100644
--- a/src/services/fetch-nodeinfo.ts
+++ b/src/services/fetch-nodeinfo.ts
@@ -1,7 +1,6 @@
-import * as request from 'request-promise-native';
+import { getJson } from '../misc/fetch';
import { Instance } from '../models/entities/instance';
import { Instances } from '../models';
-import config from '../config';
import { getNodeinfoLock } from '../misc/app-lock';
import Logger from '../services/logger';
@@ -20,23 +19,14 @@ export async function fetchNodeinfo(instance: Instance) {
logger.info(`Fetching nodeinfo of ${instance.host} ...`);
try {
- const wellknown = await request({
- url: 'https://' + instance.host + '/.well-known/nodeinfo',
- proxy: config.proxy,
- timeout: 1000 * 10,
- forever: true,
- headers: {
- 'User-Agent': config.userAgent,
- Accept: 'application/json, */*'
- },
- json: true
- }).catch(e => {
- if (e.statusCode === 404) {
- throw 'No nodeinfo provided';
- } else {
- throw e.statusCode || e.message;
- }
- });
+ const wellknown = await getJson('https://' + instance.host + '/.well-known/nodeinfo')
+ .catch(e => {
+ if (e.statusCode === 404) {
+ throw 'No nodeinfo provided';
+ } else {
+ throw e.statusCode || e.message;
+ }
+ });
if (wellknown.links == null || !Array.isArray(wellknown.links)) {
throw 'No wellknown links';
@@ -53,19 +43,10 @@ export async function fetchNodeinfo(instance: Instance) {
throw 'No nodeinfo link provided';
}
- const info = await request({
- url: link.href,
- proxy: config.proxy,
- timeout: 1000 * 10,
- forever: true,
- headers: {
- 'User-Agent': config.userAgent,
- Accept: 'application/json, */*'
- },
- json: true
- }).catch(e => {
- throw e.statusCode || e.message;
- });
+ const info = await getJson(link.href)
+ .catch(e => {
+ throw e.statusCode || e.message;
+ });
await Instances.update(instance.id, {
infoUpdatedAt: new Date(),