@gorlitzer-labs/seldon 0.17.0 → 0.17.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.
package/bin/seldon.js CHANGED
@@ -15,7 +15,7 @@ import { startLane, stopLane, resumeLane, removeLane, findLane } from "../lib/ac
15
15
  import { listMachines, addMachine, fetchLanes, remoteGroups, sshArgs, lastJsonLine } from "../lib/machines.mjs";
16
16
  import { notify } from "../lib/notify.mjs";
17
17
  import { serve, serveToken, ownerFromStatus } from "../lib/serve.mjs";
18
- import { sendCard, watchCard, KINDS, tokenName, readChat, writeChat, chatFromUpdates, getUpdates, sendText, sendFile, pollUpdates, fileFromMessage, inboxName, noteLine, downloadFile, react, MAX_DOWNLOAD } from "../lib/telegram.mjs";
18
+ import { sendCard, watchCard, KINDS, tokenName, readChat, writeChat, chatFromUpdates, getUpdates, sendText, sendFile, pollUpdates, fileFromMessage, inboxName, freeName, noteLine, downloadFile, react, MAX_DOWNLOAD } from "../lib/telegram.mjs";
19
19
  import { reportFromEvent, mergeCodexHooks, removeCodexHooks, opencodePlugin } from "../lib/reports.mjs";
20
20
  import { buildRows, headline, ago, laneDetail, unlistedAgents, GLYPH } from "../lib/home.mjs";
21
21
  import { parseDuration, describe as describeHold, NAME_RE, DEFAULT_FOR_MS } from "../lib/holds.mjs";
@@ -1680,7 +1680,7 @@ async function inboxCmd(flags) {
1680
1680
  try {
1681
1681
  if (f) {
1682
1682
  if (f.size && f.size > MAX_DOWNLOAD) throw new Error(`${f.name} is over 20 MB — a bot can't fetch it; share it another way`);
1683
- const name = inboxName(f.name, when);
1683
+ const name = freeName(inboxName(f.name, when), (n) => fs.existsSync(path.join(dir, n)));
1684
1684
  await downloadFile(t.token, f.fileId, path.join(dir, name));
1685
1685
  fs.appendFileSync(path.join(dir, "notes.md"), noteLine(when, { file: name, text }), { mode: 0o600 });
1686
1686
  console.log(`${stamp()} saved ${name}`);
package/lib/telegram.mjs CHANGED
@@ -209,6 +209,14 @@ export function inboxName(name, date) {
209
209
  return `${d.getFullYear()}${p(d.getMonth() + 1)}${p(d.getDate())}-${p(d.getHours())}${p(d.getMinutes())}${p(d.getSeconds())}-${base}`;
210
210
  }
211
211
 
212
+ // A name not already in the folder: an album arrives as several files in the same second, so the second and later
213
+ // ones get -2, -3… before the extension (20261031-091502-photo-2.jpg). `taken` says whether a name is in use.
214
+ export function freeName(name, taken) {
215
+ if (!taken(name)) return name;
216
+ const dot = name.lastIndexOf("."), stem = dot > 0 ? name.slice(0, dot) : name, ext = dot > 0 ? name.slice(dot) : "";
217
+ for (let n = 2; ; n++) { const next = `${stem}-${n}${ext}`; if (!taken(next)) return next; }
218
+ }
219
+
212
220
  // One line in notes.md per thing received, so the folder reads as a log.
213
221
  export function noteLine(date, { file, text }) {
214
222
  const d = new Date(date), p = (n) => String(n).padStart(2, "0");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gorlitzer-labs/seldon",
3
- "version": "0.17.0",
3
+ "version": "0.17.1",
4
4
  "description": "Install the Seldon stack — pick your tools from a checklist; each installs via its native method.",
5
5
  "type": "module",
6
6
  "bin": {