progress_monitor.html 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167
  1. <style>
  2. /* Progress Monitor Container */
  3. #progress-monitor {
  4. background: linear-gradient(135deg, #0d1117 0%, #161b22 100%);
  5. color: #c9d1d9;
  6. font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans', Helvetica, Arial, sans-serif;
  7. font-size: 12px;
  8. border-bottom: 1px solid #30363d;
  9. position: relative;
  10. z-index: 100;
  11. }
  12. #progress-monitor.hidden {
  13. display: none;
  14. }
  15. #progress-monitor .tree-container {
  16. max-height: 350px;
  17. overflow-y: auto;
  18. }
  19. /* Header Bar */
  20. #progress-monitor .header-bar {
  21. display: flex;
  22. justify-content: space-between;
  23. align-items: center;
  24. padding: 8px 16px;
  25. background: rgba(0,0,0,0.2);
  26. border-bottom: 1px solid #30363d;
  27. position: sticky;
  28. top: 0;
  29. z-index: 10;
  30. }
  31. #progress-monitor .header-left {
  32. display: flex;
  33. align-items: center;
  34. gap: 16px;
  35. }
  36. #progress-monitor .header-right {
  37. display: flex;
  38. align-items: center;
  39. gap: 12px;
  40. }
  41. /* Orchestrator Status */
  42. #progress-monitor .orchestrator-status {
  43. display: flex;
  44. align-items: center;
  45. gap: 6px;
  46. }
  47. #progress-monitor .status-dot {
  48. width: 8px;
  49. height: 8px;
  50. border-radius: 50%;
  51. flex-shrink: 0;
  52. }
  53. #progress-monitor .status-dot.running {
  54. background: #3fb950;
  55. box-shadow: 0 0 8px #3fb950;
  56. animation: pulse 2s infinite;
  57. }
  58. #progress-monitor .status-dot.idle {
  59. background: #d29922;
  60. box-shadow: 0 0 4px #d29922;
  61. }
  62. #progress-monitor .status-dot.stopped {
  63. background: #6e7681;
  64. }
  65. #progress-monitor .status-dot.flash {
  66. animation: flash 0.3s ease-out;
  67. }
  68. @keyframes pulse {
  69. 0%, 100% { opacity: 1; box-shadow: 0 0 8px #3fb950; }
  70. 50% { opacity: 0.6; box-shadow: 0 0 4px #3fb950; }
  71. }
  72. @keyframes flash {
  73. 0% { transform: scale(1.5); }
  74. 100% { transform: scale(1); }
  75. }
  76. /* Stats */
  77. #progress-monitor .stats {
  78. display: flex;
  79. gap: 16px;
  80. }
  81. #progress-monitor .stat {
  82. display: flex;
  83. align-items: center;
  84. gap: 4px;
  85. }
  86. #progress-monitor .stat-label {
  87. color: #8b949e;
  88. font-size: 10px;
  89. text-transform: uppercase;
  90. letter-spacing: 0.5px;
  91. }
  92. #progress-monitor .stat-value {
  93. font-weight: 600;
  94. font-variant-numeric: tabular-nums;
  95. }
  96. #progress-monitor .stat-value.success { color: #3fb950; }
  97. #progress-monitor .stat-value.error { color: #f85149; }
  98. #progress-monitor .stat-value.warning { color: #d29922; }
  99. #progress-monitor .stat-value.info { color: #58a6ff; }
  100. #progress-monitor .stat.clickable {
  101. cursor: pointer;
  102. padding: 2px 6px;
  103. margin: -2px -6px;
  104. border-radius: 4px;
  105. transition: background 0.2s;
  106. }
  107. #progress-monitor .stat.clickable:hover {
  108. background: rgba(255,255,255,0.1);
  109. }
  110. #progress-monitor .stat.clickable:active {
  111. background: rgba(255,255,255,0.2);
  112. }
  113. /* Toggle Button */
  114. #progress-monitor .toggle-btn {
  115. background: transparent;
  116. border: 1px solid #30363d;
  117. color: #8b949e;
  118. cursor: pointer;
  119. padding: 4px 8px;
  120. border-radius: 6px;
  121. font-size: 11px;
  122. transition: all 0.2s;
  123. }
  124. #progress-monitor .toggle-btn:hover {
  125. background: #21262d;
  126. color: #c9d1d9;
  127. border-color: #8b949e;
  128. }
  129. #progress-monitor .cancel-item-btn {
  130. background: transparent;
  131. border: 1px solid #30363d;
  132. color: #f85149;
  133. cursor: pointer;
  134. padding: 2px 6px;
  135. border-radius: 6px;
  136. font-size: 11px;
  137. line-height: 1;
  138. transition: all 0.2s;
  139. flex-shrink: 0;
  140. }
  141. #progress-monitor .cancel-item-btn:hover {
  142. background: rgba(248, 81, 73, 0.12);
  143. border-color: #f85149;
  144. color: #ff7b72;
  145. }
  146. #progress-monitor .cancel-item-btn.is-busy {
  147. opacity: 0.6;
  148. cursor: wait;
  149. border-color: #6e7681;
  150. color: #6e7681;
  151. }
  152. /* Tree Container */
  153. #progress-monitor .tree-container {
  154. padding: 12px 16px;
  155. }
  156. #progress-monitor.collapsed .tree-container {
  157. display: none;
  158. }
  159. /* Idle Message */
  160. #progress-monitor .idle-message {
  161. color: #8b949e;
  162. font-style: italic;
  163. padding: 8px 0;
  164. text-align: center;
  165. }
  166. /* Crawl Item */
  167. #progress-monitor .crawl-item {
  168. background: #161b22;
  169. border: 1px solid #30363d;
  170. border-radius: 8px;
  171. margin-bottom: 12px;
  172. overflow: hidden;
  173. }
  174. #progress-monitor .crawl-header {
  175. display: flex;
  176. align-items: center;
  177. gap: 12px;
  178. padding: 10px 14px;
  179. background: rgba(0,0,0,0.2);
  180. }
  181. #progress-monitor .crawl-header:hover {
  182. background: rgba(88, 166, 255, 0.1);
  183. }
  184. #progress-monitor .crawl-header-link {
  185. display: flex;
  186. align-items: center;
  187. gap: 12px;
  188. flex: 1;
  189. min-width: 0;
  190. cursor: pointer;
  191. text-decoration: none;
  192. color: inherit;
  193. }
  194. #progress-monitor a.crawl-header-link:visited {
  195. color: inherit;
  196. }
  197. #progress-monitor .crawl-icon {
  198. font-size: 16px;
  199. width: 20px;
  200. text-align: center;
  201. }
  202. #progress-monitor .crawl-info {
  203. flex: 1;
  204. min-width: 0;
  205. }
  206. #progress-monitor .crawl-label {
  207. font-weight: 600;
  208. color: #58a6ff;
  209. white-space: nowrap;
  210. overflow: hidden;
  211. text-overflow: ellipsis;
  212. }
  213. #progress-monitor .crawl-meta {
  214. font-size: 11px;
  215. color: #8b949e;
  216. margin-top: 2px;
  217. }
  218. #progress-monitor .crawl-stats {
  219. display: flex;
  220. gap: 12px;
  221. font-size: 11px;
  222. }
  223. /* Progress Bar */
  224. #progress-monitor .progress-bar-container {
  225. height: 4px;
  226. background: #21262d;
  227. border-radius: 2px;
  228. overflow: hidden;
  229. position: relative;
  230. }
  231. #progress-monitor .progress-bar {
  232. height: 100%;
  233. border-radius: 2px;
  234. transition: width 0.5s ease-out;
  235. position: relative;
  236. }
  237. #progress-monitor .progress-bar.crawl {
  238. background: linear-gradient(90deg, #238636 0%, #3fb950 100%);
  239. }
  240. #progress-monitor .progress-bar.snapshot {
  241. background: linear-gradient(90deg, #1f6feb 0%, #58a6ff 100%);
  242. }
  243. #progress-monitor .progress-bar.extractor {
  244. background: linear-gradient(90deg, #8957e5 0%, #a371f7 100%);
  245. }
  246. #progress-monitor .progress-bar.indeterminate {
  247. background: linear-gradient(90deg, transparent 0%, #58a6ff 50%, transparent 100%);
  248. animation: indeterminate 1.5s infinite linear;
  249. width: 30% !important;
  250. }
  251. @keyframes indeterminate {
  252. 0% { transform: translateX(-100%); }
  253. 100% { transform: translateX(400%); }
  254. }
  255. /* Crawl Body */
  256. #progress-monitor .crawl-body {
  257. padding: 0 14px 14px;
  258. }
  259. #progress-monitor .crawl-progress {
  260. padding: 10px 14px;
  261. border-bottom: 1px solid #21262d;
  262. }
  263. /* Snapshot List */
  264. #progress-monitor .snapshot-list {
  265. margin-top: 8px;
  266. }
  267. #progress-monitor .snapshot-item {
  268. background: #0d1117;
  269. border: 1px solid #21262d;
  270. border-radius: 6px;
  271. margin-bottom: 8px;
  272. overflow: hidden;
  273. }
  274. #progress-monitor .snapshot-header {
  275. display: flex;
  276. align-items: center;
  277. gap: 10px;
  278. padding: 8px 12px;
  279. }
  280. #progress-monitor .snapshot-header:hover {
  281. background: rgba(88, 166, 255, 0.05);
  282. }
  283. #progress-monitor .snapshot-header-link {
  284. display: flex;
  285. align-items: center;
  286. gap: 10px;
  287. flex: 1;
  288. min-width: 0;
  289. cursor: pointer;
  290. text-decoration: none;
  291. color: inherit;
  292. }
  293. #progress-monitor a.snapshot-header-link:visited {
  294. color: inherit;
  295. }
  296. #progress-monitor .snapshot-icon {
  297. font-size: 14px;
  298. width: 18px;
  299. text-align: center;
  300. color: #58a6ff;
  301. }
  302. #progress-monitor .snapshot-info {
  303. flex: 1;
  304. min-width: 0;
  305. }
  306. #progress-monitor .snapshot-url {
  307. font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
  308. font-size: 11px;
  309. color: #c9d1d9;
  310. white-space: nowrap;
  311. overflow: hidden;
  312. text-overflow: ellipsis;
  313. }
  314. #progress-monitor .snapshot-meta {
  315. font-size: 10px;
  316. color: #8b949e;
  317. margin-top: 2px;
  318. }
  319. #progress-monitor .snapshot-progress {
  320. padding: 0 12px 8px;
  321. }
  322. /* Extractor List - Compact Badge Layout */
  323. #progress-monitor .extractor-list {
  324. padding: 8px 12px;
  325. background: rgba(0,0,0,0.2);
  326. border-top: 1px solid #21262d;
  327. display: flex;
  328. flex-wrap: wrap;
  329. gap: 4px;
  330. }
  331. #progress-monitor .extractor-badge {
  332. position: relative;
  333. display: inline-flex;
  334. align-items: center;
  335. gap: 4px;
  336. padding: 3px 8px;
  337. border-radius: 4px;
  338. font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
  339. font-size: 10px;
  340. background: #21262d;
  341. overflow: hidden;
  342. white-space: nowrap;
  343. }
  344. #progress-monitor .extractor-badge .progress-fill {
  345. position: absolute;
  346. top: 0;
  347. left: 0;
  348. bottom: 0;
  349. z-index: 0;
  350. transition: width 0.3s ease-out;
  351. }
  352. #progress-monitor .extractor-badge .badge-content {
  353. position: relative;
  354. z-index: 1;
  355. display: flex;
  356. align-items: center;
  357. gap: 4px;
  358. }
  359. #progress-monitor .extractor-badge.queued {
  360. color: #8b949e;
  361. }
  362. #progress-monitor .extractor-badge.queued .progress-fill {
  363. background: rgba(110, 118, 129, 0.2);
  364. width: 0%;
  365. }
  366. #progress-monitor .extractor-badge.started {
  367. color: #d29922;
  368. }
  369. #progress-monitor .extractor-badge.started .progress-fill {
  370. background: rgba(210, 153, 34, 0.3);
  371. animation: progress-pulse 1.5s ease-in-out infinite;
  372. }
  373. @keyframes progress-pulse {
  374. 0%, 100% { opacity: 0.5; }
  375. 50% { opacity: 1; }
  376. }
  377. #progress-monitor .extractor-badge.succeeded {
  378. color: #3fb950;
  379. }
  380. #progress-monitor .extractor-badge.succeeded .progress-fill {
  381. background: rgba(63, 185, 80, 0.25);
  382. width: 100%;
  383. }
  384. #progress-monitor .extractor-badge.failed {
  385. color: #f85149;
  386. }
  387. #progress-monitor .extractor-badge.failed .progress-fill {
  388. background: rgba(248, 81, 73, 0.25);
  389. width: 100%;
  390. }
  391. #progress-monitor .extractor-badge.backoff {
  392. color: #b8860b;
  393. }
  394. #progress-monitor .extractor-badge.backoff .progress-fill {
  395. background: rgba(210, 153, 34, 0.2);
  396. width: 30%;
  397. }
  398. #progress-monitor .extractor-badge.skipped {
  399. color: #6e7681;
  400. }
  401. #progress-monitor .extractor-badge.skipped .progress-fill {
  402. background: rgba(110, 118, 129, 0.15);
  403. width: 100%;
  404. }
  405. #progress-monitor .extractor-badge .badge-icon {
  406. font-size: 10px;
  407. }
  408. #progress-monitor .extractor-badge.started .badge-icon {
  409. animation: spin 1s linear infinite;
  410. }
  411. @keyframes spin {
  412. from { transform: rotate(0deg); }
  413. to { transform: rotate(360deg); }
  414. }
  415. /* Status Badge */
  416. #progress-monitor .status-badge {
  417. font-size: 10px;
  418. padding: 2px 6px;
  419. border-radius: 10px;
  420. font-weight: 500;
  421. text-transform: uppercase;
  422. letter-spacing: 0.3px;
  423. }
  424. #progress-monitor .status-badge.queued {
  425. background: #21262d;
  426. color: #8b949e;
  427. }
  428. #progress-monitor .status-badge.started {
  429. background: rgba(210, 153, 34, 0.2);
  430. color: #d29922;
  431. }
  432. #progress-monitor .status-badge.sealed,
  433. #progress-monitor .status-badge.succeeded {
  434. background: rgba(63, 185, 80, 0.2);
  435. color: #3fb950;
  436. }
  437. #progress-monitor .status-badge.failed {
  438. background: rgba(248, 81, 73, 0.2);
  439. color: #f85149;
  440. }
  441. #progress-monitor .status-badge.backoff {
  442. background: rgba(210, 153, 34, 0.15);
  443. color: #b8860b;
  444. }
  445. #progress-monitor .status-badge.unknown {
  446. background: #21262d;
  447. color: #6e7681;
  448. }
  449. /* Thumbnail Strip */
  450. #progress-monitor .thumbnail-strip {
  451. display: flex;
  452. gap: 8px;
  453. padding: 10px 16px;
  454. background: rgba(0,0,0,0.15);
  455. border-top: 1px solid #21262d;
  456. overflow-x: auto;
  457. scrollbar-width: thin;
  458. scrollbar-color: #30363d #0d1117;
  459. }
  460. #progress-monitor .thumbnail-strip::-webkit-scrollbar {
  461. height: 6px;
  462. }
  463. #progress-monitor .thumbnail-strip::-webkit-scrollbar-track {
  464. background: #0d1117;
  465. }
  466. #progress-monitor .thumbnail-strip::-webkit-scrollbar-thumb {
  467. background: #30363d;
  468. border-radius: 3px;
  469. }
  470. #progress-monitor .thumbnail-strip::-webkit-scrollbar-thumb:hover {
  471. background: #484f58;
  472. }
  473. #progress-monitor .thumbnail-strip.empty {
  474. display: none;
  475. }
  476. #progress-monitor .thumbnail-item {
  477. flex-shrink: 0;
  478. position: relative;
  479. width: 64px;
  480. height: 48px;
  481. border-radius: 4px;
  482. overflow: hidden;
  483. border: 1px solid #30363d;
  484. background: #161b22;
  485. cursor: pointer;
  486. transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
  487. }
  488. #progress-monitor .thumbnail-item:hover {
  489. transform: scale(1.1);
  490. border-color: #58a6ff;
  491. box-shadow: 0 0 12px rgba(88, 166, 255, 0.3);
  492. z-index: 10;
  493. }
  494. #progress-monitor .thumbnail-item.new {
  495. animation: thumbnail-pop 0.4s ease-out;
  496. }
  497. @keyframes thumbnail-pop {
  498. 0% { transform: scale(0.5); opacity: 0; }
  499. 50% { transform: scale(1.15); }
  500. 100% { transform: scale(1); opacity: 1; }
  501. }
  502. #progress-monitor .thumbnail-item img {
  503. width: 100%;
  504. height: 100%;
  505. object-fit: cover;
  506. }
  507. #progress-monitor .thumbnail-item .thumbnail-fallback {
  508. width: 100%;
  509. height: 100%;
  510. display: flex;
  511. align-items: center;
  512. justify-content: center;
  513. font-size: 20px;
  514. color: #8b949e;
  515. background: linear-gradient(135deg, #21262d 0%, #161b22 100%);
  516. }
  517. #progress-monitor .thumbnail-item .thumbnail-plugin {
  518. position: absolute;
  519. bottom: 0;
  520. left: 0;
  521. right: 0;
  522. padding: 2px 4px;
  523. font-size: 8px;
  524. font-weight: 600;
  525. text-transform: uppercase;
  526. color: #fff;
  527. background: rgba(0,0,0,0.7);
  528. text-align: center;
  529. white-space: nowrap;
  530. overflow: hidden;
  531. text-overflow: ellipsis;
  532. }
  533. #progress-monitor .thumbnail-label {
  534. display: flex;
  535. align-items: center;
  536. gap: 6px;
  537. padding: 0 4px;
  538. color: #8b949e;
  539. font-size: 10px;
  540. text-transform: uppercase;
  541. letter-spacing: 0.5px;
  542. flex-shrink: 0;
  543. }
  544. #progress-monitor .pid-label {
  545. display: inline-flex;
  546. align-items: center;
  547. gap: 4px;
  548. padding: 2px 6px;
  549. border-radius: 999px;
  550. font-size: 10px;
  551. font-weight: 600;
  552. color: #8b949e;
  553. background: rgba(148, 163, 184, 0.12);
  554. border: 1px solid rgba(148, 163, 184, 0.2);
  555. font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  556. letter-spacing: 0.2px;
  557. white-space: nowrap;
  558. }
  559. #progress-monitor .pid-label.compact {
  560. padding: 1px 5px;
  561. font-size: 9px;
  562. }
  563. </style>
  564. <div id="progress-monitor">
  565. <div class="header-bar">
  566. <div class="header-left">
  567. <div class="orchestrator-status">
  568. <span class="status-dot stopped" id="orchestrator-dot"></span>
  569. <span id="orchestrator-text">Stopped</span>
  570. <span class="pid-label compact" id="orchestrator-pid" style="display:none;"></span>
  571. </div>
  572. <div class="stats">
  573. <div class="stat">
  574. <span class="stat-label">Workers</span>
  575. <span class="stat-value info" id="worker-count">0</span>
  576. </div>
  577. <div class="stat">
  578. <span class="stat-label">Queued</span>
  579. <span class="stat-value warning" id="total-queued">0</span>
  580. </div>
  581. <div class="stat clickable" id="stat-succeeded" title="Click to reset counter">
  582. <span class="stat-label">Done</span>
  583. <span class="stat-value success" id="total-succeeded">0</span>
  584. </div>
  585. <div class="stat clickable" id="stat-failed" title="Click to reset counter">
  586. <span class="stat-label">Failed</span>
  587. <span class="stat-value error" id="total-failed">0</span>
  588. </div>
  589. </div>
  590. </div>
  591. <div class="header-right">
  592. <button class="toggle-btn" id="progress-collapse" title="Toggle details">Details</button>
  593. </div>
  594. </div>
  595. <div class="thumbnail-strip empty" id="thumbnail-strip">
  596. <span class="thumbnail-label">Recent:</span>
  597. </div>
  598. <div class="tree-container" id="tree-container">
  599. <div class="idle-message" id="idle-message">No active crawls</div>
  600. <div id="crawl-tree"></div>
  601. </div>
  602. </div>
  603. <script>
  604. (function() {
  605. const monitor = document.getElementById('progress-monitor');
  606. const collapseBtn = document.getElementById('progress-collapse');
  607. const treeContainer = document.getElementById('tree-container');
  608. const crawlTree = document.getElementById('crawl-tree');
  609. const idleMessage = document.getElementById('idle-message');
  610. const thumbnailStrip = document.getElementById('thumbnail-strip');
  611. let pollInterval = null;
  612. let pollDelayMs = 1000;
  613. let idleTicks = 0;
  614. let isCollapsed = localStorage.getItem('progress-monitor-collapsed') === 'true';
  615. let knownThumbnailIds = new Set();
  616. // Baselines for resettable counters
  617. let succeededBaseline = parseInt(localStorage.getItem('progress-succeeded-baseline') || '0');
  618. let failedBaseline = parseInt(localStorage.getItem('progress-failed-baseline') || '0');
  619. function getApiKey() {
  620. return (window.ARCHIVEBOX_API_KEY || '').trim();
  621. }
  622. function buildApiUrl(path) {
  623. const apiKey = getApiKey();
  624. if (!apiKey) return path;
  625. const sep = path.includes('?') ? '&' : '?';
  626. return `${path}${sep}api_key=${encodeURIComponent(apiKey)}`;
  627. }
  628. function buildApiHeaders() {
  629. const headers = { 'Content-Type': 'application/json' };
  630. const apiKey = getApiKey();
  631. if (apiKey) headers['X-ArchiveBox-API-Key'] = apiKey;
  632. return headers;
  633. }
  634. let lastSucceeded = 0;
  635. let lastFailed = 0;
  636. // Click handlers for resetting counters
  637. document.getElementById('stat-succeeded').addEventListener('click', function() {
  638. succeededBaseline = lastSucceeded;
  639. localStorage.setItem('progress-succeeded-baseline', succeededBaseline);
  640. document.getElementById('total-succeeded').textContent = '0';
  641. });
  642. document.getElementById('stat-failed').addEventListener('click', function() {
  643. failedBaseline = lastFailed;
  644. localStorage.setItem('progress-failed-baseline', failedBaseline);
  645. document.getElementById('total-failed').textContent = '0';
  646. });
  647. function formatUrl(url) {
  648. if (!url) return '(no URL)';
  649. try {
  650. const u = new URL(url);
  651. return u.hostname + u.pathname.substring(0, 30) + (u.pathname.length > 30 ? '...' : '');
  652. } catch {
  653. return String(url).substring(0, 50) + (String(url).length > 50 ? '...' : '');
  654. }
  655. }
  656. function getPluginIcon(plugin) {
  657. const icons = {
  658. 'screenshot': '&#128247;',
  659. 'favicon': '&#11088;',
  660. 'dom': '&#128196;',
  661. 'pdf': '&#128462;',
  662. 'title': '&#128221;',
  663. 'headers': '&#128203;',
  664. 'singlefile': '&#128230;',
  665. 'readability': '&#128214;',
  666. 'mercury': '&#9884;',
  667. 'wget': '&#128229;',
  668. 'media': '&#127909;',
  669. };
  670. return icons[plugin] || '&#128196;';
  671. }
  672. function renderThumbnail(thumb, isNew) {
  673. const ext = (thumb.embed_path || '').toLowerCase().split('.').pop();
  674. const isImage = ['png', 'jpg', 'jpeg', 'gif', 'webp', 'svg', 'ico'].includes(ext);
  675. const item = document.createElement('a');
  676. item.className = 'thumbnail-item' + (isNew ? ' new' : '');
  677. item.href = `/admin/core/snapshot/${thumb.snapshot_id}/change/`;
  678. item.title = `${thumb.plugin}: ${thumb.snapshot_url}`;
  679. item.dataset.id = thumb.id;
  680. const archiveUrl = thumb.archive_url || thumb.archive_path;
  681. if (isImage && archiveUrl) {
  682. item.innerHTML = `
  683. <img src="${archiveUrl}" alt="${thumb.plugin}" loading="lazy" onerror="this.parentElement.innerHTML='<div class=\\'thumbnail-fallback\\'>${getPluginIcon(thumb.plugin)}</div><span class=\\'thumbnail-plugin\\'>${thumb.plugin}</span>'">
  684. <span class="thumbnail-plugin">${thumb.plugin}</span>
  685. `;
  686. } else {
  687. item.innerHTML = `
  688. <div class="thumbnail-fallback">${getPluginIcon(thumb.plugin)}</div>
  689. <span class="thumbnail-plugin">${thumb.plugin}</span>
  690. `;
  691. }
  692. return item;
  693. }
  694. function updateThumbnails(thumbnails) {
  695. if (!thumbnails || thumbnails.length === 0) {
  696. thumbnailStrip.classList.add('empty');
  697. return;
  698. }
  699. thumbnailStrip.classList.remove('empty');
  700. // Find new thumbnails (ones we haven't seen before)
  701. const newThumbs = thumbnails.filter(t => !knownThumbnailIds.has(t.id));
  702. // Add new thumbnails to the beginning (after the label)
  703. const label = thumbnailStrip.querySelector('.thumbnail-label');
  704. newThumbs.reverse().forEach(thumb => {
  705. const item = renderThumbnail(thumb, true);
  706. if (label.nextSibling) {
  707. thumbnailStrip.insertBefore(item, label.nextSibling);
  708. } else {
  709. thumbnailStrip.appendChild(item);
  710. }
  711. knownThumbnailIds.add(thumb.id);
  712. });
  713. // Limit to 20 thumbnails (remove old ones)
  714. const items = thumbnailStrip.querySelectorAll('.thumbnail-item');
  715. if (items.length > 20) {
  716. for (let i = 20; i < items.length; i++) {
  717. const id = items[i].dataset.id;
  718. knownThumbnailIds.delete(id);
  719. items[i].remove();
  720. }
  721. }
  722. }
  723. function renderExtractor(extractor) {
  724. const icon = extractor.status === 'started' ? '&#8635;' :
  725. extractor.status === 'succeeded' ? '&#10003;' :
  726. extractor.status === 'failed' ? '&#10007;' :
  727. extractor.status === 'backoff' ? '&#8987;' :
  728. extractor.status === 'skipped' ? '&#8674;' : '&#9675;';
  729. const progress = typeof extractor.progress === 'number'
  730. ? Math.max(0, Math.min(100, extractor.progress))
  731. : null;
  732. const progressStyle = progress !== null ? ` style="width: ${progress}%;"` : '';
  733. const pidHtml = extractor.pid ? `<span class="pid-label compact">pid ${extractor.pid}</span>` : '';
  734. return `
  735. <span class="extractor-badge ${extractor.status || 'queued'}">
  736. <span class="progress-fill"${progressStyle}></span>
  737. <span class="badge-content">
  738. <span class="badge-icon">${icon}</span>
  739. <span>${extractor.plugin || 'unknown'}</span>
  740. ${pidHtml}
  741. </span>
  742. </span>
  743. `;
  744. }
  745. function renderSnapshot(snapshot, crawlId) {
  746. const statusIcon = snapshot.status === 'started' ? '&#8635;' : '&#128196;';
  747. const adminUrl = `/admin/core/snapshot/${snapshot.id || 'unknown'}/change/`;
  748. const canCancel = snapshot.status === 'queued';
  749. const cancelBtn = canCancel
  750. ? `<button class="cancel-item-btn" data-cancel-type="snapshot" data-snapshot-id="${snapshot.id}" data-label="✕" title="Cancel snapshot">✕</button>`
  751. : '';
  752. const snapshotPidHtml = snapshot.worker_pid ? `<span class="pid-label compact">pid ${snapshot.worker_pid}</span>` : '';
  753. let extractorHtml = '';
  754. if (snapshot.all_plugins && snapshot.all_plugins.length > 0) {
  755. // Sort plugins alphabetically by name to prevent reordering on updates
  756. const sortedExtractors = [...snapshot.all_plugins].sort((a, b) =>
  757. (a.plugin || '').localeCompare(b.plugin || '')
  758. );
  759. extractorHtml = `
  760. <div class="extractor-list">
  761. ${sortedExtractors.map(e => renderExtractor(e)).join('')}
  762. </div>
  763. `;
  764. }
  765. return `
  766. <div class="snapshot-item">
  767. <div class="snapshot-header">
  768. <a class="snapshot-header-link" href="${adminUrl}">
  769. <span class="snapshot-icon">${statusIcon}</span>
  770. <div class="snapshot-info">
  771. <div class="snapshot-url">${formatUrl(snapshot.url)}</div>
  772. <div class="snapshot-meta">
  773. ${(snapshot.total_plugins || 0) > 0
  774. ? `${snapshot.completed_plugins || 0}/${snapshot.total_plugins || 0} extractors${(snapshot.failed_plugins || 0) > 0 ? ` <span style="color:#f85149">(${snapshot.failed_plugins} failed)</span>` : ''}`
  775. : 'Waiting for extractors...'}
  776. </div>
  777. </div>
  778. ${snapshotPidHtml}
  779. <span class="status-badge ${snapshot.status || 'unknown'}">${snapshot.status || 'unknown'}</span>
  780. </a>
  781. ${cancelBtn}
  782. </div>
  783. <div class="snapshot-progress">
  784. <div class="progress-bar-container">
  785. <div class="progress-bar snapshot ${snapshot.status === 'started' && (snapshot.progress || 0) === 0 ? 'indeterminate' : ''}"
  786. style="width: ${snapshot.progress || 0}%"></div>
  787. </div>
  788. </div>
  789. ${extractorHtml}
  790. </div>
  791. `;
  792. }
  793. function renderCrawl(crawl) {
  794. const statusIcon = crawl.status === 'started' ? '&#8635;' : '&#128269;';
  795. const adminUrl = `/admin/crawls/crawl/${crawl.id || 'unknown'}/change/`;
  796. const canCancel = crawl.status === 'queued' || crawl.status === 'started';
  797. const cancelBtn = canCancel
  798. ? `<button class="cancel-item-btn" data-cancel-type="crawl" data-crawl-id="${crawl.id}" data-label="✕" title="Cancel crawl">✕</button>`
  799. : '';
  800. const crawlPidHtml = crawl.worker_pid ? `<span class="pid-label compact">pid ${crawl.worker_pid}</span>` : '';
  801. let snapshotsHtml = '';
  802. if (crawl.active_snapshots && crawl.active_snapshots.length > 0) {
  803. snapshotsHtml = crawl.active_snapshots.map(s => renderSnapshot(s, crawl.id)).join('');
  804. }
  805. // Show warning if crawl is stuck (queued but can't start)
  806. let warningHtml = '';
  807. if (crawl.status === 'queued' && !crawl.can_start) {
  808. warningHtml = `
  809. <div style="padding: 8px 14px; background: rgba(248, 81, 73, 0.1); border-top: 1px solid #f85149; color: #f85149; font-size: 11px;">
  810. ⚠️ Crawl cannot start: ${crawl.urls_preview ? 'unknown error' : 'no URLs'}
  811. </div>
  812. `;
  813. } else if (crawl.status === 'queued' && crawl.retry_at_future) {
  814. // Queued but retry_at is in future (was claimed by worker, will retry)
  815. warningHtml = `
  816. <div style="padding: 8px 14px; background: rgba(88, 166, 255, 0.1); border-top: 1px solid #58a6ff; color: #58a6ff; font-size: 11px;">
  817. 🔄 Trying in ${crawl.seconds_until_retry || 0}s...${crawl.urls_preview ? ` (${crawl.urls_preview})` : ''}
  818. </div>
  819. `;
  820. } else if (crawl.status === 'queued' && crawl.total_snapshots === 0) {
  821. // Queued and waiting to be picked up by worker
  822. warningHtml = `
  823. <div style="padding: 8px 14px; background: rgba(210, 153, 34, 0.1); border-top: 1px solid #d29922; color: #d29922; font-size: 11px;">
  824. ⏳ Waiting for worker to pick up...${crawl.urls_preview ? ` (${crawl.urls_preview})` : ''}
  825. </div>
  826. `;
  827. }
  828. // Show snapshot info or URL count if no snapshots yet
  829. let metaText = `depth: ${crawl.max_depth || 0}`;
  830. if ((crawl.total_snapshots || 0) > 0) {
  831. metaText += ` | ${crawl.total_snapshots} snapshots`;
  832. } else if ((crawl.urls_count || 0) > 0) {
  833. metaText += ` | ${crawl.urls_count} URLs`;
  834. } else if (crawl.urls_preview) {
  835. metaText += ` | ${crawl.urls_preview.substring(0, 40)}${crawl.urls_preview.length > 40 ? '...' : ''}`;
  836. }
  837. return `
  838. <div class="crawl-item" data-crawl-id="${crawl.id || 'unknown'}">
  839. <div class="crawl-header">
  840. <a class="crawl-header-link" href="${adminUrl}">
  841. <span class="crawl-icon">${statusIcon}</span>
  842. <div class="crawl-info">
  843. <div class="crawl-label">${crawl.label || '(no label)'}</div>
  844. <div class="crawl-meta">${metaText}</div>
  845. </div>
  846. <div class="crawl-stats">
  847. <span style="color:#3fb950">${crawl.completed_snapshots || 0} done</span>
  848. <span style="color:#d29922">${crawl.started_snapshots || 0} active</span>
  849. <span style="color:#8b949e">${crawl.pending_snapshots || 0} pending</span>
  850. </div>
  851. ${crawlPidHtml}
  852. <span class="status-badge ${crawl.status || 'unknown'}">${crawl.status || 'unknown'}</span>
  853. </a>
  854. ${cancelBtn}
  855. </div>
  856. <div class="crawl-progress">
  857. <div class="progress-bar-container">
  858. <div class="progress-bar crawl ${crawl.status === 'started' && (crawl.progress || 0) === 0 ? 'indeterminate' : ''}"
  859. style="width: ${crawl.progress || 0}%"></div>
  860. </div>
  861. </div>
  862. ${warningHtml}
  863. <div class="crawl-body">
  864. <div class="snapshot-list">
  865. ${snapshotsHtml}
  866. </div>
  867. </div>
  868. </div>
  869. `;
  870. }
  871. function updateProgress(data) {
  872. // Calculate if there's activity
  873. const hasActivity = data.active_crawls.length > 0 ||
  874. data.crawls_pending > 0 || data.crawls_started > 0 ||
  875. data.snapshots_pending > 0 || data.snapshots_started > 0 ||
  876. data.archiveresults_pending > 0 || data.archiveresults_started > 0;
  877. if (!hasActivity && !isCollapsed) {
  878. setCollapsedState(true);
  879. }
  880. if (hasActivity) {
  881. idleTicks = 0;
  882. if (pollDelayMs !== 1000) {
  883. setPollingDelay(1000);
  884. }
  885. } else {
  886. idleTicks += 1;
  887. if (idleTicks > 5 && pollDelayMs !== 10000) {
  888. setPollingDelay(10000);
  889. }
  890. }
  891. // Update orchestrator status - show "Running" only when there's actual activity
  892. // Don't distinguish between "Stopped" and "Idle" since orchestrator starts/stops frequently
  893. const dot = document.getElementById('orchestrator-dot');
  894. const text = document.getElementById('orchestrator-text');
  895. const pidEl = document.getElementById('orchestrator-pid');
  896. const hasWorkers = data.total_workers > 0;
  897. if (hasWorkers || hasActivity) {
  898. dot.classList.remove('stopped', 'idle');
  899. dot.classList.add('running');
  900. text.textContent = 'Running';
  901. } else {
  902. // No activity - show as idle (whether orchestrator process exists or not)
  903. dot.classList.remove('stopped', 'running');
  904. dot.classList.add('idle');
  905. text.textContent = 'Idle';
  906. }
  907. if (data.orchestrator_pid) {
  908. pidEl.textContent = `pid ${data.orchestrator_pid}`;
  909. pidEl.style.display = 'inline-flex';
  910. } else {
  911. pidEl.textContent = '';
  912. pidEl.style.display = 'none';
  913. }
  914. // Pulse the dot to show we got fresh data
  915. dot.classList.add('flash');
  916. setTimeout(() => dot.classList.remove('flash'), 300);
  917. // Update stats
  918. document.getElementById('worker-count').textContent = data.total_workers;
  919. document.getElementById('total-queued').textContent =
  920. data.crawls_pending + data.snapshots_pending + data.archiveresults_pending;
  921. // Store raw values and display relative to baseline
  922. lastSucceeded = data.archiveresults_succeeded;
  923. lastFailed = data.archiveresults_failed;
  924. // If baseline is higher than current (e.g. after DB reset), reset baseline
  925. if (succeededBaseline > lastSucceeded) {
  926. succeededBaseline = 0;
  927. localStorage.setItem('progress-succeeded-baseline', '0');
  928. }
  929. if (failedBaseline > lastFailed) {
  930. failedBaseline = 0;
  931. localStorage.setItem('progress-failed-baseline', '0');
  932. }
  933. document.getElementById('total-succeeded').textContent = lastSucceeded - succeededBaseline;
  934. document.getElementById('total-failed').textContent = lastFailed - failedBaseline;
  935. // Render crawl tree
  936. if (data.active_crawls.length > 0) {
  937. idleMessage.style.display = 'none';
  938. crawlTree.innerHTML = data.active_crawls.map(c => renderCrawl(c)).join('');
  939. } else if (hasActivity) {
  940. idleMessage.style.display = 'none';
  941. crawlTree.innerHTML = `
  942. <div class="idle-message">
  943. ${data.snapshots_started || 0} snapshots processing, ${data.archiveresults_started || 0} extractors running
  944. </div>
  945. `;
  946. } else {
  947. idleMessage.style.display = '';
  948. // Build the URL for recent crawls (last 24 hours)
  949. var yesterday = new Date(Date.now() - 24*60*60*1000).toISOString().split('T')[0];
  950. var recentUrl = '/admin/crawls/crawl/?created_at__gte=' + yesterday + '&o=-1';
  951. idleMessage.innerHTML = `No active crawls (${data.crawls_pending || 0} pending, ${data.crawls_started || 0} started, <a href="${recentUrl}" style="color: #58a6ff;">${data.crawls_recent || 0} recent</a>)`;
  952. crawlTree.innerHTML = '';
  953. }
  954. // Update thumbnail strip with recently completed results
  955. updateThumbnails(data.recent_thumbnails || []);
  956. }
  957. function fetchProgress() {
  958. fetch('/admin/live-progress/')
  959. .then(response => response.json())
  960. .then(data => {
  961. if (data.error) {
  962. console.error('Progress API error:', data.error, data.traceback);
  963. idleMessage.textContent = 'API Error: ' + data.error;
  964. idleMessage.style.color = '#f85149';
  965. }
  966. updateProgress(data);
  967. })
  968. .catch(error => {
  969. console.error('Progress fetch error:', error);
  970. idleMessage.textContent = 'Fetch Error: ' + error.message;
  971. idleMessage.style.color = '#f85149';
  972. });
  973. }
  974. function startPolling() {
  975. if (pollInterval) return;
  976. fetchProgress();
  977. pollInterval = setInterval(fetchProgress, pollDelayMs);
  978. }
  979. function stopPolling() {
  980. if (pollInterval) {
  981. clearInterval(pollInterval);
  982. pollInterval = null;
  983. }
  984. }
  985. function setPollingDelay(ms) {
  986. pollDelayMs = ms;
  987. if (pollInterval) {
  988. clearInterval(pollInterval);
  989. pollInterval = setInterval(fetchProgress, pollDelayMs);
  990. }
  991. }
  992. function setCollapsedState(collapsed, persist = true) {
  993. isCollapsed = collapsed;
  994. if (persist) {
  995. localStorage.setItem('progress-monitor-collapsed', isCollapsed);
  996. }
  997. if (isCollapsed) {
  998. monitor.classList.add('collapsed');
  999. collapseBtn.textContent = 'Expand';
  1000. } else {
  1001. monitor.classList.remove('collapsed');
  1002. collapseBtn.textContent = 'Details';
  1003. }
  1004. }
  1005. function setCancelButtonState(btn, busy) {
  1006. if (!btn) return;
  1007. const label = btn.dataset.label || '✕';
  1008. btn.disabled = !!busy;
  1009. btn.classList.toggle('is-busy', !!busy);
  1010. btn.textContent = busy ? '…' : label;
  1011. }
  1012. function cancelCrawl(crawlId, btn) {
  1013. if (!crawlId) return;
  1014. if (!getApiKey()) {
  1015. console.warn('API key unavailable for this session.');
  1016. setCancelButtonState(btn, false);
  1017. return;
  1018. }
  1019. setCancelButtonState(btn, true);
  1020. fetch(buildApiUrl(`/api/v1/crawls/crawl/${crawlId}`), {
  1021. method: 'PATCH',
  1022. headers: buildApiHeaders(),
  1023. body: JSON.stringify({ status: 'sealed', retry_at: null }),
  1024. })
  1025. .then(response => response.json())
  1026. .then(data => {
  1027. if (data.error) {
  1028. console.error('Cancel crawl error:', data.error);
  1029. }
  1030. fetchProgress();
  1031. })
  1032. .catch(error => {
  1033. console.error('Cancel crawl failed:', error);
  1034. setCancelButtonState(btn, false);
  1035. });
  1036. }
  1037. function cancelSnapshot(snapshotId, btn) {
  1038. if (!snapshotId) return;
  1039. if (!getApiKey()) {
  1040. console.warn('API key unavailable for this session.');
  1041. setCancelButtonState(btn, false);
  1042. return;
  1043. }
  1044. setCancelButtonState(btn, true);
  1045. fetch(buildApiUrl(`/api/v1/core/snapshot/${snapshotId}`), {
  1046. method: 'PATCH',
  1047. headers: buildApiHeaders(),
  1048. body: JSON.stringify({ status: 'sealed', retry_at: null }),
  1049. })
  1050. .then(response => response.json())
  1051. .then(data => {
  1052. if (data.error) {
  1053. console.error('Cancel snapshot error:', data.error);
  1054. }
  1055. fetchProgress();
  1056. })
  1057. .catch(error => {
  1058. console.error('Cancel snapshot failed:', error);
  1059. setCancelButtonState(btn, false);
  1060. });
  1061. }
  1062. // Collapse toggle
  1063. collapseBtn.addEventListener('click', function() {
  1064. setCollapsedState(!isCollapsed);
  1065. });
  1066. crawlTree.addEventListener('click', function(event) {
  1067. const btn = event.target.closest('.cancel-item-btn');
  1068. if (!btn) return;
  1069. event.preventDefault();
  1070. event.stopPropagation();
  1071. const cancelType = btn.dataset.cancelType;
  1072. if (cancelType === 'crawl') {
  1073. cancelCrawl(btn.dataset.crawlId, btn);
  1074. } else if (cancelType === 'snapshot') {
  1075. cancelSnapshot(btn.dataset.snapshotId, btn);
  1076. }
  1077. });
  1078. // Apply initial state
  1079. if (isCollapsed) {
  1080. setCollapsedState(true, false);
  1081. }
  1082. // Start polling when page loads
  1083. startPolling();
  1084. // Pause polling when tab is hidden
  1085. document.addEventListener('visibilitychange', function() {
  1086. if (document.hidden) {
  1087. stopPolling();
  1088. } else {
  1089. startPolling();
  1090. }
  1091. });
  1092. })();
  1093. </script>