|
376 | 376 | let onHashUpdate = [];
|
377 | 377 |
|
378 | 378 | let latest_hash = "";
|
| 379 | + |
379 | 380 | const getLatestHash = async () => {
|
380 |
| - fetch( |
381 |
| - `https://api.github.com/repos/plugdata-team/plugdata/commits/develop`, |
382 |
| - ) |
383 |
| - .then((response) => response.json()) |
384 |
| - .then((data) => { |
385 |
| - latest_hash = data.sha; |
386 |
| - console.log("Last Commit Hash:", latest_hash); |
387 |
| - for (let i = 0; i < onHashUpdate.length; i++) { |
388 |
| - onHashUpdate[i](); |
389 |
| - } |
390 |
| - }) |
391 |
| - .catch((error) => console.error("Error:", error)); |
| 381 | + try { |
| 382 | + const response = await fetch( |
| 383 | + `https://api.github.com/repos/plugdata-team/plugdata/commits/develop`, |
| 384 | + ); |
| 385 | + const data = await response.json(); |
| 386 | + latest_hash = data.sha; |
| 387 | + console.log("Last Commit Hash:", latest_hash); |
| 388 | + onHashUpdate.forEach((fn) => fn()); |
| 389 | + } catch (error) { |
| 390 | + console.error("Error:", error); |
| 391 | + } |
392 | 392 | };
|
393 | 393 |
|
394 | 394 | const table = document.getElementById("nightly-table");
|
395 | 395 |
|
396 |
| - for (let i = 0; i < unstable_downloads.length; i++) { |
| 396 | + const getDownloadInfo = async (download, i) => { |
397 | 397 | const downloadRow = document.createElement("tr");
|
398 | 398 |
|
399 | 399 | let name = document.createElement("td");
|
400 |
| - name.textContent = unstable_downloads[i][0]; |
| 400 | + name.textContent = download[0]; |
401 | 401 |
|
402 | 402 | let link = document.createElement("td");
|
403 | 403 | let clickableLink = document.createElement("a");
|
404 | 404 |
|
405 |
| - clickableLink.href = unstable_downloads[i][1]; |
406 |
| - clickableLink.textContent = unstable_downloads[i][2]; |
| 405 | + clickableLink.href = download[1]; |
| 406 | + clickableLink.textContent = download[2]; |
407 | 407 | link.appendChild(clickableLink);
|
408 | 408 |
|
409 |
| - let has_info = unstable_downloads[i][3]; |
410 |
| - |
411 | 409 | const dummy1 = document.createElement("td");
|
412 | 410 | const dummy2 = document.createElement("td");
|
413 | 411 |
|
|
416 | 414 | downloadRow.appendChild(dummy2);
|
417 | 415 | downloadRow.appendChild(link);
|
418 | 416 |
|
419 |
| - const getDownloadInfo = async () => { |
420 |
| - let url = unstable_downloads[i][1] + ".txt"; |
| 417 | + table.appendChild(downloadRow); |
| 418 | + |
| 419 | + if (!download[3]) return; |
| 420 | + |
| 421 | + try { |
| 422 | + let url = download[1] + ".txt"; |
421 | 423 | console.log(url);
|
422 | 424 | let response = await fetch(url);
|
423 |
| - const result = await response.text().then((str) => { |
424 |
| - return str.split("\n"); // return the string after splitting it. |
425 |
| - }); |
| 425 | + let result = await response.text(); |
| 426 | + result = result.split("\n"); |
426 | 427 |
|
427 |
| - // Create new cells and set their content |
| 428 | + // Create new cells |
428 | 429 | const date = document.createElement("td");
|
429 | 430 | date.textContent = result[0];
|
430 | 431 | date.style.minWidth = "200px";
|
431 | 432 |
|
432 | 433 | const hash = result[1];
|
433 |
| - let color = hash == latest_hash ? "#006400" : "#FFA500"; |
434 |
| - |
435 | 434 | const commit_hash = document.createElement("td");
|
436 | 435 | const commit_link = document.createElement("a");
|
437 | 436 |
|
438 | 437 | commit_link.textContent = hash.substring(0, 7);
|
439 |
| - commit_link.style.cssText = `color: ${color}`; |
440 |
| - commit_link.href = |
441 |
| - "https://github.com/plugdata-team/plugdata/commits/" + |
442 |
| - hash; |
| 438 | + commit_link.href = `https://github.com/plugdata-team/plugdata/commits/${hash}`; |
443 | 439 | commit_hash.appendChild(commit_link);
|
444 | 440 |
|
445 |
| - onHashUpdate.push(() => { |
446 |
| - let color = |
447 |
| - hash == latest_hash ? "#006400" : "#FFA500"; |
448 |
| - commit_hash.style.cssText = `color: ${color}`; |
449 |
| - console.log( |
450 |
| - hash == latest_hash |
451 |
| - ? "hash was equal" |
452 |
| - : "hash was not equal", |
453 |
| - ); |
454 |
| - }); |
455 |
| - |
456 |
| - downloadRow.removeChild(name); |
457 |
| - downloadRow.removeChild(dummy1); |
458 |
| - downloadRow.removeChild(dummy2); |
459 |
| - downloadRow.removeChild(link); |
| 441 | + // Set initial color (will update later) |
| 442 | + const updateColor = () => { |
| 443 | + const color = |
| 444 | + hash === latest_hash ? "#006400" : "#FFA500"; |
| 445 | + commit_link.style.cssText = `color: ${color}`; |
| 446 | + }; |
| 447 | + updateColor(); // set now |
| 448 | + onHashUpdate.push(updateColor); // also set later |
460 | 449 |
|
461 |
| - // Append the cells to the row |
| 450 | + // Replace old cells |
| 451 | + downloadRow.innerHTML = ""; |
462 | 452 | downloadRow.appendChild(name);
|
463 | 453 | downloadRow.appendChild(date);
|
464 | 454 | downloadRow.appendChild(commit_hash);
|
465 | 455 | downloadRow.appendChild(link);
|
466 |
| - }; |
467 |
| - |
468 |
| - if (has_info) { |
469 |
| - getDownloadInfo(); |
| 456 | + } catch (e) { |
| 457 | + console.error( |
| 458 | + "Error fetching info for", |
| 459 | + download[0], |
| 460 | + e, |
| 461 | + ); |
470 | 462 | }
|
| 463 | + }; |
471 | 464 |
|
472 |
| - // Append the row to the table |
473 |
| - table.appendChild(downloadRow); |
474 |
| - } |
| 465 | + // Main loop: fetch all info |
| 466 | + const promises = unstable_downloads.map((download, i) => |
| 467 | + getDownloadInfo(download, i), |
| 468 | + ); |
475 | 469 |
|
476 |
| - getLatestHash(); |
| 470 | + // After all info is fetched, get the latest hash |
| 471 | + Promise.all(promises).then(() => getLatestHash()); |
477 | 472 | }
|
478 | 473 |
|
479 | 474 | main();
|
|
0 commit comments