channel-worker 1.3.0 → 1.3.2
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/bin/cli.js +10 -6
- package/lib/nst-manager.js +11 -7
- package/package.json +1 -1
package/bin/cli.js
CHANGED
|
@@ -6,6 +6,10 @@ const os = require('os');
|
|
|
6
6
|
|
|
7
7
|
const CONFIG_DIR = path.join(os.homedir(), '.channel-worker');
|
|
8
8
|
const CONFIG_FILE = path.join(CONFIG_DIR, 'config.json');
|
|
9
|
+
const DEFAULT_API_URL = 'https://api.channel.tunasm.art';
|
|
10
|
+
const DEFAULT_EXT_PATH = process.platform === 'win32'
|
|
11
|
+
? 'C:\\agents\\channel-manager-ext'
|
|
12
|
+
: path.join(os.homedir(), 'channel-manager-ext');
|
|
9
13
|
|
|
10
14
|
function parseArgs(args) {
|
|
11
15
|
const result = {};
|
|
@@ -40,9 +44,9 @@ const cmd = args._cmd || 'start';
|
|
|
40
44
|
if (cmd === 'pair') {
|
|
41
45
|
// Pair with dashboard using one-time code
|
|
42
46
|
const code = args.code;
|
|
43
|
-
const apiUrl = args.api ||
|
|
47
|
+
const apiUrl = args.api || DEFAULT_API_URL;
|
|
44
48
|
const nstKey = args['nst-key'] || '';
|
|
45
|
-
const extensionPath = args.extension ||
|
|
49
|
+
const extensionPath = args.extension || DEFAULT_EXT_PATH;
|
|
46
50
|
const maxConcurrent = parseInt(args.concurrent || '2', 10);
|
|
47
51
|
|
|
48
52
|
if (!code) {
|
|
@@ -91,10 +95,10 @@ if (cmd === 'pair') {
|
|
|
91
95
|
} else if (cmd === 'init') {
|
|
92
96
|
const config = {
|
|
93
97
|
worker_id: args.id || `worker-${os.hostname()}`,
|
|
94
|
-
api_url: args.api ||
|
|
98
|
+
api_url: args.api || DEFAULT_API_URL,
|
|
95
99
|
max_concurrent: parseInt(args.concurrent || '2', 10),
|
|
96
100
|
nst_api_key: args['nst-key'] || '',
|
|
97
|
-
extension_path: args.extension ||
|
|
101
|
+
extension_path: args.extension || DEFAULT_EXT_PATH,
|
|
98
102
|
worker_token: args.token || '',
|
|
99
103
|
};
|
|
100
104
|
saveConfig(config);
|
|
@@ -108,10 +112,10 @@ if (cmd === 'pair') {
|
|
|
108
112
|
const saved = loadConfig();
|
|
109
113
|
const config = {
|
|
110
114
|
worker_id: args.id || saved.worker_id || `worker-${os.hostname()}`,
|
|
111
|
-
api_url: args.api || saved.api_url ||
|
|
115
|
+
api_url: args.api || saved.api_url || DEFAULT_API_URL,
|
|
112
116
|
max_concurrent: parseInt(args.concurrent || saved.max_concurrent || '2', 10),
|
|
113
117
|
nst_api_key: args['nst-key'] || saved.nst_api_key || '',
|
|
114
|
-
extension_path: args.extension || saved.extension_path ||
|
|
118
|
+
extension_path: args.extension || saved.extension_path || DEFAULT_EXT_PATH,
|
|
115
119
|
worker_token: args.token || saved.worker_token || '',
|
|
116
120
|
verbose: !!args.verbose,
|
|
117
121
|
};
|
package/lib/nst-manager.js
CHANGED
|
@@ -46,16 +46,17 @@ class NstManager {
|
|
|
46
46
|
profiles = res.data;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
const match = profiles.find(p => p.name === name);
|
|
49
|
+
const match = profiles.find(p => p.name?.toLowerCase() === name.toLowerCase());
|
|
50
50
|
if (match) return match.profileId || match._id;
|
|
51
51
|
|
|
52
|
-
// Fallback: fetch
|
|
53
|
-
const rawRes = await fetch(
|
|
52
|
+
// Fallback: fetch profiles via local API with exact name search
|
|
53
|
+
const rawRes = await fetch(`http://localhost:8848/api/v2/profiles/?keyword=${encodeURIComponent(name)}&limit=100`, {
|
|
54
54
|
headers: { 'x-api-key': this.apiKey },
|
|
55
55
|
});
|
|
56
56
|
const rawData = await rawRes.json();
|
|
57
57
|
const allProfiles = rawData?.data?.docs || rawData?.data || [];
|
|
58
|
-
|
|
58
|
+
console.log(`[nst] Fallback search for "${name}": found ${allProfiles.length} profiles`);
|
|
59
|
+
const fallback = allProfiles.find(p => p.name?.toLowerCase() === name.toLowerCase());
|
|
59
60
|
if (fallback) return fallback.profileId || fallback._id;
|
|
60
61
|
|
|
61
62
|
return null;
|
|
@@ -73,7 +74,7 @@ class NstManager {
|
|
|
73
74
|
return existing;
|
|
74
75
|
}
|
|
75
76
|
|
|
76
|
-
console.log(`[nst]
|
|
77
|
+
console.log(`[nst] WARNING: Profile "${name}" NOT FOUND — creating new profile...`);
|
|
77
78
|
const res = await this.client.profiles().createProfile({
|
|
78
79
|
name,
|
|
79
80
|
platform: 'Windows',
|
|
@@ -122,9 +123,12 @@ class NstManager {
|
|
|
122
123
|
|
|
123
124
|
// Ensure profile language is en-US to prevent auto-translate
|
|
124
125
|
try {
|
|
125
|
-
await
|
|
126
|
-
|
|
126
|
+
const res = await fetch(`http://localhost:8848/api/v2/profiles/${profileId}`, {
|
|
127
|
+
method: 'PATCH',
|
|
128
|
+
headers: { 'Content-Type': 'application/json', 'x-api-key': this.apiKey },
|
|
129
|
+
body: JSON.stringify({ fingerprint: { language: 'en-US' } }),
|
|
127
130
|
});
|
|
131
|
+
if (!res.ok) console.warn(`[nst] Could not update profile language: ${res.status}`);
|
|
128
132
|
} catch (err) {
|
|
129
133
|
console.warn(`[nst] Could not update profile language:`, err.message);
|
|
130
134
|
}
|