channel-worker 1.6.15 → 1.6.17

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.
@@ -78,6 +78,9 @@ class CommandPoller {
78
78
  case 'launch_veo3_profile':
79
79
  await this.handleLaunchVeo3Profile(command);
80
80
  break;
81
+ case 'set_profile_proxy':
82
+ await this.handleSetProfileProxy(command);
83
+ break;
81
84
  default:
82
85
  // Other commands (scan_facebook_pages, etc.) handled by extension
83
86
  console.log(`[commands] Skipping ${command.type} — handled by extension`);
@@ -184,8 +187,8 @@ class CommandPoller {
184
187
  }
185
188
  }
186
189
 
187
- // Auto-create Nstbrowser profile if not exists
188
- await this.nst.ensureProfile(nst_profile_id, { os: os || 'windows' });
190
+ // Auto-create Nstbrowser profile if not exists (with proxy saved to profile)
191
+ await this.nst.ensureProfile(nst_profile_id, { os: os || 'windows', proxy: proxy || null });
189
192
 
190
193
  // Auto-download Content Creator extension if not present
191
194
  const path = require('path');
@@ -246,6 +249,25 @@ class CommandPoller {
246
249
  }
247
250
  }
248
251
 
252
+ async handleSetProfileProxy(command) {
253
+ const { nst_profile_id, proxy, os } = command.payload || {};
254
+ console.log(`[commands] Setting proxy for profile ${nst_profile_id}`);
255
+ try {
256
+ if (!this.nst) {
257
+ const apiKey = await this.api.getSetting('nst_api_key');
258
+ if (apiKey) this.nst = new NstManager(apiKey);
259
+ else throw new Error('Nstbrowser API key not configured.');
260
+ }
261
+ // Ensure profile exists first
262
+ await this.nst.ensureProfile(nst_profile_id, { os: os || 'windows', proxy: proxy || null });
263
+ await this.api.updateCommand(command._id, { status: 'done' });
264
+ console.log(`[commands] Proxy set for ${nst_profile_id}`);
265
+ } catch (err) {
266
+ console.error(`[commands] Failed to set proxy: ${err.message}`);
267
+ await this.api.updateCommand(command._id, { status: 'failed', error: err.message });
268
+ }
269
+ }
270
+
249
271
  async _ensureContentCreatorExt(extPath) {
250
272
  const fs = require('fs');
251
273
  const path = require('path');
@@ -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
- await this.api(`/profiles/${profileId}/proxy`, {
116
- method: 'PATCH',
117
- body: JSON.stringify({ url: proxyUrl }),
118
- });
119
- console.log(`[nst] Proxy set`);
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
- // Pass proxy as URL string in connect config (Nstbrowser API format)
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) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "channel-worker",
3
- "version": "1.6.15",
3
+ "version": "1.6.17",
4
4
  "description": "Channel Manager worker daemon — runs on remote machines to execute video pipeline jobs",
5
5
  "main": "lib/daemon.js",
6
6
  "bin": {