channel-worker 2.5.17 → 2.5.18

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.17",
3
+ "version": "2.5.18",
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.18a-fb-caption');
286
+ log('info', '[fb-pw] selectors version=2026.06.18b-thumb-required');
287
287
 
288
288
  page.on('dialog', (d) => { d.accept().catch(() => {}); });
289
289
 
@@ -918,6 +918,7 @@ async function run({ page, payload, log }) {
918
918
  // iterations, throw with diagnostics.
919
919
  let published = false;
920
920
  let customThumbDone = false;
921
+ let thumbWaitDone = false; // poll for the thumb-edit pill at most once
921
922
  let pubWaitDone = false; // guard: wait for a disabled "Đăng" at most once
922
923
  for (let step = 0; step < 7 && !published; step++) {
923
924
  await page.waitForTimeout(3000);
@@ -928,7 +929,7 @@ async function run({ page, payload, log }) {
928
929
  // file picker → "Lưu"). Per user screenshots, this is the only way to
929
930
  // attach a custom thumbnail in the Page-wall composer.
930
931
  if (!customThumbDone && thumbPath && /^https?:\/\/(www\.)?facebook\.com\/?($|\?|#)/.test(page.url())) {
931
- const editBtn = await page.evaluate(() => {
932
+ const findThumbBtn = () => page.evaluate(() => {
932
933
  // Look for the thumbnail-edit button inside the REEL COMPOSER dialog
933
934
  // only — scanning all dialogs risked matching a button on the
934
935
  // page-wall photo composer (which would post a separate "Tin dạng
@@ -969,7 +970,20 @@ async function run({ page, payload, log }) {
969
970
  }
970
971
  return null;
971
972
  }).catch(() => null);
973
+ let editBtn = await findThumbBtn();
974
+ // The "Chỉnh sửa hình thu nhỏ" pill only appears AFTER FB finishes
975
+ // processing the uploaded video (frame extraction). For larger clips
976
+ // that lags past the 30s upload-wait, so a single check often misses it.
977
+ // Poll once (up to 75s) for it before giving up.
978
+ if (!editBtn && !thumbWaitDone) {
979
+ log('info', '[fb-pw] thumb-edit pill not visible yet — waiting for video processing (up to 75s)…');
980
+ const tdl = Date.now() + 75_000;
981
+ while (!editBtn && Date.now() < tdl) { await page.waitForTimeout(4000); editBtn = await findThumbBtn(); }
982
+ if (editBtn) log('info', '[fb-pw] thumb-edit pill appeared after wait');
983
+ }
984
+ thumbWaitDone = true;
972
985
 
986
+ let thumbApplied = false;
973
987
  if (editBtn) {
974
988
  log('info', `[fb-pw] page-wall thumb — opening "Chỉnh sửa hình thu nhỏ" modal (via=${editBtn.via}, aria="${editBtn.aria}", text="${editBtn.text}"${editBtn.size ? `, size=${editBtn.size}` : ''})…`);
975
989
  try {
@@ -1090,6 +1104,7 @@ async function run({ page, payload, log }) {
1090
1104
  await page.waitForTimeout(1000);
1091
1105
  }
1092
1106
  if (modalClosed) {
1107
+ thumbApplied = true;
1093
1108
  log('info', `[fb-pw] page-wall thumb — modal closed after save (retries=${retryCount})`);
1094
1109
  } else {
1095
1110
  log('warn', '[fb-pw] page-wall thumb — modal still open 60s after Lưu click; trying ESC + click Hủy fallback');
@@ -1111,7 +1126,16 @@ async function run({ page, payload, log }) {
1111
1126
  } catch (e) {
1112
1127
  log('warn', `[fb-pw] page-wall thumb flow failed: ${e.message.slice(0, 100)}`);
1113
1128
  }
1114
- customThumbDone = true;
1129
+ customThumbDone = thumbApplied;
1130
+ }
1131
+ // The idea HAS a thumbnail → it is REQUIRED. If the pill never showed
1132
+ // (after the wait) or applying it failed, REFUSE to publish with FB's
1133
+ // auto-thumb. Fail HERE — at the caption step, BEFORE any "Tiếp"/publish
1134
+ // — so nothing ships and a retry can't double-post.
1135
+ if (!customThumbDone) {
1136
+ await dumpInventory(page, log, 'thumb-required-missing');
1137
+ await dumpFailure(page, 'thumb-required-missing', log);
1138
+ throw new Error('Custom thumbnail required but could not be applied (FB "Chỉnh sửa hình thu nhỏ" not available, or upload/save failed) — refusing to publish with FB auto-thumb');
1115
1139
  }
1116
1140
  }
1117
1141
 
@@ -1435,12 +1459,13 @@ async function run({ page, payload, log }) {
1435
1459
  // output. (Observed on reel 1506614811005729: step 1 → click Tiếp
1436
1460
  // → publish, the thumb-edit pill never appeared.)
1437
1461
  if (thumbPath && !customThumbDone) {
1438
- // Custom thumb couldn't be applied (FB didn't render the "Chỉnh sửa
1439
- // hình thu nhỏ" overlay). DON'T refuse to publish the strict
1440
- // failure shipped false "failed" results (the reel still published)
1441
- // and double-posts on retry. Publish with FB's auto-thumbnail; the
1442
- // custom artwork is a nice-to-have, not worth a hard failure.
1443
- log('warn', `[fb-pw] custom thumb skipped — "Chỉnh sửa hình thu nhỏ" overlay never appeared (step ${step + 1}); publishing with FB auto-thumb`);
1462
+ // Defensive: we normally fail at the caption step (before any Tiếp)
1463
+ // when a required custom thumb can't be applied. If we somehow reach
1464
+ // here without it, refuse to publish but BEFORE clicking Đăng, so
1465
+ // nothing ships and a retry can't double-post. (The v2.5.14 double-post
1466
+ // came from failing AFTER publish; this throw is pre-publish.)
1467
+ await dumpFailure(page, 'thumb-required-at-publish', log);
1468
+ throw new Error('Custom thumbnail required but not applied — refusing to publish with FB auto-thumb');
1444
1469
  }
1445
1470
  log('info', `[fb-pw] click publish "${pub.verb}" via "${pub.sel}" (step ${step + 1})`);
1446
1471
  // Snapshot the captured-IDs list RIGHT BEFORE the publish click. The