From 0433b2b19bebd250e3154dd64ae996d091590afa Mon Sep 17 00:00:00 2001 From: Sefinek Date: Fri, 22 Nov 2024 21:36:46 +0100 Subject: [PATCH] services/axios.js --- index.js | 2 +- scripts/cloudflare.js | 2 +- scripts/services/axios.js | 16 ++++++++++++++++ utils/processUrls.js | 3 ++- 4 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 scripts/services/axios.js diff --git a/index.js b/index.js index 4927188..8a3e558 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,4 @@ -const axios = require('axios'); +const axios = require('./scripts/services/axios.js'); const fs = require('node:fs'); const path = require('node:path'); const { parse } = require('csv-parse/sync'); diff --git a/scripts/cloudflare.js b/scripts/cloudflare.js index f200213..a162e57 100644 --- a/scripts/cloudflare.js +++ b/scripts/cloudflare.js @@ -1,4 +1,4 @@ -const axios = require('axios'); +const axios = require('../scripts/services/axios.js'); const fs = require('node:fs'); const path = require('node:path'); diff --git a/scripts/services/axios.js b/scripts/services/axios.js new file mode 100644 index 0000000..7b1deb9 --- /dev/null +++ b/scripts/services/axios.js @@ -0,0 +1,16 @@ +const axios = require('axios'); +const { name, version } = require('../../package.json'); + +axios.defaults.headers.common = { + 'User-Agent': `Mozilla/5.0 (compatible; ${name}/${version}; +https://github.com/sefinek/Malicious-IP-Addresses)`, + 'Accept': 'application/json', + 'Content-Type': 'application/json', + 'Accept-Encoding': 'gzip, deflate, br', + 'Accept-Language': 'pl;q=0.9', + 'Cache-Control': 'no-cache', + 'Connection': 'keep-alive', +}; + +axios.defaults.timeout = 8000; + +module.exports = axios; \ No newline at end of file diff --git a/utils/processUrls.js b/utils/processUrls.js index a299188..54d11f2 100644 --- a/utils/processUrls.js +++ b/utils/processUrls.js @@ -1,4 +1,4 @@ -const axios = require('axios'); +const axios = require('../scripts/services/axios.js'); const fs = require('node:fs'); const path = require('node:path'); @@ -8,6 +8,7 @@ module.exports = async (urls, filePath) => { const content = responses.map(({ data }, index) => `# ${urls[index]}\n${data.prefixes.map(prefix => prefix.ipv4Prefix || prefix.ipv6Prefix).join('\n')}` ).join('\n\n'); + fs.mkdirSync(path.dirname(filePath), { recursive: true }); fs.writeFileSync(filePath, content, 'utf-8'); } catch (err) {