channel-worker 1.0.4 → 1.0.5
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 +13 -5
- package/lib/nst-manager.js +15 -2
- package/package.json +1 -1
package/lib/command-poller.js
CHANGED
|
@@ -61,12 +61,11 @@ class CommandPoller {
|
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
async handleLaunchProfile(command) {
|
|
64
|
-
const { profile_id } = command.payload || {};
|
|
64
|
+
const { profile_id, channel_id } = command.payload || {};
|
|
65
65
|
console.log(`[commands] Launching Nstbrowser profile: ${profile_id}`);
|
|
66
66
|
|
|
67
67
|
try {
|
|
68
68
|
if (!this.nst) {
|
|
69
|
-
// No Nstbrowser SDK — try to get API key from dashboard settings
|
|
70
69
|
const apiKey = await this.api.getSetting('nst_api_key');
|
|
71
70
|
if (apiKey) {
|
|
72
71
|
this.nst = new NstManager(apiKey);
|
|
@@ -75,12 +74,21 @@ class CommandPoller {
|
|
|
75
74
|
}
|
|
76
75
|
}
|
|
77
76
|
|
|
78
|
-
|
|
79
|
-
|
|
77
|
+
// Fetch channel proxy if channel_id provided
|
|
78
|
+
let proxy = null;
|
|
79
|
+
if (channel_id) {
|
|
80
|
+
try {
|
|
81
|
+
const channel = await this.api.getChannel(channel_id);
|
|
82
|
+
proxy = channel?.proxy || null;
|
|
83
|
+
} catch { /* ignore */ }
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const result = await this.nst.launchProfile(profile_id, { proxy });
|
|
87
|
+
console.log(`[commands] Profile ${profile_id} launched${proxy ? ' (proxy: ' + proxy + ')' : ''}`);
|
|
80
88
|
|
|
81
89
|
await this.api.updateCommand(command._id, {
|
|
82
90
|
status: 'done',
|
|
83
|
-
result: { profile_id: result.profileId, launched_at: new Date().toISOString() },
|
|
91
|
+
result: { profile_id: result.profileId, launched_at: new Date().toISOString(), proxy: proxy || null },
|
|
84
92
|
});
|
|
85
93
|
} catch (err) {
|
|
86
94
|
console.error(`[commands] Failed to launch profile: ${err.message}`);
|
package/lib/nst-manager.js
CHANGED
|
@@ -89,8 +89,16 @@ class NstManager {
|
|
|
89
89
|
return profileId;
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
//
|
|
93
|
-
async
|
|
92
|
+
// Set proxy on profile
|
|
93
|
+
async setProxy(profileId, proxyUrl) {
|
|
94
|
+
if (!proxyUrl) return;
|
|
95
|
+
console.log(`[nst] Setting proxy for ${profileId}: ${proxyUrl}`);
|
|
96
|
+
await this.client.profiles().updateProfileProxy(profileId, { url: proxyUrl });
|
|
97
|
+
console.log(`[nst] Proxy set`);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Launch browser — skip if already running, set proxy if provided
|
|
101
|
+
async launchProfile(profileIdOrName, options = {}) {
|
|
94
102
|
let profileId = profileIdOrName;
|
|
95
103
|
if (!this.isUUID(profileIdOrName)) {
|
|
96
104
|
profileId = await this.ensureProfile(profileIdOrName);
|
|
@@ -102,6 +110,11 @@ class NstManager {
|
|
|
102
110
|
return { profileId, alreadyRunning: true };
|
|
103
111
|
}
|
|
104
112
|
|
|
113
|
+
// Set proxy before launch
|
|
114
|
+
if (options.proxy) {
|
|
115
|
+
await this.setProxy(profileId, options.proxy);
|
|
116
|
+
}
|
|
117
|
+
|
|
105
118
|
console.log(`[nst] Starting browser for profile: ${profileId}`);
|
|
106
119
|
const res = await this.client.browsers().startBrowser(profileId);
|
|
107
120
|
console.log(`[nst] Browser started`);
|