nodejs-argo 2.0.2 → 2.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +26 -17
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -12,7 +12,7 @@ const { execSync } = require('child_process'); // 只填写UPLOAD_URL将
|
|
|
12
12
|
const UPLOAD_URL = process.env.UPLOAD_URL || ''; // 节点或订阅自动上传地址,需填写部署Merge-sub项目后的首页地址,例如:https://merge.xxx.com
|
|
13
13
|
const PROJECT_URL = process.env.PROJECT_URL || ''; // 需要上传订阅或保活时需填写项目分配的url,例如:https://google.com
|
|
14
14
|
const AUTO_ACCESS = process.env.AUTO_ACCESS || false; // false关闭自动保活,true开启,需同时填写PROJECT_URL变量
|
|
15
|
-
const FILE_PATH = process.env.FILE_PATH || '
|
|
15
|
+
const FILE_PATH = process.env.FILE_PATH || '.npm'; // 运行目录,sub节点文件保存目录
|
|
16
16
|
const SUB_PATH = process.env.SUB_PATH || 'sub'; // 订阅路径
|
|
17
17
|
const PORT = process.env.SERVER_PORT || process.env.PORT || 3000; // http服务订阅端口
|
|
18
18
|
const UUID = process.env.UUID || '9afd1229-b893-40c1-84dd-51e7ce204913'; // 使用哪吒v1,在不同的平台运行需修改UUID,否则会覆盖
|
|
@@ -112,11 +112,6 @@ function cleanupOldFiles() {
|
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
-
// 根路由
|
|
116
|
-
app.get("/", function(req, res) {
|
|
117
|
-
res.send("Hello world!");
|
|
118
|
-
});
|
|
119
|
-
|
|
120
115
|
// 生成xr-ay配置文件
|
|
121
116
|
async function generateConfig() {
|
|
122
117
|
const config = {
|
|
@@ -383,7 +378,7 @@ function argoType() {
|
|
|
383
378
|
`;
|
|
384
379
|
fs.writeFileSync(path.join(FILE_PATH, 'tunnel.yml'), tunnelYaml);
|
|
385
380
|
} else {
|
|
386
|
-
console.log(
|
|
381
|
+
console.log(`Using token connect to tunnel,please set ${ARGO_PORT} in cloudflare tunnel`);
|
|
387
382
|
}
|
|
388
383
|
}
|
|
389
384
|
argoType();
|
|
@@ -449,9 +444,8 @@ async function extractDomains() {
|
|
|
449
444
|
// 生成 list 和 sub 信息
|
|
450
445
|
async function generateLinks(argoDomain) {
|
|
451
446
|
let ISP = 'Unknown';
|
|
452
|
-
|
|
453
447
|
try {
|
|
454
|
-
const response = await axios.get('https://
|
|
448
|
+
const response = await axios.get('https://api.ip.sb/geoip', {
|
|
455
449
|
timeout: 5000,
|
|
456
450
|
headers: {
|
|
457
451
|
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'
|
|
@@ -460,19 +454,23 @@ async function extractDomains() {
|
|
|
460
454
|
|
|
461
455
|
if (response.data) {
|
|
462
456
|
const data = typeof response.data === 'string' ? JSON.parse(response.data) : response.data;
|
|
463
|
-
if (data.
|
|
464
|
-
ISP = `${data.
|
|
457
|
+
if (data.country_code && data.isp) {
|
|
458
|
+
ISP = `${data.country_code}-${data.isp}`.replace(/\s+/g, '_');
|
|
465
459
|
} else {
|
|
466
|
-
ISP = data.
|
|
460
|
+
ISP = data.country_code || data.isp;
|
|
467
461
|
}
|
|
468
462
|
}
|
|
469
463
|
} catch (err) {
|
|
470
464
|
try {
|
|
471
|
-
const
|
|
472
|
-
|
|
473
|
-
{
|
|
474
|
-
);
|
|
475
|
-
|
|
465
|
+
const response2 = await axios.get('http://ip-api.com/json', {
|
|
466
|
+
timeout: 3000,
|
|
467
|
+
headers: { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36' }
|
|
468
|
+
});
|
|
469
|
+
if (response2.data && response2.data.status === 'success' && response2.data.countryCode && response2.data.org) {
|
|
470
|
+
ISP = `${response2.data.countryCode}_${response2.data.org}`.replace(/\s+/g, '_');
|
|
471
|
+
} else {
|
|
472
|
+
ISP = 'Unknown';
|
|
473
|
+
}
|
|
476
474
|
} catch (execErr) {
|
|
477
475
|
ISP = 'Unknown';
|
|
478
476
|
}
|
|
@@ -633,4 +631,15 @@ startserver().catch(error => {
|
|
|
633
631
|
console.error('Unhandled error in startserver:', error);
|
|
634
632
|
});
|
|
635
633
|
|
|
634
|
+
// 根路由
|
|
635
|
+
app.get("/", async function(req, res) {
|
|
636
|
+
try {
|
|
637
|
+
const filePath = path.join(__dirname, 'index.html');
|
|
638
|
+
const data = await fs.promises.readFile(filePath, 'utf8');
|
|
639
|
+
res.send(data);
|
|
640
|
+
} catch (err) {
|
|
641
|
+
res.send("Hello world!<br><br>You can visit /{SUB_PATH}(Default: /sub) get your nodes!");
|
|
642
|
+
}
|
|
643
|
+
});
|
|
644
|
+
|
|
636
645
|
app.listen(PORT, () => console.log(`http server is running on port:${PORT}!`));
|