@decentnetwork/beagle 0.1.65 → 0.1.66

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.
@@ -1,4 +1,4 @@
1
- window.__DK_UI_VERSION="0.1.65";
1
+ window.__DK_UI_VERSION="0.1.66";
2
2
  "use strict";
3
3
  (() => {
4
4
  // packages/beagle-ui/dist/beagle-ui.js
package/dist/server.js CHANGED
@@ -1582,15 +1582,28 @@ export function startBeagleServer(opts) {
1582
1582
  // ── self-update: check (cached), run (localhost), restart (localhost) ──
1583
1583
  if (req.method === "GET" && url === "/api/update-check") {
1584
1584
  const force = new URL(req.url || "", "http://localhost").searchParams.get("force") === "1";
1585
- if (!force && updateCache && Date.now() - updateCache.at < UPDATE_TTL_MS) {
1586
- sendJson(res, 200, updateCache.body);
1587
- return;
1588
- }
1589
- const [beagleLatest, peerLatest, lanLatest] = await Promise.all([
1590
- npmLatest(BEAGLE_PKG),
1591
- npmLatest("@decentnetwork/peer"),
1592
- npmLatest("@decentnetwork/lan"),
1593
- ]);
1585
+ // Cache the REGISTRY lookups, never the answer. The whole body used to
1586
+ // be cached for six hours, and it is only invalidated by updating
1587
+ // THROUGH this app — so someone who ran the terminal command the card
1588
+ // itself told them to run saw the same "update available" for the rest
1589
+ // of the day, no matter how many times they ran it. The card sent
1590
+ // people in a loop it was creating.
1591
+ //
1592
+ // What is actually slow and rate-limited is npm; the running versions
1593
+ // come from the daemon and are already cached for 30s. So the rows are
1594
+ // rebuilt every call and only `latest` is held.
1595
+ if (force)
1596
+ updateCache = null;
1597
+ const cachedLatest = updateCache && Date.now() - updateCache.at < UPDATE_TTL_MS
1598
+ ? updateCache.body.latest
1599
+ : undefined;
1600
+ const [beagleLatest, peerLatest, lanLatest] = cachedLatest
1601
+ ? [cachedLatest.beagle ?? null, cachedLatest.peer ?? null, cachedLatest.lan ?? null]
1602
+ : await Promise.all([
1603
+ npmLatest(BEAGLE_PKG),
1604
+ npmLatest("@decentnetwork/peer"),
1605
+ npmLatest("@decentnetwork/lan"),
1606
+ ]);
1594
1607
  const running = await runningVersions(opts.call);
1595
1608
  const curLan = running.lanVer || (opts.meExtra?.lanVer ?? "");
1596
1609
  const row = (pkg, current, latest) => ({
@@ -1617,7 +1630,15 @@ export function startBeagleServer(opts) {
1617
1630
  ...(curLan && curLan !== "(none)" ? [row("@decentnetwork/lan", curLan, lanLatest)] : []),
1618
1631
  ],
1619
1632
  };
1620
- updateCache = { at: Date.now(), body };
1633
+ // Keep only what npm told us, and only when it actually answered.
1634
+ // Caching a failed lookup as "null" would pin the panel to "up to
1635
+ // date" for six hours after one flaky request.
1636
+ if (!cachedLatest && (beagleLatest || peerLatest || lanLatest)) {
1637
+ updateCache = {
1638
+ at: Date.now(),
1639
+ body: { latest: { beagle: beagleLatest, peer: peerLatest, lan: lanLatest } },
1640
+ };
1641
+ }
1621
1642
  sendJson(res, 200, body);
1622
1643
  return;
1623
1644
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decentnetwork/beagle",
3
- "version": "0.1.65",
3
+ "version": "0.1.66",
4
4
  "description": "Beagle — P2P chat, file transfer and calls for regular users, on the Decent Network. No admin privilege required.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",