clavarium 0.2.104-beta.1 → 0.2.105-beta.1

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.
@@ -962,7 +962,7 @@ case "$AREA $VERB" in
962
962
  # WHAT THE SERVER'S PROGRAMS SAID, for Settings (This server, Logs): one
963
963
  # source, over a span; read-only, bounded. The page masks what looks
964
964
  # like a secret before showing it.
965
- # server logs <clavarium|machines|updates|web|signin|tunnel|system> <1|6|24|168|boot>
965
+ # server logs <clavarium|machines|updates|web|signin|tunnel|system> <10m|1|6|24|168|boot>
966
966
  [ $# -eq 2 ] || usage
967
967
  case "$1" in
968
968
  clavarium) units=(-u clavarium.service -u 'clavarium-view-*' -u clavarium-tools-view.service -u clavarium-move-machines.service) ;;
@@ -974,9 +974,10 @@ case "$AREA $VERB" in
974
974
  system) units=(-k) ;;
975
975
  *) refuse "not a source of logs: $1" ;;
976
976
  esac
977
- case "$2" in 1|6|24|168) since=(--since "-$2h") ;; boot) since=(-b) ;; *) refuse "not a span: $2 (1, 6, 24, 168 hours, or boot)" ;; esac
978
- if [ "$SAY" = "yes" ]; then echo "journalctl ${units[*]} ${since[*]} -o short-iso --no-pager (the last 200000 lines)"; exit 0; fi
979
- journalctl "${units[@]}" "${since[@]}" -o short-iso --no-pager -n 200000 2>/dev/null | cut -c1-2000 || true
977
+ case "$2" in 10m) since=(--since "-10min") ;; 1|6|24|168) since=(--since "-$2h") ;; boot) since=(-b) ;; *) refuse "not a span: $2 (10m, 1, 6, 24, 168 hours, or boot)" ;; esac
978
+ # The newest 20000 lines at most: more is too much to read on a page, and to send.
979
+ if [ "$SAY" = "yes" ]; then echo "journalctl ${units[*]} ${since[*]} -o short-iso --no-pager (the last 20000 lines)"; exit 0; fi
980
+ journalctl "${units[@]}" "${since[@]}" -o short-iso --no-pager -n 20000 2>/dev/null | cut -c1-2000 || true
980
981
  exit 0 ;;
981
982
  "server restart")
982
983
  # THIS SERVER STARTED AGAIN, asked from the page: in two seconds, by
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "clavarium",
3
- "version": "0.2.104-beta.1",
3
+ "version": "0.2.105-beta.1",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "clavarium",
9
- "version": "0.2.104-beta.1",
9
+ "version": "0.2.105-beta.1",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@xterm/addon-fit": "^0.11.0",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clavarium",
3
- "version": "0.2.104-beta.1",
3
+ "version": "0.2.105-beta.1",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "description": "A conversation is a VM with a terminal in it. Everything else is a folder.",
@@ -11,8 +11,10 @@
11
11
  import { Refusal } from './conversations.mjs';
12
12
 
13
13
  export const SOURCES = ['clavarium', 'machines', 'updates', 'web', 'signin', 'tunnel', 'system'];
14
- export const SPANS = ['1', '6', '24', '168', 'boot'];
15
- const TEXT_MAX = 24 * 1024 * 1024;
14
+ export const SPANS = ['10m', '1', '6', '24', '168', 'boot'];
15
+ /* What a page reads at once: masking and sending more held this server for seconds (found 31-10:
16
+ the front then said "being updated" to every other page meanwhile). The newest are kept. */
17
+ const TEXT_MAX = 4 * 1024 * 1024;
16
18
 
17
19
  const NAMED = /\b(password|passwd|passphrase|secret|token|api[_-]?key|authorization|cookie|bearer|client[_-]?secret)(["']?\s*[=:]\s*|\s+)("[^"]*"|'[^']*'|\S+)/gi;
18
20
  const LONG = /[A-Za-z0-9_+/=]{32,}/g;
@@ -25,7 +27,7 @@ export class ServerLogs {
25
27
  constructor({ host }) { this.#host = host; }
26
28
  async read(source, span) {
27
29
  if (!SOURCES.includes(source)) throw new Refusal(400, `Not a source of logs: say one of ${SOURCES.join(', ')}.`);
28
- if (!SPANS.includes(String(span))) throw new Refusal(400, 'Not a span: 1, 6, 24 or 168 hours, or since the server started (boot).');
30
+ if (!SPANS.includes(String(span))) throw new Refusal(400, 'Not a span: 10 minutes (10m), 1, 6, 24 or 168 hours, or since the server started (boot).');
29
31
  const r = await this.#host(['server', 'logs', source, String(span)], { timeoutMs: 120_000, maxBytes: TEXT_MAX * 2 });
30
32
  if (r.code !== 0) throw new Refusal(502, `The logs could not be read: ${String(r.stderr ?? '').trim().split('\n').pop()?.replace(/^REFUSED: /, '').slice(0, 200) || `exit ${r.code}`}`);
31
33
  let text = String(r.stdout ?? '');
package/web/app.js CHANGED
@@ -980,9 +980,13 @@
980
980
  pointManifest(installName());
981
981
 
982
982
  /* ---------- the list ---------- */
983
+ /* THE FRONT'S "NO ANSWER" (503, down): the server was busy a moment, or restarting -- it does
984
+ not know which. Said as busy, never as an update (#220); a read is tried again by itself. */
985
+ const BUSY = 'The server is busy just now: try again in a moment.';
983
986
  const post = async (path, body) => {
984
987
  const r = await fetch(path, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(body ?? {}) });
985
988
  const j = await r.json().catch(() => ({}));
989
+ if (!r.ok && r.status === 503 && j.down === true) throw Object.assign(new Error(BUSY), { retry: true });
986
990
  if (!r.ok) throw Object.assign(new Error(j.error || 'The request failed.'), { kind: j.kind, retry: j.retry === true });
987
991
  return j;
988
992
  };
@@ -3296,7 +3300,30 @@
3296
3300
  /* Adding to a type category of live links (a calendar, an address book, an
3297
3301
  access) is connecting an account: they all open the connect-account form. */
3298
3302
  const addForm = (k) => (['agenda', 'contacts', 'acces'].includes(k) ? 'connexion' : k);
3299
- const getJson = (path, fallback) => fetch(`${API}${path}`).then((r) => (r.ok ? r.json() : fallback)).catch(() => fallback);
3303
+ /* Its answer, or { state: 'error', message }: the server's own words, or busy (asked again first). */
3304
+ const readOrSay = async (path) => {
3305
+ for (let i = 0; i < 3; i++) {
3306
+ try {
3307
+ const r = await fetch(`${API}${path}`);
3308
+ const j = await r.json().catch(() => ({}));
3309
+ if (r.ok) return j;
3310
+ if (!(r.status === 503 && j.down === true)) return { state: 'error', message: j.error || 'It could not be read.' };
3311
+ } catch { return { state: 'error', message: 'It could not be read.' }; }
3312
+ await new Promise((ok) => setTimeout(ok, 1500 * (i + 1)));
3313
+ }
3314
+ return { state: 'error', message: BUSY };
3315
+ };
3316
+ const getJson = async (path, fallback) => {
3317
+ for (let i = 0; i < 3; i++) {
3318
+ try {
3319
+ const r = await fetch(`${API}${path}`);
3320
+ if (r.ok) return await r.json();
3321
+ if (r.status !== 503) return fallback;
3322
+ } catch { return fallback; }
3323
+ await new Promise((ok) => setTimeout(ok, 1500 * (i + 1))); /* busy a moment: asked again */
3324
+ }
3325
+ return fallback;
3326
+ };
3300
3327
  const el = (tag, cls, text) => { const e = document.createElement(tag); if (cls) e.className = cls; if (text !== undefined) e.textContent = text; return e; };
3301
3328
  /* A commit: its line, and the rest of its message under it, opened by a click. */
3302
3329
  function commitRow(c) {
@@ -3728,7 +3755,7 @@
3728
3755
  const query = new URLSearchParams();
3729
3756
  if (r.branch) query.set('branch', r.branch);
3730
3757
  if (r.target) query.set('target', r.target);
3731
- const [out, keep] = await Promise.all([fetch(`${API}/git/${r.name}/outgoing${query.size ? `?${query}` : ''}`).then(async (x) => { const j = await x.json().catch(() => ({})); return x.ok ? j : { state: 'error', message: j.error || 'It could not be read.' }; }).catch(() => ({ state: 'error', message: 'It could not be read.' })), r.keep ? r.keep : getJson(`/git/${r.name}/keep`, null)]);
3758
+ const [out, keep] = await Promise.all([readOrSay(`/git/${r.name}/outgoing${query.size ? `?${query}` : ''}`), r.keep ? r.keep : getJson(`/git/${r.name}/keep`, null)]);
3732
3759
  r.out = out; r.keep = keep; r.branch = out.branch ?? r.branch; r.target = out.target ?? r.target; r.check = null;
3733
3760
  /* What the server knows of this very commit and target: a check still running is followed again; the last
3734
3761
  one that ran is shown with its age (left and come back, even the next day: nothing run again for nothing). */
package/web/index.html CHANGED
@@ -965,9 +965,10 @@
965
965
  <option value="tunnel">Tunnel</option>
966
966
  </select></label>
967
967
  <label>Over <select id="logs-span" class="pill">
968
+ <option value="10m" selected>the last 10 minutes</option>
968
969
  <option value="1">the last hour</option>
969
970
  <option value="6">the last 6 hours</option>
970
- <option value="24" selected>the last 24 hours</option>
971
+ <option value="24">the last 24 hours</option>
971
972
  <option value="168">the last 7 days</option>
972
973
  <option value="boot">since the server started</option>
973
974
  </select></label>