tt-help-cli-ycl 1.3.33 → 1.3.34

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.
Files changed (59) hide show
  1. package/README.md +17 -17
  2. package/cli.js +9 -9
  3. package/package.json +47 -47
  4. package/scripts/run-explore copy.bat +101 -101
  5. package/scripts/run-explore.bat +132 -127
  6. package/scripts/run-explore.ps1 +157 -153
  7. package/scripts/run-explore.sh +119 -113
  8. package/src/cli/attach.js +180 -180
  9. package/src/cli/auto.js +240 -240
  10. package/src/cli/config.js +152 -152
  11. package/src/cli/explore.js +488 -481
  12. package/src/cli/info.js +88 -88
  13. package/src/cli/open.js +111 -111
  14. package/src/cli/progress.js +111 -111
  15. package/src/cli/refresh.js +216 -216
  16. package/src/cli/scrape.js +47 -47
  17. package/src/cli/utils.js +18 -18
  18. package/src/cli/videos.js +41 -41
  19. package/src/cli/watch.js +31 -31
  20. package/src/lib/api-interceptor.js +43 -202
  21. package/src/lib/args.js +722 -722
  22. package/src/lib/browser/anti-detect.js +23 -23
  23. package/src/lib/browser/cdp.js +261 -261
  24. package/src/lib/browser/health-checker.js +114 -114
  25. package/src/lib/browser/launch.js +43 -43
  26. package/src/lib/browser/page.js +183 -183
  27. package/src/lib/constants.js +216 -213
  28. package/src/lib/delay.js +54 -54
  29. package/src/lib/explore-fetch.js +118 -118
  30. package/src/lib/fetcher.js +45 -45
  31. package/src/lib/filter.js +66 -66
  32. package/src/lib/io.js +54 -54
  33. package/src/lib/output.js +80 -80
  34. package/src/lib/page-error-detector.js +105 -105
  35. package/src/lib/parse-ssr.mjs +69 -69
  36. package/src/lib/parser.js +47 -47
  37. package/src/lib/retry.js +45 -45
  38. package/src/lib/scrape.js +89 -89
  39. package/src/lib/tiktok-scraper.mjs +194 -194
  40. package/src/lib/url.js +52 -52
  41. package/src/main.js +48 -48
  42. package/src/scraper/auto-core.js +203 -203
  43. package/src/scraper/core.js +211 -211
  44. package/src/scraper/explore-core.js +167 -167
  45. package/src/scraper/modules/captcha-handler.js +114 -114
  46. package/src/scraper/modules/follow-extractor.js +194 -194
  47. package/src/scraper/modules/guess-extractor.js +51 -51
  48. package/src/scraper/modules/page-helpers.js +48 -48
  49. package/src/scraper/refresh-core.js +179 -179
  50. package/src/videos/core.js +125 -125
  51. package/src/watch/data-store.js +1030 -1030
  52. package/src/watch/public/index.html +753 -753
  53. package/src/watch/server.js +933 -933
  54. package/scripts/test-captcha-lib.mjs +0 -68
  55. package/scripts/test-captcha.mjs +0 -81
  56. package/scripts/test-incognito-lib.mjs +0 -36
  57. package/scripts/test-login-state.mjs +0 -128
  58. package/scripts/test-safe-click.mjs +0 -45
  59. package/src/results/user-videos-bar.lar.lar.moeta.json +0 -37
@@ -1,153 +1,157 @@
1
- $packageName = "tt-help-cli-ycl"
2
- $configPath = Join-Path $env:USERPROFILE ".tt-help.json"
3
-
4
- Write-Host "========================================"
5
- Write-Host " tt-help-cli-ycl 一键启动脚本 (Windows)"
6
- Write-Host "========================================"
7
-
8
- # ---------- 0. 根据本机 IP 自动选择 server ----------
9
- $localIp = $null
10
- try {
11
- $localIp = Get-WmiObject Win32_NetworkAdapterConfiguration |
12
- Where-Object { $_.IPEnabled -eq $true } |
13
- ForEach-Object { $_.IPAddress } |
14
- Where-Object {
15
- $_ -match '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$' -and
16
- $_ -ne '127.0.0.1' -and
17
- $_ -notlike '169.254.*'
18
- } |
19
- Select-Object -First 1
20
- } catch {
21
- }
22
- if (-not $localIp) {
23
- try {
24
- $localIp = Get-NetIPAddress -AddressFamily IPv4 -ErrorAction Stop |
25
- Where-Object { $_.IPAddress -ne '127.0.0.1' -and $_.IPAddress -notlike '169.254.*' } |
26
- Select-Object -First 1 -ExpandProperty IPAddress
27
- } catch {
28
- }
29
- }
30
- if (-not $localIp) {
31
- try {
32
- $localIp = [System.Net.Dns]::GetHostAddresses([System.Net.Dns]::GetHostName()) |
33
- Where-Object {
34
- $_.AddressFamily -eq [System.Net.Sockets.AddressFamily]::InterNetwork -and
35
- $_.IPAddressToString -ne '127.0.0.1' -and
36
- $_.IPAddressToString -notlike '169.254.*'
37
- } |
38
- Select-Object -First 1 -ExpandProperty IPAddressToString
39
- } catch {
40
- }
41
- }
42
- Write-Host "[提示] 本机 IP: $(if ($localIp) { $localIp } else { '未检测到' })"
43
- if ($localIp -and $localIp -match '^172\.18\.154\.') {
44
- $targetServer = "http://172.18.154.201:3001"
45
- Write-Host "[提示] 检测到内网 IP: $localIp,使用内网 server"
46
- } else {
47
- $targetServer = "http://117.71.53.99:17301"
48
- Write-Host "[提示] 未检测到内网 IP,使用公网 server"
49
- }
50
-
51
- # ---------- 1. 检查/安装最新版本 ----------
52
- $latestVersion = npm view $packageName version 2>$null
53
-
54
- if (-not $latestVersion) {
55
- Write-Host "[错误] 无法从 npm 获取最新版本信息"
56
- exit 1
57
- }
58
-
59
- $installedVersion = ""
60
- $output = npm list -g $packageName --depth=0 2>$null
61
- if ($output -match "$packageName@([\d.]+)") {
62
- $installedVersion = $matches[1]
63
- }
64
-
65
- if (-not $installedVersion) {
66
- Write-Host "[提示] tt-help-cli-ycl 未安装,正在安装最新版本..."
67
- npm install -g $packageName 2>$null
68
- if ($LASTEXITCODE -eq 0) {
69
- Write-Host "[OK] 安装完成: $latestVersion"
70
- } else {
71
- Write-Host "[错误] 安装失败,请手动执行: npm install -g $packageName"
72
- exit 1
73
- }
74
- } elseif ($installedVersion -eq $latestVersion) {
75
- Write-Host "[OK] tt-help-cli-ycl 已是最新版本: $latestVersion"
76
- } else {
77
- Write-Host "[提示] 当前版本: $installedVersion, 最新版本: $latestVersion"
78
- Write-Host "[执行] 正在升级最新版本..."
79
- npm install -g $packageName 2>$null
80
- if ($LASTEXITCODE -eq 0) {
81
- Write-Host "[OK] 升级完成: $latestVersion"
82
- } else {
83
- Write-Host "[警告] 升级失败,请手动执行: npm install -g $packageName"
84
- }
85
- }
86
-
87
- # ---------- 2. 检查/设置 server 配置 ----------
88
- $currentServer = ""
89
- if (Test-Path $configPath) {
90
- try {
91
- $config = Get-Content $configPath -Raw | ConvertFrom-Json
92
- $currentServer = $config.server
93
- } catch {
94
- $currentServer = ""
95
- }
96
- }
97
-
98
- if ($currentServer -eq $targetServer) {
99
- Write-Host "[OK] Server 配置正确: $targetServer"
100
- } else {
101
- $currentDisplay = if ($currentServer) { $currentServer } else { "未设置" }
102
- Write-Host "[提示] 当前 server: $currentDisplay, 目标: $targetServer"
103
- Write-Host "[执行] 正在设置 server 配置..."
104
-
105
- node -e "
106
- const fs = require('fs');
107
- const path = require('path');
108
- const configPath = path.join(require('os').homedir(), '.tt-help.json');
109
- let cfg = {};
110
- try { cfg = JSON.parse(fs.readFileSync(configPath, 'utf-8')); } catch(e) {}
111
- cfg.server = '$targetServer';
112
- fs.writeFileSync(configPath, JSON.stringify(cfg, null, 2), 'utf-8');
113
- console.log(' 已写入: ' + configPath);
114
- "
115
- Write-Host "[OK] Server 配置已设置"
116
- }
117
-
118
- # ---------- 3. 询问用户参数 ----------
119
- Write-Host ""
120
- Write-Host "========================================"
121
- Write-Host " 参数配置"
122
- Write-Host "========================================"
123
-
124
- $inputBasePort = Read-Host "起始端口 (--base-port) [默认: 9222]"
125
- $basePort = if ($inputBasePort) { $inputBasePort } else { "9222" }
126
-
127
- $inputPortCount = Read-Host "端口数量 (--port-count) [默认: 10]"
128
- $portCount = if ($inputPortCount) { $inputPortCount } else { "10" }
129
-
130
- # ---------- 4. 获取配置中的用户编号并拼接 ----------
131
- $configUserId = ""
132
- if (Test-Path $configPath) {
133
- try {
134
- $config = Get-Content $configPath -Raw | ConvertFrom-Json
135
- $configUserId = $config.userId
136
- } catch {
137
- $configUserId = ""
138
- }
139
- }
140
- if (-not $configUserId) { $configUserId = "user" }
141
- $userId = "${configUserId}_${basePort}_${portCount}"
142
-
143
- # ---------- 5. 启动 tt-help explore ----------
144
- Write-Host ""
145
- Write-Host "========================================"
146
- Write-Host " 启动 tt-help explore"
147
- Write-Host "========================================"
148
- Write-Host " 用户编号: $userId"
149
- Write-Host " 起始端口: $basePort"
150
- Write-Host " 端口数量: $portCount"
151
- Write-Host " 速度: stealth (最慢)"
152
- Write-Host "========================================"
153
- tt-help explore stealth --user-id $userId --base-port $basePort --port-count $portCount
1
+ $packageName = "tt-help-cli-ycl"
2
+ $configPath = Join-Path $env:USERPROFILE ".tt-help.json"
3
+
4
+ Write-Host "========================================"
5
+ Write-Host " tt-help-cli-ycl 一键启动脚本 (Windows)"
6
+ Write-Host "========================================"
7
+
8
+ # ---------- 0. 根据本机 IP 自动选择 server ----------
9
+ $localIp = $null
10
+ try {
11
+ $localIp = Get-WmiObject Win32_NetworkAdapterConfiguration |
12
+ Where-Object { $_.IPEnabled -eq $true } |
13
+ ForEach-Object { $_.IPAddress } |
14
+ Where-Object {
15
+ $_ -match '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$' -and
16
+ $_ -ne '127.0.0.1' -and
17
+ $_ -notlike '169.254.*'
18
+ } |
19
+ Select-Object -First 1
20
+ } catch {
21
+ }
22
+ if (-not $localIp) {
23
+ try {
24
+ $localIp = Get-NetIPAddress -AddressFamily IPv4 -ErrorAction Stop |
25
+ Where-Object { $_.IPAddress -ne '127.0.0.1' -and $_.IPAddress -notlike '169.254.*' } |
26
+ Select-Object -First 1 -ExpandProperty IPAddress
27
+ } catch {
28
+ }
29
+ }
30
+ if (-not $localIp) {
31
+ try {
32
+ $localIp = [System.Net.Dns]::GetHostAddresses([System.Net.Dns]::GetHostName()) |
33
+ Where-Object {
34
+ $_.AddressFamily -eq [System.Net.Sockets.AddressFamily]::InterNetwork -and
35
+ $_.IPAddressToString -ne '127.0.0.1' -and
36
+ $_.IPAddressToString -notlike '169.254.*'
37
+ } |
38
+ Select-Object -First 1 -ExpandProperty IPAddressToString
39
+ } catch {
40
+ }
41
+ }
42
+ Write-Host "[提示] 本机 IP: $(if ($localIp) { $localIp } else { '未检测到' })"
43
+ if ($localIp -and $localIp -match '^172\.18\.154\.') {
44
+ $targetServer = "http://172.18.154.201:3001"
45
+ Write-Host "[提示] 检测到内网 IP: $localIp,使用内网 server"
46
+ } else {
47
+ $targetServer = "http://117.71.53.99:17301"
48
+ Write-Host "[提示] 未检测到内网 IP,使用公网 server"
49
+ }
50
+
51
+ # ---------- 1. 检查/安装最新版本 ----------
52
+ $latestVersion = npm view $packageName version 2>$null
53
+
54
+ if (-not $latestVersion) {
55
+ Write-Host "[错误] 无法从 npm 获取最新版本信息"
56
+ exit 1
57
+ }
58
+
59
+ $installedVersion = ""
60
+ $output = npm list -g $packageName --depth=0 2>$null
61
+ if ($output -match "$packageName@([\d.]+)") {
62
+ $installedVersion = $matches[1]
63
+ }
64
+
65
+ if (-not $installedVersion) {
66
+ Write-Host "[提示] tt-help-cli-ycl 未安装,正在安装最新版本..."
67
+ npm install -g $packageName 2>$null
68
+ if ($LASTEXITCODE -eq 0) {
69
+ Write-Host "[OK] 安装完成: $latestVersion"
70
+ } else {
71
+ Write-Host "[错误] 安装失败,请手动执行: npm install -g $packageName"
72
+ exit 1
73
+ }
74
+ } elseif ($installedVersion -eq $latestVersion) {
75
+ Write-Host "[OK] tt-help-cli-ycl 已是最新版本: $latestVersion"
76
+ } else {
77
+ Write-Host "[提示] 当前版本: $installedVersion, 最新版本: $latestVersion"
78
+ Write-Host "[执行] 正在升级最新版本..."
79
+ npm install -g $packageName 2>$null
80
+ if ($LASTEXITCODE -eq 0) {
81
+ Write-Host "[OK] 升级完成: $latestVersion"
82
+ } else {
83
+ Write-Host "[警告] 升级失败,请手动执行: npm install -g $packageName"
84
+ }
85
+ }
86
+
87
+ # ---------- 2. 检查/设置 server 配置 ----------
88
+ $currentServer = ""
89
+ if (Test-Path $configPath) {
90
+ try {
91
+ $config = Get-Content $configPath -Raw | ConvertFrom-Json
92
+ $currentServer = $config.server
93
+ } catch {
94
+ $currentServer = ""
95
+ }
96
+ }
97
+
98
+ if ($currentServer -eq $targetServer) {
99
+ Write-Host "[OK] Server 配置正确: $targetServer"
100
+ } else {
101
+ $currentDisplay = if ($currentServer) { $currentServer } else { "未设置" }
102
+ Write-Host "[提示] 当前 server: $currentDisplay, 目标: $targetServer"
103
+ Write-Host "[执行] 正在设置 server 配置..."
104
+
105
+ node -e "
106
+ const fs = require('fs');
107
+ const path = require('path');
108
+ const configPath = path.join(require('os').homedir(), '.tt-help.json');
109
+ let cfg = {};
110
+ try { cfg = JSON.parse(fs.readFileSync(configPath, 'utf-8')); } catch(e) {}
111
+ cfg.server = '$targetServer';
112
+ fs.writeFileSync(configPath, JSON.stringify(cfg, null, 2), 'utf-8');
113
+ console.log(' 已写入: ' + configPath);
114
+ "
115
+ Write-Host "[OK] Server 配置已设置"
116
+ }
117
+
118
+ # ---------- 3. 询问用户参数 ----------
119
+ Write-Host ""
120
+ Write-Host "========================================"
121
+ Write-Host " 参数配置"
122
+ Write-Host "========================================"
123
+
124
+ $inputBasePort = Read-Host "起始端口 (--base-port) [默认: 9222]"
125
+ $basePort = if ($inputBasePort) { $inputBasePort } else { "9222" }
126
+
127
+ $inputPortCount = Read-Host "端口数量 (--port-count) [默认: 10]"
128
+ $portCount = if ($inputPortCount) { $inputPortCount } else { "10" }
129
+
130
+ $inputJobLocations = Read-Host "任务国家 (--job-locations) [默认: 无,使用全部]"
131
+ $jobLocationsArg = if ($inputJobLocations) { "--job-locations $inputJobLocations" } else { "" }
132
+
133
+ # ---------- 4. 获取配置中的用户编号并拼接 ----------
134
+ $configUserId = ""
135
+ if (Test-Path $configPath) {
136
+ try {
137
+ $config = Get-Content $configPath -Raw | ConvertFrom-Json
138
+ $configUserId = $config.userId
139
+ } catch {
140
+ $configUserId = ""
141
+ }
142
+ }
143
+ if (-not $configUserId) { $configUserId = "user" }
144
+ $userId = "${configUserId}_${basePort}_${portCount}"
145
+
146
+ # ---------- 5. 启动 tt-help explore ----------
147
+ Write-Host ""
148
+ Write-Host "========================================"
149
+ Write-Host " 启动 tt-help explore"
150
+ Write-Host "========================================"
151
+ Write-Host " 用户编号: $userId"
152
+ Write-Host " 起始端口: $basePort"
153
+ Write-Host " 端口数量: $portCount"
154
+ if ($inputJobLocations) { Write-Host " 任务国家: $inputJobLocations" }
155
+ Write-Host " 速度: stealth (最慢)"
156
+ Write-Host "========================================"
157
+ tt-help explore stealth --user-id $userId --base-port $basePort --port-count $portCount $jobLocationsArg
@@ -1,113 +1,119 @@
1
- #!/bin/bash
2
-
3
- PACKAGENAME="tt-help-cli-ycl"
4
- CONFIG_PATH="$HOME/.tt-help.json"
5
-
6
- echo "========================================"
7
- echo " tt-help-cli-ycl 一键启动脚本 (macOS)"
8
- echo "========================================"
9
-
10
- # ---------- 0. 根据本机 IP 自动选择 server ----------
11
- LOCAL_IP=$(ifconfig | awk '/inet / && $2 != "127.0.0.1" { print $2; exit }')
12
-
13
- echo "[提示] 本机 IP: ${LOCAL_IP:-未检测到}"
14
-
15
- if [[ "$LOCAL_IP" =~ ^172\.18\.154\.[0-9]+$ ]]; then
16
- TARGET_SERVER="http://172.18.154.201:3001"
17
- echo "[提示] 检测到内网 IP: $LOCAL_IP,使用内网 server"
18
- else
19
- TARGET_SERVER="http://117.71.53.99:17301"
20
- echo "[提示] 未检测到内网 IP,使用公网 server"
21
- fi
22
-
23
- # ---------- 1. 检查/安装最新版本 ----------
24
- LATEST_VERSION=$(npm view "$PACKAGENAME" version 2>/dev/null)
25
-
26
- if [ -z "$LATEST_VERSION" ]; then
27
- echo "[错误] 无法从 npm 获取最新版本信息"
28
- exit 1
29
- fi
30
-
31
- INSTALLED_VERSION=$(npm list -g "$PACKAGENAME" --depth=0 2>/dev/null | grep "$PACKAGENAME@" | head -1 | sed 's/.*@//' | sed 's/[) ].*//')
32
-
33
- if [ -z "$INSTALLED_VERSION" ]; then
34
- echo "[提示] tt-help-cli-ycl 未安装,正在安装最新版本..."
35
- npm install -g "$PACKAGENAME"
36
- if [ $? -eq 0 ]; then
37
- echo "[OK] 安装完成: $LATEST_VERSION"
38
- else
39
- echo "[错误] 安装失败,请手动执行: npm install -g $PACKAGENAME"
40
- exit 1
41
- fi
42
- elif [ "$INSTALLED_VERSION" = "$LATEST_VERSION" ]; then
43
- echo "[OK] tt-help-cli-ycl 已是最新版本: $LATEST_VERSION"
44
- else
45
- echo "[提示] 当前版本: $INSTALLED_VERSION, 最新版本: $LATEST_VERSION"
46
- echo "[执行] 正在升级最新版本..."
47
- npm install -g "$PACKAGENAME" 2>/dev/null
48
- if [ $? -eq 0 ]; then
49
- echo "[OK] 安装完成: $LATEST_VERSION"
50
- else
51
- echo "[警告] 自动安装失败,尝试手动更新..."
52
- npm update -g "$PACKAGENAME"
53
- fi
54
- fi
55
-
56
- # ---------- 2. 检查/设置 server 配置 ----------
57
- CURRENT_SERVER=""
58
- if [ -f "$CONFIG_PATH" ]; then
59
- CURRENT_SERVER=$(node -e "try{const c=JSON.parse(require('fs').readFileSync('$CONFIG_PATH','utf-8'));console.log(c.server||'')}catch(e){}" 2>/dev/null)
60
- fi
61
-
62
- if [ "$CURRENT_SERVER" = "$TARGET_SERVER" ]; then
63
- echo "[OK] Server 配置正确: $TARGET_SERVER"
64
- else
65
- echo "[提示] 当前 server: ${CURRENT_SERVER:-未设置}, 目标: $TARGET_SERVER"
66
- echo "[执行] 正在设置 server 配置..."
67
- node -e "
68
- const fs = require('fs');
69
- const path = require('path');
70
- const configPath = path.join(require('os').homedir(), '.tt-help.json');
71
- let cfg = {};
72
- try { cfg = JSON.parse(fs.readFileSync(configPath, 'utf-8')); } catch(e) {}
73
- cfg.server = '$TARGET_SERVER';
74
- fs.writeFileSync(configPath, JSON.stringify(cfg, null, 2), 'utf-8');
75
- console.log(' 已写入: ' + configPath);
76
- "
77
- echo "[OK] Server 配置已设置"
78
- fi
79
-
80
- # ---------- 3. 询问用户参数 ----------
81
- echo ""
82
- echo "========================================"
83
- echo " 参数配置"
84
- echo "========================================"
85
-
86
- printf "起始端口 (--base-port) [默认: 9222]: "
87
- read INPUT_BASE_PORT
88
- BASE_PORT="${INPUT_BASE_PORT:-9222}"
89
-
90
- printf "端口数量 (--port-count) [默认: 10]: "
91
- read INPUT_PORT_COUNT
92
- PORT_COUNT="${INPUT_PORT_COUNT:-10}"
93
-
94
- # ---------- 4. 获取配置中的用户编号并拼接 ----------
95
- CONFIG_USER_ID=""
96
- if [ -f "$CONFIG_PATH" ]; then
97
- CONFIG_USER_ID=$(node -e "try{const c=JSON.parse(require('fs').readFileSync('$CONFIG_PATH','utf-8'));console.log(c.userId||'')}catch(e){}" 2>/dev/null)
98
- fi
99
- if [ -z "$CONFIG_USER_ID" ]; then
100
- CONFIG_USER_ID="user"
101
- fi
102
- USER_ID="${CONFIG_USER_ID}_${BASE_PORT}_${PORT_COUNT}"
103
-
104
- echo ""
105
- echo "========================================"
106
- echo " 启动 tt-help explore"
107
- echo "========================================"
108
- echo " 用户编号: $USER_ID"
109
- echo " 起始端口: $BASE_PORT"
110
- echo " 端口数量: $PORT_COUNT"
111
- echo " 速度: stealth (最慢)"
112
- echo "========================================"
113
- tt-help explore stealth --user-id "$USER_ID" --base-port "$BASE_PORT" --port-count "$PORT_COUNT"
1
+ #!/bin/bash
2
+
3
+ PACKAGENAME="tt-help-cli-ycl"
4
+ CONFIG_PATH="$HOME/.tt-help.json"
5
+
6
+ echo "========================================"
7
+ echo " tt-help-cli-ycl 一键启动脚本 (macOS)"
8
+ echo "========================================"
9
+
10
+ # ---------- 0. 根据本机 IP 自动选择 server ----------
11
+ LOCAL_IP=$(ifconfig | awk '/inet / && $2 != "127.0.0.1" { print $2; exit }')
12
+
13
+ echo "[提示] 本机 IP: ${LOCAL_IP:-未检测到}"
14
+
15
+ if [[ "$LOCAL_IP" =~ ^172\.18\.154\.[0-9]+$ ]]; then
16
+ TARGET_SERVER="http://172.18.154.201:3001"
17
+ echo "[提示] 检测到内网 IP: $LOCAL_IP,使用内网 server"
18
+ else
19
+ TARGET_SERVER="http://117.71.53.99:17301"
20
+ echo "[提示] 未检测到内网 IP,使用公网 server"
21
+ fi
22
+
23
+ # ---------- 1. 检查/安装最新版本 ----------
24
+ LATEST_VERSION=$(npm view "$PACKAGENAME" version 2>/dev/null)
25
+
26
+ if [ -z "$LATEST_VERSION" ]; then
27
+ echo "[错误] 无法从 npm 获取最新版本信息"
28
+ exit 1
29
+ fi
30
+
31
+ INSTALLED_VERSION=$(npm list -g "$PACKAGENAME" --depth=0 2>/dev/null | grep "$PACKAGENAME@" | head -1 | sed 's/.*@//' | sed 's/[) ].*//')
32
+
33
+ if [ -z "$INSTALLED_VERSION" ]; then
34
+ echo "[提示] tt-help-cli-ycl 未安装,正在安装最新版本..."
35
+ npm install -g "$PACKAGENAME"
36
+ if [ $? -eq 0 ]; then
37
+ echo "[OK] 安装完成: $LATEST_VERSION"
38
+ else
39
+ echo "[错误] 安装失败,请手动执行: npm install -g $PACKAGENAME"
40
+ exit 1
41
+ fi
42
+ elif [ "$INSTALLED_VERSION" = "$LATEST_VERSION" ]; then
43
+ echo "[OK] tt-help-cli-ycl 已是最新版本: $LATEST_VERSION"
44
+ else
45
+ echo "[提示] 当前版本: $INSTALLED_VERSION, 最新版本: $LATEST_VERSION"
46
+ echo "[执行] 正在升级最新版本..."
47
+ npm install -g "$PACKAGENAME" 2>/dev/null
48
+ if [ $? -eq 0 ]; then
49
+ echo "[OK] 安装完成: $LATEST_VERSION"
50
+ else
51
+ echo "[警告] 自动安装失败,尝试手动更新..."
52
+ npm update -g "$PACKAGENAME"
53
+ fi
54
+ fi
55
+
56
+ # ---------- 2. 检查/设置 server 配置 ----------
57
+ CURRENT_SERVER=""
58
+ if [ -f "$CONFIG_PATH" ]; then
59
+ CURRENT_SERVER=$(node -e "try{const c=JSON.parse(require('fs').readFileSync('$CONFIG_PATH','utf-8'));console.log(c.server||'')}catch(e){}" 2>/dev/null)
60
+ fi
61
+
62
+ if [ "$CURRENT_SERVER" = "$TARGET_SERVER" ]; then
63
+ echo "[OK] Server 配置正确: $TARGET_SERVER"
64
+ else
65
+ echo "[提示] 当前 server: ${CURRENT_SERVER:-未设置}, 目标: $TARGET_SERVER"
66
+ echo "[执行] 正在设置 server 配置..."
67
+ node -e "
68
+ const fs = require('fs');
69
+ const path = require('path');
70
+ const configPath = path.join(require('os').homedir(), '.tt-help.json');
71
+ let cfg = {};
72
+ try { cfg = JSON.parse(fs.readFileSync(configPath, 'utf-8')); } catch(e) {}
73
+ cfg.server = '$TARGET_SERVER';
74
+ fs.writeFileSync(configPath, JSON.stringify(cfg, null, 2), 'utf-8');
75
+ console.log(' 已写入: ' + configPath);
76
+ "
77
+ echo "[OK] Server 配置已设置"
78
+ fi
79
+
80
+ # ---------- 3. 询问用户参数 ----------
81
+ echo ""
82
+ echo "========================================"
83
+ echo " 参数配置"
84
+ echo "========================================"
85
+
86
+ printf "起始端口 (--base-port) [默认: 9222]: "
87
+ read INPUT_BASE_PORT
88
+ BASE_PORT="${INPUT_BASE_PORT:-9222}"
89
+
90
+ printf "端口数量 (--port-count) [默认: 10]: "
91
+ read INPUT_PORT_COUNT
92
+ PORT_COUNT="${INPUT_PORT_COUNT:-10}"
93
+
94
+ printf "任务国家 (--job-locations) [默认: 无,使用全部]: "
95
+ read INPUT_JOB_LOCATIONS
96
+
97
+ # ---------- 4. 获取配置中的用户编号并拼接 ----------
98
+ CONFIG_USER_ID=""
99
+ if [ -f "$CONFIG_PATH" ]; then
100
+ CONFIG_USER_ID=$(node -e "try{const c=JSON.parse(require('fs').readFileSync('$CONFIG_PATH','utf-8'));console.log(c.userId||'')}catch(e){}" 2>/dev/null)
101
+ fi
102
+ if [ -z "$CONFIG_USER_ID" ]; then
103
+ CONFIG_USER_ID="user"
104
+ fi
105
+ USER_ID="${CONFIG_USER_ID}_${BASE_PORT}_${PORT_COUNT}"
106
+
107
+ echo ""
108
+ echo "========================================"
109
+ echo " 启动 tt-help explore"
110
+ echo "========================================"
111
+ echo " 用户编号: $USER_ID"
112
+ echo " 起始端口: $BASE_PORT"
113
+ echo " 端口数量: $PORT_COUNT"
114
+ if [ -n "$INPUT_JOB_LOCATIONS" ]; then echo " 任务国家: $INPUT_JOB_LOCATIONS"; fi
115
+ echo " 速度: stealth (最慢)"
116
+ echo "========================================"
117
+ JOB_LOC_ARGS=""
118
+ if [ -n "$INPUT_JOB_LOCATIONS" ]; then JOB_LOC_ARGS="--job-locations $INPUT_JOB_LOCATIONS"; fi
119
+ tt-help explore stealth --user-id "$USER_ID" --base-port "$BASE_PORT" --port-count "$PORT_COUNT" $JOB_LOC_ARGS