channel-worker 2.5.18 → 2.5.19

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "channel-worker",
3
- "version": "2.5.18",
3
+ "version": "2.5.19",
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": {
@@ -283,7 +283,7 @@ async function run({ page, payload, log }) {
283
283
  } = payload || {};
284
284
  if (!video_url) throw new Error('No video_url provided');
285
285
 
286
- log('info', '[fb-pw] selectors version=2026.06.18b-thumb-required');
286
+ log('info', '[fb-pw] selectors version=2026.06.18c-proc-wait');
287
287
 
288
288
  page.on('dialog', (d) => { d.accept().catch(() => {}); });
289
289
 
@@ -510,11 +510,41 @@ async function run({ page, payload, log }) {
510
510
  throw new Error('FB Reels modal: "Thêm video"/"Tải lên" trigger not found — could not start video upload');
511
511
  }
512
512
 
513
- // 4) Wait for the video to finish processing on FB's side before we can
514
- // fill the caption + advance. FB shows a progress indicator and only
515
- // enables the "Tiếp" button once upload + thumbnail extraction is done.
516
- log('info', '[fb-pw] waiting for video upload to process (up to 60s)…');
517
- await page.waitForTimeout(30000); // FB processes 10-60s for short Reels
513
+ // 4) Wait for FB to finish processing the uploaded video before filling the
514
+ // caption + advancing. FB disables "Tiếp" (and hides the caption field)
515
+ // until upload + frame-extraction is done; processing time scales with
516
+ // video size/length. Instead of a blind fixed sleep (wasted idle for
517
+ // small clips, too short for big ones), POLL for an ENABLED "Tiếp" —
518
+ // proceed the instant it's ready, but give large clips up to 120s.
519
+ log('info', '[fb-pw] waiting for FB to finish processing the video…');
520
+ const procT0 = Date.now();
521
+ const procDeadline = procT0 + 120_000;
522
+ await page.waitForTimeout(2500); // let the upload register first
523
+ let procReady = false;
524
+ while (Date.now() < procDeadline) {
525
+ procReady = await page.evaluate(() => {
526
+ const dlgs = document.querySelectorAll("[role='dialog']");
527
+ const roots = dlgs.length ? Array.from(dlgs) : [document];
528
+ const verbs = ['Tiếp', 'Tiếp theo', 'Next', 'Continue'];
529
+ for (const root of roots) {
530
+ for (const el of root.querySelectorAll("button, [role='button']")) {
531
+ const t = (el.innerText || '').trim();
532
+ if (!verbs.includes(t)) continue;
533
+ const r = el.getBoundingClientRect();
534
+ if (r.width < 8 || r.height < 8) continue;
535
+ const cs = getComputedStyle(el);
536
+ if (cs.visibility === 'hidden' || cs.display === 'none') continue;
537
+ if (el.getAttribute('aria-disabled') === 'true' || el.disabled) continue;
538
+ return true; // an enabled Tiếp/Next → processing done, can advance
539
+ }
540
+ }
541
+ return false;
542
+ }).catch(() => false);
543
+ if (procReady) break;
544
+ await page.waitForTimeout(2500);
545
+ }
546
+ if (procReady) log('info', `[fb-pw] video processed in ~${Math.round((Date.now() - procT0) / 1000)}s — caption step ready`);
547
+ else log('warn', '[fb-pw] processing wait hit 120s cap — proceeding (Tiếp click auto-waits anyway)');
518
548
 
519
549
  // 5) Fill metadata. FB Reels has THREE separate fields (verified visually
520
550
  // by user — different from how YT lumps everything into title + desc):