channel-worker 1.6.5 → 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/command-poller.js +69 -3
- package/package.json +1 -1
package/lib/command-poller.js
CHANGED
|
@@ -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
|
-
//
|
|
191
|
-
const
|
|
192
|
-
|
|
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}`);
|