From 995f992d7cb8c25e991ad2f797cdb2a15eb64dd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=93=E5=AE=B9=20=28hyj1991=29?= Date: Wed, 11 Dec 2024 12:10:59 +0800 Subject: [PATCH] feat: rollback for removing third-party dependencies (#61) --- .autod.conf.js | 2 ++ common/utils.js | 22 ++-------------------- package.json | 1 + test/fixtures/files/package-lock.json | 17 +++++++++++++++++ test/fixtures/files/package.json | 2 ++ test/fixtures/files/test_error | 0 6 files changed, 24 insertions(+), 20 deletions(-) delete mode 100644 test/fixtures/files/test_error diff --git a/.autod.conf.js b/.autod.conf.js index 250a499..c5861d4 100644 --- a/.autod.conf.js +++ b/.autod.conf.js @@ -7,6 +7,8 @@ module.exports = { 'test', ], dep: [ + 'address', + 'formstream', 'moment', 'nounou', 'p-map', diff --git a/common/utils.js b/common/utils.js index 4106516..bd15437 100644 --- a/common/utils.js +++ b/common/utils.js @@ -1,29 +1,11 @@ 'use strict'; const os = require('os'); +const address = require('address'); const crypto = require('crypto'); const { promisify } = require('util'); const path = require('path'); -exports.getIp = function getIp() { - const interfaces = os.networkInterfaces(); - for (const interfaceItems of Object.values(interfaces)) { - for (const item of interfaceItems) { - // skip local network ip - if (item.address.startsWith('10.') || - item.address.startsWith('172.16.') || - item.address.startsWith('192.168.') || - item.address.startsWith('169.254.')) { - continue; - } - if (item.family === 'IPv4' && !item.internal) { - return item.address; - } - } - } - return '127.0.0.1'; -}; - exports.regularWsServer = function(server) { return server.startsWith('ws://') || server.startsWith('wss://'); }; @@ -40,7 +22,7 @@ exports.getAgentId = function(customAgent, ipMode) { if (!ipMode) { return `${os.hostname()}`; } - return `${exports.getIp()}::${os.hostname()}`; + return `${address.ip()}::${os.hostname()}`; }; exports.sign = function(message, secret) { diff --git a/package.json b/package.json index cbbd467..12aff90 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,7 @@ }, "homepage": "https://github.com/X-Profiler/xtransit#readme", "dependencies": { + "address": "^1.1.2", "form-data": "^4.0.0", "moment": "^2.28.0", "nounou": "^1.2.1", diff --git a/test/fixtures/files/package-lock.json b/test/fixtures/files/package-lock.json index d3e0f4a..c381cb3 100644 --- a/test/fixtures/files/package-lock.json +++ b/test/fixtures/files/package-lock.json @@ -551,6 +551,11 @@ "integrity": "sha1-KUrbcbVzmLBoABXwo4xWPuHbU4Q=", "dev": true }, + "address": { + "version": "1.1.2", + "resolved": "https://registry.npm.taobao.org/address/download/address-1.1.2.tgz", + "integrity": "sha1-vxEWycdYxRt6kz0pa3LCIe2UKLY=" + }, "agent-base": { "version": "4.3.0", "resolved": "https://registry.npm.taobao.org/agent-base/download/agent-base-4.3.0.tgz?cache=0&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fagent-base%2Fdownload%2Fagent-base-4.3.0.tgz", @@ -2536,6 +2541,7 @@ "resolved": "https://registry.npm.taobao.org/utility/download/utility-0.1.11.tgz?cache=0&sync_timestamp=1574243892588&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Futility%2Fdownload%2Futility-0.1.11.tgz", "integrity": "sha1-/eYM+bTkdRlHoM9dEEzik2ciZxU=", "requires": { + "address": ">=0.0.1" } } } @@ -3252,6 +3258,16 @@ } } }, + "formstream": { + "version": "1.1.0", + "resolved": "https://registry.npm.taobao.org/formstream/download/formstream-1.1.0.tgz", + "integrity": "sha1-UfOXDyYTbrCtRDBN5M67UCB7RHk=", + "requires": { + "destroy": "^1.0.4", + "mime": "^1.3.4", + "pause-stream": "~0.0.11" + } + }, "fromentries": { "version": "1.2.0", "resolved": "https://registry.npm.taobao.org/fromentries/download/fromentries-1.2.0.tgz", @@ -6309,6 +6325,7 @@ "default-user-agent": "^1.0.0", "digest-header": "^0.0.1", "ee-first": "~1.1.1", + "formstream": "^1.1.0", "humanize-ms": "^1.2.0", "iconv-lite": "^0.4.15", "ip": "^1.1.5", diff --git a/test/fixtures/files/package.json b/test/fixtures/files/package.json index 0a755f3..b059fcd 100644 --- a/test/fixtures/files/package.json +++ b/test/fixtures/files/package.json @@ -40,6 +40,8 @@ }, "homepage": "https://github.com/X-Profiler/xtransit#readme", "dependencies": { + "address": "^1.1.2", + "formstream": "^1.1.0", "moment": "^2.26.0", "nounou": "^1.2.1", "p-map": "^4.0.0", diff --git a/test/fixtures/files/test_error b/test/fixtures/files/test_error deleted file mode 100644 index e69de29..0000000