channel-worker 1.6.4 → 1.6.6

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/api-client.js CHANGED
@@ -65,7 +65,7 @@ class ApiClient {
65
65
 
66
66
  // Commands
67
67
  async getNextCommand(workerId) {
68
- const workerTypes = 'launch_profile,close_profile,save_file,set_thumbnail,set_tags,set_file_input,click_and_upload,type_text,verify_logins,update_extension,sync_youtube_stats,restart_worker';
68
+ const workerTypes = 'launch_profile,close_profile,launch_veo3_profile,save_file,set_thumbnail,set_tags,set_file_input,click_and_upload,type_text,verify_logins,update_extension,sync_youtube_stats,restart_worker';
69
69
  return this.request('GET', `/workers/commands?worker_id=${workerId}&types=${encodeURIComponent(workerTypes)}`);
70
70
  }
71
71
 
@@ -187,9 +187,12 @@ class CommandPoller {
187
187
  // Auto-create Nstbrowser profile if not exists
188
188
  await this.nst.ensureProfile(nst_profile_id, { os: os || 'windows' });
189
189
 
190
- // Use Content Creator extension path (separate from channel-manager-ext)
191
- const baseExtPath = this.config.content_creator_ext_path || '';
192
- if (!baseExtPath) throw new Error('content_creator_ext_path not configured in worker config.');
190
+ // Auto-download Content Creator extension if not present
191
+ const path = require('path');
192
+ const os_mod = require('os');
193
+ const defaultCCExtPath = path.join(os_mod.homedir(), 'content-creator-ext');
194
+ const baseExtPath = this.config.content_creator_ext_path || defaultCCExtPath;
195
+ await this._ensureContentCreatorExt(baseExtPath);
193
196
 
194
197
  let extensionPath = baseExtPath;
195
198
 
@@ -247,6 +250,69 @@ class CommandPoller {
247
250
  }
248
251
  }
249
252
 
253
+ async _ensureContentCreatorExt(extPath) {
254
+ const fs = require('fs');
255
+ const path = require('path');
256
+ const os = require('os');
257
+ const { execSync } = require('child_process');
258
+
259
+ // Check if already downloaded
260
+ const manifestPath = path.join(extPath, 'manifest.json');
261
+ if (fs.existsSync(manifestPath)) {
262
+ // Check for updates
263
+ try {
264
+ const local = JSON.parse(fs.readFileSync(manifestPath, 'utf8')).version;
265
+ const res = await this.api.request('GET', '/cc-extension-download/version');
266
+ const remote = res?.version;
267
+ if (remote && local && remote === local) {
268
+ console.log(`[commands] CC extension up to date (v${local})`);
269
+ return;
270
+ }
271
+ console.log(`[commands] CC extension update: ${local} → ${remote}`);
272
+ } catch {
273
+ console.log('[commands] CC extension exists, skip version check');
274
+ return;
275
+ }
276
+ }
277
+
278
+ console.log(`[commands] Downloading Content Creator extension to ${extPath}...`);
279
+ const tmpArchive = path.join(os.tmpdir(), `content-creator-ext-${Date.now()}.tar.gz`);
280
+ const tmpExtract = path.join(os.tmpdir(), `content-creator-ext-new-${Date.now()}`);
281
+
282
+ try {
283
+ // Download zip from API
284
+ const url = `${this.api.baseUrl}/cc-extension-download/zip`;
285
+ const res = await fetch(url, { headers: { 'x-worker-token': this.api.workerToken } });
286
+ if (!res.ok) throw new Error(`Download failed: ${res.status}`);
287
+ const buffer = Buffer.from(await res.arrayBuffer());
288
+ fs.writeFileSync(tmpArchive, buffer);
289
+
290
+ // Extract
291
+ fs.mkdirSync(tmpExtract, { recursive: true });
292
+ execSync(`tar -xzf "${tmpArchive}" -C "${tmpExtract}"`, { timeout: 30000 });
293
+
294
+ const extracted = path.join(tmpExtract, 'content-creator');
295
+ const sourceDir = fs.existsSync(extracted) ? extracted : tmpExtract;
296
+
297
+ // Replace extension dir
298
+ if (fs.existsSync(extPath)) {
299
+ fs.rmSync(extPath, { recursive: true, force: true });
300
+ }
301
+ fs.mkdirSync(extPath, { recursive: true });
302
+ const files = fs.readdirSync(sourceDir);
303
+ for (const f of files) {
304
+ const src = path.join(sourceDir, f);
305
+ const dest = path.join(extPath, f);
306
+ if (fs.statSync(src).isFile()) fs.copyFileSync(src, dest);
307
+ else if (fs.statSync(src).isDirectory()) fs.cpSync(src, dest, { recursive: true });
308
+ }
309
+ console.log(`[commands] CC extension downloaded to ${extPath}`);
310
+ } finally {
311
+ try { fs.unlinkSync(tmpArchive); } catch {}
312
+ try { fs.rmSync(tmpExtract, { recursive: true, force: true }); } catch {}
313
+ }
314
+ }
315
+
250
316
  async handleScanFacebookPages(command) {
251
317
  const { profile_id } = command.payload || {};
252
318
  console.log(`[commands] Scan Facebook pages — launching profile: ${profile_id}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "channel-worker",
3
- "version": "1.6.4",
3
+ "version": "1.6.6",
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": {