fix(core): update

This commit is contained in:
2023-07-28 14:13:16 +02:00
parent 0517f95d25
commit 792224c96b
7 changed files with 116 additions and 36 deletions

View File

@ -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'
}

View File

@ -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) => {

View File

@ -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
View 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());
}

View File

@ -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,
}