channel-worker 1.6.15 → 1.6.16
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/lib/command-poller.js +2 -2
- package/lib/nst-manager.js +32 -8
- package/package.json +1 -1
package/lib/command-poller.js
CHANGED
|
@@ -184,8 +184,8 @@ class CommandPoller {
|
|
|
184
184
|
}
|
|
185
185
|
}
|
|
186
186
|
|
|
187
|
-
// Auto-create Nstbrowser profile if not exists
|
|
188
|
-
await this.nst.ensureProfile(nst_profile_id, { os: os || 'windows' });
|
|
187
|
+
// Auto-create Nstbrowser profile if not exists (with proxy saved to profile)
|
|
188
|
+
await this.nst.ensureProfile(nst_profile_id, { os: os || 'windows', proxy: proxy || null });
|
|
189
189
|
|
|
190
190
|
// Auto-download Content Creator extension if not present
|
|
191
191
|
const path = require('path');
|
package/lib/nst-manager.js
CHANGED
|
@@ -69,6 +69,8 @@ class NstManager {
|
|
|
69
69
|
const existing = await this.findProfile(name);
|
|
70
70
|
if (existing) {
|
|
71
71
|
console.log(`[nst] Profile "${name}" exists: ${existing}`);
|
|
72
|
+
// Set proxy on existing profile if provided
|
|
73
|
+
if (options.proxy) await this.setProxy(existing, options.proxy);
|
|
72
74
|
return existing;
|
|
73
75
|
}
|
|
74
76
|
|
|
@@ -104,19 +106,40 @@ class NstManager {
|
|
|
104
106
|
const profileId = res?.data?.profileId || res?.data?._id;
|
|
105
107
|
if (!profileId) throw new Error('Failed to create profile — no ID returned');
|
|
106
108
|
|
|
109
|
+
// Set proxy on newly created profile
|
|
110
|
+
if (options.proxy) await this.setProxy(profileId, options.proxy);
|
|
111
|
+
|
|
107
112
|
console.log(`[nst] Profile "${name}" created: ${profileId}`);
|
|
108
113
|
return profileId;
|
|
109
114
|
}
|
|
110
115
|
|
|
111
|
-
// Set proxy on profile
|
|
116
|
+
// Set proxy on profile (persisted — works even when opened from Nst UI)
|
|
112
117
|
async setProxy(profileId, proxyUrl) {
|
|
113
118
|
if (!proxyUrl) return;
|
|
114
119
|
console.log(`[nst] Setting proxy for ${profileId}: ${proxyUrl}`);
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
+
// Parse proxy URL: protocol://user:pass@host:port
|
|
121
|
+
const parsed = new URL(proxyUrl);
|
|
122
|
+
const proxyConfig = {
|
|
123
|
+
proxy: {
|
|
124
|
+
type: parsed.protocol.replace(':', '').replace('socks5', 'socks5'), // http, https, socks5
|
|
125
|
+
host: parsed.hostname,
|
|
126
|
+
port: parsed.port,
|
|
127
|
+
...(parsed.username && { username: decodeURIComponent(parsed.username) }),
|
|
128
|
+
...(parsed.password && { password: decodeURIComponent(parsed.password) }),
|
|
129
|
+
},
|
|
130
|
+
};
|
|
131
|
+
// Try PATCH first, fallback to PUT
|
|
132
|
+
for (const method of ['PATCH', 'PUT']) {
|
|
133
|
+
try {
|
|
134
|
+
const res = await fetch(`${this.baseUrl}/profiles/${profileId}`, {
|
|
135
|
+
method,
|
|
136
|
+
headers: { 'Content-Type': 'application/json', 'x-api-key': this.apiKey },
|
|
137
|
+
body: JSON.stringify(proxyConfig),
|
|
138
|
+
});
|
|
139
|
+
if (res.ok) { console.log(`[nst] Proxy saved to profile (${method})`); return; }
|
|
140
|
+
} catch {}
|
|
141
|
+
}
|
|
142
|
+
console.warn(`[nst] Failed to save proxy to profile — will still use at launch time`);
|
|
120
143
|
}
|
|
121
144
|
|
|
122
145
|
// Launch browser — skip if already running, set proxy if provided
|
|
@@ -174,11 +197,12 @@ class NstManager {
|
|
|
174
197
|
},
|
|
175
198
|
};
|
|
176
199
|
|
|
177
|
-
//
|
|
200
|
+
// Save proxy to profile (persists for manual launches from Nst UI)
|
|
178
201
|
if (options.proxy) {
|
|
202
|
+
await this.setProxy(profileId, options.proxy);
|
|
179
203
|
connectConfig.proxy = options.proxy;
|
|
180
204
|
connectConfig.args['--proxy-bypass-list'] = 'api.channel.tunasm.art,*.amazonaws.com,localhost,127.0.0.1';
|
|
181
|
-
console.log(`[nst] Proxy: ${options.proxy} (bypass: api.channel.tunasm.art)`);
|
|
205
|
+
console.log(`[nst] Proxy: ${options.proxy} (saved to profile + bypass: api.channel.tunasm.art)`);
|
|
182
206
|
}
|
|
183
207
|
|
|
184
208
|
if (options.extensionPath) {
|