fix(core): update
This commit is contained in:
@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@apiclient.xyz/abuse.ch',
|
||||
version: '1.0.6',
|
||||
version: '1.0.7',
|
||||
description: 'an unofficial client to retrieve abuse.ch data'
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
import * as plugins from './plugins.js';
|
||||
import * as paths from './paths.js';
|
||||
import axios from 'axios';
|
||||
import * as helpers from './helpers.js';
|
||||
|
||||
export interface IThreatFoxData {
|
||||
ID: string;
|
||||
@ -21,13 +21,23 @@ export class ThreatFox {
|
||||
const zipPath = plugins.path.join(paths.threatFoxTmp, 'threatfox.zip');
|
||||
const csvPath = plugins.path.join(paths.threatFoxTmp, 'full.csv');
|
||||
|
||||
const response = await axios.get(ThreatFox.THREATFOX_API_URL, { responseType: 'stream' });
|
||||
|
||||
const response = await plugins.nodeFetch(ThreatFox.THREATFOX_API_URL, {
|
||||
...(helpers.findProxy() ? {
|
||||
agent: helpers.getAgent(),
|
||||
} : {})
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
|
||||
await new Promise((resolve, reject) => {
|
||||
const fileStream = plugins.fs.createWriteStream(zipPath);
|
||||
response.data.pipe(fileStream);
|
||||
fileStream.on('finish', resolve);
|
||||
fileStream.on('error', reject);
|
||||
// @ts-ignore
|
||||
const readable = plugins.stream.Readable.from(response.body);
|
||||
plugins.stream.pipeline(readable, fileStream, (err) => {
|
||||
if (err) reject(err);
|
||||
else resolve(null);
|
||||
});
|
||||
});
|
||||
|
||||
await new Promise((resolve, reject) => {
|
||||
|
@ -1,6 +1,6 @@
|
||||
import * as plugins from './plugins.js';
|
||||
import * as paths from './paths.js';
|
||||
import axios from 'axios';
|
||||
import * as helpers from './helpers.js';
|
||||
|
||||
export interface IUrlHouseData {
|
||||
ID: string;
|
||||
@ -21,13 +21,23 @@ export class UrlHouse {
|
||||
const zipPath = plugins.path.join(paths.urlHouseTmp, 'urlhaus.zip');
|
||||
const csvPath = plugins.path.join(paths.urlHouseTmp, 'csv.txt');
|
||||
|
||||
const response = await axios.get(UrlHouse.URLHOUSE_API_URL, { responseType: 'stream' });
|
||||
const response = await plugins.nodeFetch(UrlHouse.URLHOUSE_API_URL, {
|
||||
...(helpers.findProxy() ? {
|
||||
agent: helpers.getAgent(),
|
||||
} : {})
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
|
||||
await new Promise((resolve, reject) => {
|
||||
const fileStream = plugins.fs.createWriteStream(zipPath);
|
||||
response.data.pipe(fileStream);
|
||||
fileStream.on('finish', resolve);
|
||||
fileStream.on('error', reject);
|
||||
// @ts-ignore
|
||||
const readable = plugins.stream.Readable.from(response.body);
|
||||
plugins.stream.pipeline(readable, fileStream, (err) => {
|
||||
if (err) reject(err);
|
||||
else resolve(null);
|
||||
});
|
||||
});
|
||||
|
||||
await new Promise((resolve, reject) => {
|
||||
|
8
ts/helpers.ts
Normal file
8
ts/helpers.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import * as plugins from './plugins.js';
|
||||
|
||||
export const findProxy = () => {
|
||||
return process.env.HTTPS_PROXY || process.env.https_proxy || process.env.HTTP_PROXY || process.env.http_proxy
|
||||
}
|
||||
export const getAgent = () => {
|
||||
return new plugins.httpsProxy.HttpsProxyAgent(findProxy());
|
||||
}
|
@ -22,4 +22,13 @@ import * as smartpath from '@push.rocks/smartpath';
|
||||
export {
|
||||
smartfile,
|
||||
smartpath,
|
||||
}
|
||||
|
||||
// third party
|
||||
import nodeFetch from 'node-fetch';
|
||||
import * as httpsProxy from 'https-proxy-agent';
|
||||
|
||||
export {
|
||||
nodeFetch,
|
||||
httpsProxy,
|
||||
}
|
Reference in New Issue
Block a user