Use node-fetch instead of request (#6228)
* requestをnode-fetchになど * format * fix error * t * Fix test
This commit is contained in:
parent
bb7edfee04
commit
d3c0f3c251
12 changed files with 140 additions and 218 deletions
|
@ -1,32 +1,17 @@
|
|||
import * as S3 from 'aws-sdk/clients/s3';
|
||||
import config from '../../config';
|
||||
import { Meta } from '../../models/entities/meta';
|
||||
import { HttpsProxyAgent } from 'https-proxy-agent';
|
||||
import * as agentkeepalive from 'agentkeepalive';
|
||||
|
||||
const httpsAgent = config.proxy
|
||||
? new HttpsProxyAgent(config.proxy)
|
||||
: new agentkeepalive.HttpsAgent({
|
||||
freeSocketTimeout: 30 * 1000
|
||||
});
|
||||
import { httpsAgent, httpAgent } from '../../misc/fetch';
|
||||
|
||||
export function getS3(meta: Meta) {
|
||||
const conf = {
|
||||
return new S3({
|
||||
endpoint: meta.objectStorageEndpoint || undefined,
|
||||
accessKeyId: meta.objectStorageAccessKey,
|
||||
secretAccessKey: meta.objectStorageSecretKey,
|
||||
accessKeyId: meta.objectStorageAccessKey!,
|
||||
secretAccessKey: meta.objectStorageSecretKey!,
|
||||
region: meta.objectStorageRegion || undefined,
|
||||
sslEnabled: meta.objectStorageUseSSL,
|
||||
s3ForcePathStyle: !!meta.objectStorageEndpoint,
|
||||
httpOptions: {
|
||||
agent: meta.objectStorageUseSSL ? httpsAgent : httpAgent
|
||||
}
|
||||
} as S3.ClientConfiguration;
|
||||
|
||||
if (meta.objectStorageUseSSL) {
|
||||
conf.httpOptions!.agent = httpsAgent;
|
||||
}
|
||||
|
||||
const s3 = new S3(conf);
|
||||
|
||||
return s3;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue