@needmoretruth/nmts-cli 0.44.0 → 0.45.0

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.
Files changed (45) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.ko.md +1 -1
  3. package/README.md +1 -1
  4. package/dist/arg-options.d.ts +6 -0
  5. package/dist/args.js +4 -1
  6. package/dist/artifact-about.d.ts +1 -1
  7. package/dist/commands/get.d.ts +2 -0
  8. package/dist/commands/get.js +13 -1
  9. package/dist/commands/ls.d.ts +2 -0
  10. package/dist/commands/ls.js +18 -5
  11. package/dist/commands/put-thumbnail.d.ts +4 -0
  12. package/dist/commands/put-thumbnail.js +119 -0
  13. package/dist/commands/put-wallet.d.ts +2 -0
  14. package/dist/commands/put-wallet.js +3 -2
  15. package/dist/commands/put.d.ts +8 -0
  16. package/dist/commands/put.js +5 -0
  17. package/dist/drive-edit/trash.js +5 -3
  18. package/dist/drive-edit/tree.d.ts +6 -0
  19. package/dist/drive-edit/tree.js +10 -0
  20. package/dist/drive-erase.js +2 -2
  21. package/dist/drive-paths.d.ts +2 -2
  22. package/dist/drive-paths.js +2 -2
  23. package/dist/help-options.js +4 -0
  24. package/dist/main.js +3 -0
  25. package/dist/mcp-tools/files.js +21 -2
  26. package/dist/mcp-tools/reads.js +9 -1
  27. package/dist/portable.d.ts +2 -1
  28. package/dist/portable.js +2 -1
  29. package/dist/product.d.ts +1 -1
  30. package/dist/product.js +1 -1
  31. package/dist/shared/lib/drive/manifest-codec.d.ts +11 -31
  32. package/dist/shared/lib/drive/manifest-codec.js +15 -23
  33. package/dist/shared/lib/drive/manifest-index.d.ts +10 -1
  34. package/dist/shared/lib/drive/manifest-index.js +30 -8
  35. package/dist/shared/lib/drive/manifest-wire-extras.d.ts +50 -0
  36. package/dist/shared/lib/drive/manifest-wire-extras.js +65 -0
  37. package/dist/shared/lib/drive/preview-classify.d.ts +17 -0
  38. package/dist/shared/lib/drive/preview-classify.js +96 -0
  39. package/dist/upload-wallet-put.d.ts +2 -0
  40. package/dist/upload-wallet-put.js +1 -0
  41. package/docs/commands/get.md +3 -0
  42. package/docs/commands/ls.md +5 -0
  43. package/docs/commands/put.md +8 -0
  44. package/package.json +1 -1
  45. package/server.json +2 -2
package/CHANGELOG.md CHANGED
@@ -3,6 +3,18 @@
3
3
  Each version's entry is what changed for the person or the program using `nmts`. The product's own
4
4
  update history, which covers the site and the server too, is at https://nmts.me/updates.
5
5
 
6
+ ## 0.45.0 — 2026-09-24
7
+
8
+ - **Video preview pictures.** `nmts put <video> --thumbnail` takes one frame with ffmpeg, when it is
9
+ on your PATH, and uploads it beside the video as an ordinary small file linked to it; without
10
+ ffmpeg the video goes alone and `nmts` says why. `--thumbnail-file <picture>` hands in a picture
11
+ you made yourself. The picture is priced, encrypted and paid for like any other file.
12
+ - `nmts get <video> --thumbnail` fetches the picture instead of the video.
13
+ - `nmts ls --media` lists one kind of file. A preview picture is listed on its own only when its
14
+ video is gone.
15
+ - Moving a video to the trash, restoring it and erasing it take its picture with it.
16
+ - The MCP tools take the same options.
17
+
6
18
  ## 0.44.0 — 2026-09-23
7
19
 
8
20
  - **Recovery phrase.** An NMTS key can be written as 15 words from the BIP-39 English or Korean word
package/README.ko.md CHANGED
@@ -50,7 +50,7 @@ nmts --help
50
50
 
51
51
  ```sh
52
52
  npm install -g github:needmoretruth/nmts-cli # 기본 브랜치
53
- npm install -g github:needmoretruth/nmts-cli#v0.44.0 # 버전을 고정할 때
53
+ npm install -g github:needmoretruth/nmts-cli#v0.45.0 # 버전을 고정할 때
54
54
  npm install -g https://github.com/needmoretruth/nmts-cli/releases/latest/download/nmts.tgz
55
55
  ```
56
56
 
package/README.md CHANGED
@@ -51,7 +51,7 @@ default branch, from a pinned version, or from the tarball attached to the
51
51
 
52
52
  ```sh
53
53
  npm install -g github:needmoretruth/nmts-cli # the default branch
54
- npm install -g github:needmoretruth/nmts-cli#v0.44.0 # a pinned version
54
+ npm install -g github:needmoretruth/nmts-cli#v0.45.0 # a pinned version
55
55
  npm install -g https://github.com/needmoretruth/nmts-cli/releases/latest/download/nmts.tgz
56
56
  ```
57
57
 
@@ -20,6 +20,12 @@ export interface ParsedArgs {
20
20
  to?: string;
21
21
  /** Say what an upload would cost and stop. */
22
22
  dryRun: boolean;
23
+ /** `put`: send a video's preview picture with it (a frame from ffmpeg) · `get`: fetch only that picture. */
24
+ thumbnail: boolean;
25
+ /** `put`: the picture to send as the video's preview, instead of a frame from ffmpeg. */
26
+ thumbnailFile?: string;
27
+ /** `ls`: only files of this kind — image, video or audio. */
28
+ media?: string;
23
29
  /** `put`: how much of a file goes into one part. A byte count, optionally with a unit. */
24
30
  partSize?: string;
25
31
  /** `put`/`push`: what THIS run does about a name already in use. Absent = this machine's setting. */
package/dist/args.js CHANGED
@@ -19,6 +19,8 @@ const VALUE_OPTIONS = {
19
19
  "--on-collision": "onCollision",
20
20
  "--deposit": "deposit",
21
21
  "--find": "find",
22
+ "--thumbnail-file": "thumbnailFile",
23
+ "--media": "media",
22
24
  "--sort": "sort",
23
25
  "--epochs": "epochs",
24
26
  "--pay": "pay",
@@ -92,6 +94,7 @@ const FLAG_OPTIONS = {
92
94
  "--all": "all",
93
95
  "--force": "force",
94
96
  "--dry-run": "dryRun",
97
+ "--thumbnail": "thumbnail",
95
98
  "--yes": "yes",
96
99
  "-y": "yes",
97
100
  "--publish": "publish",
@@ -146,7 +149,7 @@ function append(parsed, field, value) {
146
149
  * time, because a shape the compiler cannot see would let a new flag arrive as `undefined`.
147
150
  */
148
151
  const FLAG_DEFAULTS = {
149
- help: false, version: false, json: false, all: false, force: false, dryRun: false, releaseStorage: false,
152
+ help: false, version: false, json: false, all: false, force: false, dryRun: false, thumbnail: false, releaseStorage: false,
150
153
  yes: false, publish: false, plain: false, env: false, status: false,
151
154
  desc: false, hidden: false, reveal: false, phrase: false, print: false, qr: false, board: false,
152
155
  save: false, acceptExtremes: false, remove: false, noWait: false, trustServerTipAddress: false,
@@ -11,7 +11,7 @@ export declare const CRYPTO_SPEC_URL = "https://github.com/needmoretruth/nmts-re
11
11
  * is the field's own contract — what the writer says about itself — and a person holding two
12
12
  * copies of one account's artefacts can then tell which program made each.
13
13
  */
14
- export declare const WRITTEN_BY = "nmts-cli 0.44.0";
14
+ export declare const WRITTEN_BY = "nmts-cli 0.45.0";
15
15
  /** Which of the three artefacts a wrapper is. A reader holding several can sort them. */
16
16
  export type ArtifactKind = "recovery-list" | "file-list" | "recovery-kit";
17
17
  /**
@@ -11,6 +11,8 @@ export interface GetOptions {
11
11
  /** Overwrite an existing file. Off by default, and saying so is the point. */
12
12
  force?: boolean;
13
13
  json?: boolean;
14
+ /** Fetch the video's preview picture — the small JPEG uploaded with it — instead of the video. */
15
+ thumbnail?: boolean;
14
16
  write?: (line: string) => void;
15
17
  /** Where the file's own bytes go when `out` is `-`. Injectable so a test can read them. */
16
18
  stdout?: ByteDestination;
@@ -66,7 +66,9 @@ export async function get(target, options = {}) {
66
66
  const wanted = normalisePath(target);
67
67
  // ⚠ Looked up WITHOUT a kind filter on purpose: a path that names a folder must be told apart
68
68
  // from a path that names nothing, and a filtered lookup can only say "nothing is there".
69
- const entry = entryAt(list.manifest.entries, wanted, { nothingHappened: "Nothing was written." });
69
+ const named = entryAt(list.manifest.entries, wanted, { nothingHappened: "Nothing was written." });
70
+ // `--thumbnail`: the video's preview picture instead of the video.
71
+ const entry = options.thumbnail === true ? pictureOf(index, named) : named;
70
72
  if (entry.kind !== KIND_FILE) {
71
73
  throw new NmtsError(`No file at "${fullPathOf(index, entry)}".`, {
72
74
  exitCode: 4,
@@ -128,3 +130,13 @@ export async function get(target, options = {}) {
128
130
  }
129
131
  return 0;
130
132
  }
133
+ /** The preview picture uploaded with this video, or a refusal that says how one is made. */
134
+ function pictureOf(index, video) {
135
+ const picture = index.byId.get(index.previews.get(video.id)?.[0] ?? "");
136
+ if (picture !== undefined)
137
+ return picture;
138
+ throw new NmtsError(`"${fullPathOf(index, video)}" has no preview picture.`, {
139
+ exitCode: 4,
140
+ nextStep: `Nothing was written. \`${BINARY_NAME} put <video> --thumbnail\` sends one with a video.`,
141
+ });
142
+ }
@@ -5,6 +5,8 @@ export interface LsOptions {
5
5
  json?: boolean;
6
6
  /** Include entries that are in the trash. */
7
7
  all?: boolean;
8
+ /** Only files of this kind — `image`, `video` or `audio`, judged by name as the gallery does. */
9
+ media?: string | undefined;
8
10
  /**
9
11
  * Keep only files whose name contains this text, case-insensitively.
10
12
  *
@@ -17,8 +17,9 @@
17
17
  // line, not a failing account, so it costs no round trip and reads as exit 2 — otherwise an
18
18
  // agent that mistyped a key goes off investigating the account instead of its own arguments.
19
19
  import { CODE_ENV_VAR } from "../credentials.js";
20
- import { buildIndex, fullPathOf, isLive, KIND_FOLDER, trashedAt } from "../drive-paths.js";
20
+ import { buildIndex, fullPathOf, isLive, KIND_FOLDER, shown as inViews, trashedAt } from "../drive-paths.js";
21
21
  import { NmtsError } from "../errors.js";
22
+ import { classify } from "../shared/lib/drive/preview-classify.js";
22
23
  import { marksOf, markSuffix } from "../mark-render.js";
23
24
  import { idsForQuery, needleOf } from "../list-view-find.js";
24
25
  import { orderRows, parseSortKey } from "../list-view-order.js";
@@ -56,6 +57,8 @@ function byPath(rows, dir) {
56
57
  return dir === "desc" ? sorted.reverse() : sorted;
57
58
  }
58
59
  export async function ls(options = {}) {
60
+ // A kind that cannot mean anything is refused before the account is read.
61
+ const media = mediaOf(options.media);
59
62
  const say = options.write ?? ((line) => process.stdout.write(`${line}\n`));
60
63
  const now = options.now ?? Date.now();
61
64
  const dir = options.desc === true ? "desc" : "asc";
@@ -89,10 +92,12 @@ export async function ls(options = {}) {
89
92
  // built to avoid, and it shipped: `hiddenTrashed` said 1 while two unreachable files were
90
93
  // printed as live (2026-08-23).
91
94
  const index = buildIndex(list.manifest.entries);
92
- const listed = options.all
93
- ? list.manifest.entries
94
- : list.manifest.entries.filter((e) => isLive(index, e));
95
- const hidden = list.manifest.entries.length - listed.length;
95
+ // A video's preview picture is part of the video, never a line of its own — and it is
96
+ // not counted among what `--all` would add either.
97
+ const visible = list.manifest.entries.filter((e) => inViews(index, e));
98
+ const kept = media === null ? visible : visible.filter((e) => e.kind !== KIND_FOLDER && classify(e.name).kind === media);
99
+ const listed = options.all ? kept : kept.filter((e) => isLive(index, e));
100
+ const hidden = kept.length - listed.length;
96
101
  // The query runs over what was going to be shown, so `--find` and `--all` compose instead of one
97
102
  // quietly widening the other: a search without `--all` searches the drive, not the trash.
98
103
  const keep = needle === null ? null : idsForQuery(index, listed, needle);
@@ -200,3 +205,11 @@ export async function ls(options = {}) {
200
205
  }
201
206
  return 0;
202
207
  }
208
+ /** `--media`, checked: the three kinds the gallery and the music place gather, or null for all. */
209
+ function mediaOf(asked) {
210
+ if (asked === undefined)
211
+ return null;
212
+ if (asked === "image" || asked === "video" || asked === "audio")
213
+ return asked;
214
+ throw new NmtsError(`--media takes image, video or audio, not "${asked}".`, { exitCode: 2 });
215
+ }
@@ -0,0 +1,4 @@
1
+ import type { PutOptions } from "./put.ts";
2
+ type PutOne = (target: string | undefined, options: PutOptions) => Promise<number>;
3
+ export declare function putWithThumbnail(target: string | undefined, options: PutOptions, putOne: PutOne): Promise<number>;
4
+ export {};
@@ -0,0 +1,119 @@
1
+ // `nmts put <video> --thumbnail` — the video, then its preview picture as an ordinary file linked to
2
+ // it.
3
+ //
4
+ // THE PICTURE IS A SECOND `put`, not a new kind of upload: it is priced, sealed, paid for and listed
5
+ // exactly like any small file, and its list entry carries the video's id (`thumbOf`) so every app
6
+ // hides it while the video is there. `--dry-run` prices both and sends neither.
7
+ //
8
+ // WHERE THE PICTURE COMES FROM: `--thumbnail-file <picture>`, or one frame taken by `ffmpeg` if it is
9
+ // on this machine's PATH (one second in, 512 px on the long side). Without either the video is
10
+ // still stored, and the output says why it went alone.
11
+ //
12
+ // ⚠ ONE JSON LINE PER COMMAND, as everywhere in this tool: with `--json` both runs are captured and
13
+ // printed as the video's object with the picture's under `thumbnail`.
14
+ import { execFile } from "node:child_process";
15
+ import { mkdtemp, rm, stat } from "node:fs/promises";
16
+ import { tmpdir } from "node:os";
17
+ import { basename, join, resolve } from "node:path";
18
+ import { promisify } from "node:util";
19
+ import { classify } from "../shared/lib/drive/preview-classify.js";
20
+ import { BINARY_NAME } from "../product.js";
21
+ const run = promisify(execFile);
22
+ /** Long edge of the frame, px — the same picture the browser makes (spec §4). */
23
+ const FRAME_PX = 512;
24
+ export async function putWithThumbnail(target, options, putOne) {
25
+ const say = options.write ?? ((line) => process.stdout.write(`${line}\n`));
26
+ const name = options.name ?? basename(target ?? "");
27
+ if (classify(name).kind !== "video") {
28
+ say(` ${name} is not a video, so no preview picture goes with it.`);
29
+ return putOne(target, withoutThumbnail(options));
30
+ }
31
+ const captured = [];
32
+ // A holder rather than a `let`: the callback fills it, and a narrowed `let` would read as never set.
33
+ const got = { video: null };
34
+ const code = await putOne(target, {
35
+ ...withoutThumbnail(options),
36
+ onStored: (id, savedAs) => {
37
+ got.video = { id, name: savedAs };
38
+ },
39
+ ...(options.json === true ? { write: (line) => captured.push(line) } : {}),
40
+ });
41
+ const video = got.video;
42
+ if (code !== 0 || (video === null && options.dryRun !== true))
43
+ return finish(code, captured, null, options, say);
44
+ const picture = await pictureFor(target ?? "", options);
45
+ if ("reason" in picture)
46
+ return finish(code, captured, { skipped: picture.reason }, options, say);
47
+ try {
48
+ const pictureLines = [];
49
+ if (options.json !== true)
50
+ say(` with its preview picture:`);
51
+ const pictureCode = await putOne(picture.path, {
52
+ ...withoutThumbnail(options),
53
+ name: `${video?.name ?? name}.thumb.jpg`,
54
+ ...(video !== null ? { thumbOf: video.id } : {}),
55
+ write: options.json === true ? (line) => pictureLines.push(line) : (line) => say(` ${line}`),
56
+ });
57
+ const parsed = pictureLines.length > 0 ? parseLast(pictureLines) : null;
58
+ return finish(pictureCode === 0 ? code : pictureCode, captured, parsed ?? {}, options, say);
59
+ }
60
+ finally {
61
+ await picture.cleanup();
62
+ }
63
+ }
64
+ function withoutThumbnail(options) {
65
+ const { thumbnail: _asked, thumbnailFile: _file, ...rest } = options;
66
+ return rest;
67
+ }
68
+ /** The video's JSON line with the picture's result folded in, or nothing more in human mode. */
69
+ function finish(code, captured, thumbnail, options, say) {
70
+ if (options.json === true) {
71
+ const video = parseLast(captured) ?? {};
72
+ say(JSON.stringify({ ...video, thumbnail }));
73
+ }
74
+ else if (thumbnail !== null && typeof thumbnail.skipped === "string") {
75
+ say(` No preview picture went with it: ${thumbnail.skipped}`);
76
+ }
77
+ return code;
78
+ }
79
+ function parseLast(lines) {
80
+ const last = lines.at(-1);
81
+ if (last === undefined)
82
+ return null;
83
+ try {
84
+ const value = JSON.parse(last);
85
+ return typeof value === "object" && value !== null && !Array.isArray(value) ? { ...value } : null;
86
+ }
87
+ catch {
88
+ return null;
89
+ }
90
+ }
91
+ /** The picture to send, and how to tidy up after it — or why there is none. */
92
+ async function pictureFor(videoPath, options) {
93
+ if (options.thumbnailFile !== undefined)
94
+ return { path: resolve(options.thumbnailFile), cleanup: async () => undefined };
95
+ const dir = await mkdtemp(join(tmpdir(), "nmts-thumb-"));
96
+ const out = join(dir, "frame.jpg");
97
+ const cleanup = () => rm(dir, { recursive: true, force: true });
98
+ const scale = `scale='if(gt(iw,ih),${FRAME_PX},-2)':'if(gt(iw,ih),-2,${FRAME_PX})'`;
99
+ // One second in first; a clip shorter than that has its first frame instead.
100
+ for (const at of ["1", "0"]) {
101
+ try {
102
+ await run("ffmpeg", ["-hide_banner", "-loglevel", "error", "-y", "-ss", at, "-i", resolve(videoPath), "-frames:v", "1", "-vf", scale, "-q:v", "5", out]);
103
+ // ⚠ Past the end, ffmpeg exits 0 having written nothing — only a file with bytes is a frame.
104
+ if ((await stat(out).catch(() => null))?.size)
105
+ return { path: out, cleanup };
106
+ }
107
+ catch (error) {
108
+ if (isMissing(error)) {
109
+ await cleanup();
110
+ return { reason: `ffmpeg is not on this machine's PATH. Give the picture yourself: ${BINARY_NAME} put <video> --thumbnail-file <picture>` };
111
+ }
112
+ }
113
+ }
114
+ await cleanup();
115
+ return { reason: "ffmpeg could not take a frame from this file." };
116
+ }
117
+ function isMissing(error) {
118
+ return typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT";
119
+ }
@@ -58,6 +58,8 @@ export interface WalletUploadFile {
58
58
  parentId: string | null;
59
59
  /** The destination AS TYPED — part of the reservation key. */
60
60
  destination: string;
61
+ /** A video's preview picture: the video's item id (`put-thumbnail.ts`). */
62
+ thumbOf?: string | undefined;
61
63
  }
62
64
  export interface WalletUploadContext {
63
65
  code: string;
@@ -101,7 +101,7 @@ export async function putWithWallet(target, options) {
101
101
  try {
102
102
  const size = local?.size ?? original?.entry.size ?? 0;
103
103
  const localPath = local?.localPath ?? scratch?.localPath ?? "";
104
- done = await uploadOneWithWallet(ctx, { localPath, size, name, parentId, destination }, options);
104
+ done = await uploadOneWithWallet(ctx, { localPath, size, name, parentId, destination, thumbOf: options.thumbOf }, options);
105
105
  }
106
106
  finally {
107
107
  // ⛔ ON EVERY PATH OUT, INCLUDING THE FAILING ONES. What it removes is a decrypted copy of
@@ -116,6 +116,7 @@ export async function putWithWallet(target, options) {
116
116
  ? null
117
117
  : await settleRefill({ server, apiKey: key.key, code: resolved.code, accountId: identity.accountId }, original, done.itemId);
118
118
  const savedAs = original?.name ?? done.savedAs;
119
+ options.onStored?.(done.itemId, savedAs);
119
120
  if (options.json) {
120
121
  say(JSON.stringify({ id: done.itemId, name: savedAs, ...done.facts, resumed: done.resumed, renamed: savedAs !== name, ...(original !== null ? { replacedIntoTrash: original.entry.id } : done.replaced ? { replacedIntoTrash: done.replaced } : {}), fileListVersion: settled ?? done.seq }));
121
122
  return 0;
@@ -179,7 +180,7 @@ export async function uploadOneWithWallet(ctx, file, options) {
179
180
  partSize: ctx.partSize,
180
181
  rule: ctx.rule,
181
182
  onCollision: ctx.onCollision,
182
- }, { source: fileSource(file.localPath, file.size), name: file.name, parentId: file.parentId, destination: file.destination }, {
183
+ }, { source: fileSource(file.localPath, file.size), name: file.name, parentId: file.parentId, destination: file.destination, thumbOf: file.thumbOf }, {
183
184
  epochs: options.epochs,
184
185
  storage: options.storage,
185
186
  dryRun: options.dryRun,
@@ -44,6 +44,14 @@ export interface PutOptions {
44
44
  trustServerTipAddress?: boolean;
45
45
  json?: boolean;
46
46
  write?: (line: string) => void;
47
+ /** Send the video's preview picture with it — a frame from ffmpeg (`put-thumbnail.ts`). */
48
+ thumbnail?: boolean;
49
+ /** The picture to send as the video's preview, instead of a frame from ffmpeg. */
50
+ thumbnailFile?: string | undefined;
51
+ /** Set by `put-thumbnail.ts` on the picture's own run: the video's item id, written as `thumbOf`. */
52
+ thumbOf?: string;
53
+ /** Told the stored item's id and the name it was saved as, before anything is printed. */
54
+ onStored?: (itemId: string, savedAs: string) => void;
47
55
  }
48
56
  /** Who pays, and the options that lose their meaning under that answer — the rule is in `put-payer.ts`; this is its one road. */
49
57
  import { payerOf, refuseWalletOnlyOptions } from "./put-payer.ts";
@@ -69,6 +69,9 @@ export function folderIdFor(wanted, entries) {
69
69
  return folder.id;
70
70
  }
71
71
  export async function put(target, options = {}) {
72
+ if (options.thumbnail === true || options.thumbnailFile !== undefined) {
73
+ return (await import("./put-thumbnail.js")).putWithThumbnail(target, options, put);
74
+ }
72
75
  // ⛔ DECIDED BEFORE ANYTHING IS READ. The wallet path prices in WAL and signs; nothing below this
73
76
  // line knows how to do either, and it must not learn.
74
77
  if (payerOf(options.pay) === "wallet") {
@@ -258,8 +261,10 @@ export async function put(target, options = {}) {
258
261
  updatedAt: now,
259
262
  dekWrapped: result.entry.dekWrapped,
260
263
  contentHashCt: result.entry.contentHashCt,
264
+ ...(options.thumbOf !== undefined ? { thumbOf: options.thumbOf } : {}),
261
265
  },
262
266
  });
267
+ options.onStored?.(result.itemId, added.name);
263
268
  // ⛔ ONLY NOW, AND EVERY PART. Until the entry is in the list the file is paid for and invisible,
264
269
  // and the records are the only thing that lets a second run finish the job without spending
265
270
  // again. Clearing the file-level one first would leave a run able to commit a second time.
@@ -6,7 +6,7 @@ import { readFileList } from "../manifest.js";
6
6
  import { applyManyToList, batchTargets } from "../manifest-write.js";
7
7
  import { applyIntent } from "../shared/lib/drive/manifest-ops.js";
8
8
  import { DriveEditError, resolving } from "./errors.js";
9
- import { filesUnder, hasNamedAncestor, uniqueById } from "./tree.js";
9
+ import { filesUnder, hasNamedAncestor, uniqueById, withPreviews } from "./tree.js";
10
10
  /**
11
11
  * Move things to the trash, or bring them back.
12
12
  *
@@ -88,9 +88,11 @@ export async function trashPaths(input, verb, paths, options = {}) {
88
88
  // storage, and leave the list saying "trashed" while the server says "live" — after which
89
89
  // `rm` refuses to put it back and there is no way out.
90
90
  const at = Date.now();
91
- const ids = targets.map((t) => t.entry.id);
91
+ // A video's hidden preview picture goes into and out of the trash with it (gallery spec §4).
92
+ const under = withPreviews(entries, targets.flatMap((t) => filesUnder(entries, t.entry.id)));
93
+ const chosen = targets.map((t) => t.entry.id);
94
+ const ids = [...chosen, ...under.filter((f) => f.thumbOf !== undefined && !chosen.includes(f.id)).map((f) => f.id)];
92
95
  const preview = buildIndex(applyIntent(entries, intentFor(verb, ids, at)));
93
- const under = uniqueById(targets.flatMap((t) => filesUnder(entries, t.entry.id)));
94
96
  // ⚠ Judged on the PREVIEW's own row, not on the one in hand: `applyIntent` returns new objects,
95
97
  // so asking the preview about the old object reads the old `deletedAt` and answers "still
96
98
  // trashed" for the very thing being restored.
@@ -3,6 +3,12 @@ import type { ManifestEntry } from "../shared/lib/drive/manifest-codec.ts";
3
3
  export declare function isUnder(entries: readonly ManifestEntry[], id: string | null, rootId: string): boolean;
4
4
  /** Is any ancestor of this entry in the set? Used to drop a target a named folder already covers. */
5
5
  export declare function hasNamedAncestor(entries: readonly ManifestEntry[], entry: ManifestEntry, named: ReadonlySet<string>): boolean;
6
+ /**
7
+ * `files` and the preview pictures of the videos among them. A video's
8
+ * picture is a file of its own, hidden from every listing while the video is there, so it goes
9
+ * wherever the video goes — left behind, it would be charged for and then show up on its own.
10
+ */
11
+ export declare function withPreviews(entries: readonly ManifestEntry[], files: readonly ManifestEntry[]): ManifestEntry[];
6
12
  /** One entry per id, keeping the first. Two named folders can hold the same file only once. */
7
13
  export declare function uniqueById(files: readonly ManifestEntry[]): ManifestEntry[];
8
14
  /**
@@ -27,6 +27,16 @@ export function hasNamedAncestor(entries, entry, named) {
27
27
  }
28
28
  return false;
29
29
  }
30
+ /**
31
+ * `files` and the preview pictures of the videos among them. A video's
32
+ * picture is a file of its own, hidden from every listing while the video is there, so it goes
33
+ * wherever the video goes — left behind, it would be charged for and then show up on its own.
34
+ */
35
+ export function withPreviews(entries, files) {
36
+ const index = buildIndex(entries);
37
+ const pictures = files.flatMap((f) => (index.previews.get(f.id) ?? []).flatMap((id) => index.byId.get(id) ?? []));
38
+ return uniqueById([...files, ...pictures]);
39
+ }
30
40
  /** One entry per id, keeping the first. Two named folders can hold the same file only once. */
31
41
  export function uniqueById(files) {
32
42
  const byId = new Map();
@@ -30,7 +30,7 @@
30
30
  // from each other. This is a sibling of that family rather than an outside caller.
31
31
  import { request, ServerError } from "./api.js";
32
32
  import { DriveEditError, resolving } from "./drive-edit/errors.js";
33
- import { filesUnder, foldersUnder, uniqueById } from "./drive-edit/tree.js";
33
+ import { filesUnder, foldersUnder, uniqueById, withPreviews } from "./drive-edit/tree.js";
34
34
  import { buildIndex, fullPathOf, KIND_FILE } from "./drive-paths.js";
35
35
  import { NmtsError } from "./errors.js";
36
36
  import { readFileList } from "./manifest.js";
@@ -53,7 +53,7 @@ export async function planErase(input, paths) {
53
53
  const entries = list.manifest?.entries ?? [];
54
54
  const index = buildIndex(entries);
55
55
  const targets = resolving(() => batchTargets(entries, paths, { includeTrashed: true, nothingHappened: "Nothing was erased." }));
56
- const files = uniqueById(targets.flatMap((t) => (t.kind === KIND_FILE ? [t] : filesUnder(entries, t.id))));
56
+ const files = withPreviews(entries, targets.flatMap((t) => (t.kind === KIND_FILE ? [t] : filesUnder(entries, t.id))));
57
57
  // ⛔ AND THE FOLDERS UNDER A NAMED FOLDER, which `targets + files` left behind. A sub-folder
58
58
  // holding no file was in neither set, so it stayed in the sealed list with its parent gone —
59
59
  // a folder the drive still showed, sitting under nothing, that no command could reach
@@ -1,10 +1,10 @@
1
1
  import type { ManifestEntry } from "./shared/lib/drive/manifest-codec.ts";
2
- import { buildIndex, isLive, type ManifestIndex, trashedAt } from "./shared/lib/drive/manifest-index.ts";
2
+ import { buildIndex, isLive, type ManifestIndex, shown, trashedAt } from "./shared/lib/drive/manifest-index.ts";
3
3
  /** Folder. The same numeric codes the items API uses. */
4
4
  export declare const KIND_FOLDER = 0;
5
5
  /** File. */
6
6
  export declare const KIND_FILE = 1;
7
- export { buildIndex, isLive, trashedAt };
7
+ export { buildIndex, isLive, shown, trashedAt };
8
8
  export type { ManifestIndex };
9
9
  /**
10
10
  * The full path of one entry, marked when the walk could not reach the root.
@@ -23,12 +23,12 @@
23
23
  // the third walk silently resolved the orphan to the same string. **The path that is printed
24
24
  // must be the path that matches**, so there is one function and everybody calls it.
25
25
  import { NmtsError } from "./errors.js";
26
- import { buildIndex, isLive, KIND_FILE as SHARED_KIND_FILE, KIND_FOLDER as SHARED_KIND_FOLDER, trashedAt, } from "./shared/lib/drive/manifest-index.js";
26
+ import { buildIndex, isLive, KIND_FILE as SHARED_KIND_FILE, KIND_FOLDER as SHARED_KIND_FOLDER, shown, trashedAt, } from "./shared/lib/drive/manifest-index.js";
27
27
  /** Folder. The same numeric codes the items API uses. */
28
28
  export const KIND_FOLDER = SHARED_KIND_FOLDER;
29
29
  /** File. */
30
30
  export const KIND_FILE = SHARED_KIND_FILE;
31
- export { buildIndex, isLive, trashedAt };
31
+ export { buildIndex, isLive, shown, trashedAt };
32
32
  /**
33
33
  * What a broken parent chain is drawn as.
34
34
  *
@@ -57,6 +57,7 @@ export function optionLines() {
57
57
  ` (whoami). --lang ko for the Korean word list`,
58
58
  ` --find <text> List only the files whose name contains this text (ls). Folders`,
59
59
  ` appear only where they hold a match`,
60
+ ` --media <kind> image, video or audio: only files of that kind (ls)`,
60
61
  ` --sort <key> name, size or date. Default: whole paths, ascending (ls)`,
61
62
  ` --desc Reverse whichever order is in effect (ls)`,
62
63
  ` --hidden Include entries whose name begins with a dot (push)`,
@@ -79,6 +80,9 @@ export function optionLines() {
79
80
  ` --dry-run Say what it would cost, and stop (put, push, extend), or what it`,
80
81
  ` would install, and stop (update). With \`extend\` and \`--pay`,
81
82
  ` wallet\` nothing is signed and the wallet key is never touched`,
83
+ ` --thumbnail Send a video's preview picture with it, one frame taken by ffmpeg`,
84
+ ` (put); fetch only that picture (get)`,
85
+ ` --thumbnail-file <f> The picture to send as the video's preview instead (put)`,
82
86
  ` --part-size <n> Bytes per part for a large upload (put, push). Default 64MiB.`,
83
87
  ` A plain number, or one with KiB, MiB or GiB. Bigger parts mean`,
84
88
  ` fewer purchases; smaller parts use less memory`,
package/dist/main.js CHANGED
@@ -98,6 +98,7 @@ export async function run(argv) {
98
98
  find: args.find,
99
99
  sort: args.sort,
100
100
  desc: args.desc,
101
+ media: args.media,
101
102
  });
102
103
  }
103
104
  case "usage": {
@@ -172,6 +173,7 @@ export async function run(argv) {
172
173
  const { get } = await import("./commands/get.js");
173
174
  return await get(args.operands[0], {
174
175
  server: args.server, network: args.network, out: args.out, force: args.force, json: args.json,
176
+ thumbnail: args.thumbnail,
175
177
  });
176
178
  }
177
179
  case "put": {
@@ -189,6 +191,7 @@ export async function run(argv) {
189
191
  epochs: args.epochs,
190
192
  storage: args.storage, from: args.from,
191
193
  json: args.json, wallet: args.wallet, trustServerTipAddress: args.trustServerTipAddress,
194
+ thumbnail: args.thumbnail, thumbnailFile: args.thumbnailFile,
192
195
  });
193
196
  }
194
197
  case "push": {
@@ -61,13 +61,21 @@ export function fileTools(ctx) {
61
61
  `The reply says where it went.`,
62
62
  inputSchema: {
63
63
  type: "object",
64
- properties: { path: { type: "string", description: "The file's path inside the account." } },
64
+ properties: {
65
+ path: { type: "string", description: "The file's path inside the account." },
66
+ thumbnail: {
67
+ type: "boolean",
68
+ description: "Fetch the video's preview picture instead of the video, as <path>.thumb.jpg.",
69
+ },
70
+ },
65
71
  required: ["path"],
66
72
  additionalProperties: false,
67
73
  },
68
74
  run: (args) => {
69
75
  const wanted = needString(args, "path");
70
- return say((write) => get(wanted, { ...common(ctx), out: destinationFor(ctx.outDir, wanted), json: true, write }));
76
+ const thumbnail = args["thumbnail"] === true;
77
+ const out = destinationFor(ctx.outDir, thumbnail ? `${wanted}.thumb.jpg` : wanted);
78
+ return say((write) => get(wanted, { ...common(ctx), out, thumbnail, json: true, write }));
71
79
  },
72
80
  },
73
81
  {
@@ -118,6 +126,15 @@ export function fileTools(ctx) {
118
126
  to: { type: "string", description: "An existing folder in the account, as nmts_list prints it." },
119
127
  deposit_credits: { type: "integer", description: DEPOSIT_HINT },
120
128
  dry_run: { type: "boolean", description: "Say what it would cost and stop. Nothing is sent or charged." },
129
+ thumbnail: {
130
+ type: "boolean",
131
+ description: "For a video: also send one frame of it (taken by ffmpeg) as a small preview file every " +
132
+ "app shows as the video's tile. It is priced and charged like any file.",
133
+ },
134
+ thumbnail_file: {
135
+ type: "string",
136
+ description: "For a video: a picture ON THIS MACHINE to send as its preview instead of a frame.",
137
+ },
121
138
  },
122
139
  required: ["file"],
123
140
  additionalProperties: false,
@@ -129,6 +146,8 @@ export function fileTools(ctx) {
129
146
  ...(typeof args["to"] === "string" ? { to: args["to"] } : {}),
130
147
  ...(typeof args["deposit_credits"] === "number" ? { deposit: args["deposit_credits"] } : {}),
131
148
  ...(args["dry_run"] === true ? { dryRun: true } : {}),
149
+ ...(args["thumbnail"] === true ? { thumbnail: true } : {}),
150
+ ...(typeof args["thumbnail_file"] === "string" ? { thumbnailFile: args["thumbnail_file"] } : {}),
132
151
  write,
133
152
  })),
134
153
  },
@@ -24,7 +24,9 @@ export function readTools(ctx) {
24
24
  name: "nmts_list",
25
25
  description: "List the files stored in the NMTS account, as JSON. Paths are what nmts_get takes. " +
26
26
  "Entries in the trash are left out unless include_trashed is true, and the reply says " +
27
- "how many were left out. Optionally narrow with a search word and choose an order.",
27
+ "how many were left out. Optionally narrow with a search word or a media kind and choose " +
28
+ "an order. A video's preview picture is not listed while its video is: nmts_get with " +
29
+ "thumbnail fetches it.",
28
30
  inputSchema: {
29
31
  type: "object",
30
32
  properties: {
@@ -36,6 +38,11 @@ export function readTools(ctx) {
36
38
  description: "Order the listing. Absent means the path order this tool has always printed.",
37
39
  },
38
40
  descending: { type: "boolean", description: "Reverse the order." },
41
+ media: {
42
+ type: "string",
43
+ enum: ["image", "video", "audio"],
44
+ description: "Keep only files of this kind, judged by the name's extension.",
45
+ },
39
46
  },
40
47
  additionalProperties: false,
41
48
  },
@@ -46,6 +53,7 @@ export function readTools(ctx) {
46
53
  ...(typeof args["find"] === "string" ? { find: args["find"] } : {}),
47
54
  ...(typeof args["sort"] === "string" ? { sort: args["sort"] } : {}),
48
55
  ...(args["descending"] === true ? { desc: true } : {}),
56
+ ...(typeof args["media"] === "string" ? { media: args["media"] } : {}),
49
57
  write,
50
58
  })),
51
59
  },
@@ -22,7 +22,7 @@ export type { FileList } from "./manifest.ts";
22
22
  export { addEntry, applyManyToList, applyToList, planAddition } from "./manifest-write.ts";
23
23
  export type { AddEntryInput, AddEntryResult, ListEditInput, ListEditResult } from "./manifest-write.ts";
24
24
  export type { Manifest, ManifestEntry } from "./shared/lib/drive/manifest-codec.ts";
25
- export { buildIndex, entryAt, folderIdFor, fullPathOf, isLive, KIND_FILE, KIND_FOLDER, namesIn, normalisePath, trashedAt, } from "./drive-paths.ts";
25
+ export { buildIndex, entryAt, folderIdFor, fullPathOf, isLive, KIND_FILE, KIND_FOLDER, namesIn, normalisePath, shown, trashedAt, } from "./drive-paths.ts";
26
26
  export type { FindOptions, ManifestIndex } from "./drive-paths.ts";
27
27
  export { setTrashed } from "./item-trash.ts";
28
28
  export { businessPublicKey, businessSigningInput, BUSINESS_CONTEXT, BUSINESS_PREFIX, delegationSigningInput, DELEGATION_CONTEXT, DELEGATION_MAX_TTL_SECS, DELEGATION_PREFIX, generateBusinessKeys, mintDelegation, NONCE_LEN, PUBKEY_LEN, rotationProof, rotationSigningInput, ROTATE_CONTEXT, SCOPE_ALL, SCOPE_BITS, scopeMask, signatureHolds, signBusinessRequest, SIGNATURE_LEN, } from "./platform-sign.ts";
@@ -56,6 +56,7 @@ export { chainReader } from "./wallet-chain.ts";
56
56
  export { signerAddress, signExtension, signTransfer } from "./wallet-sign.ts";
57
57
  export type { SignTransfer } from "./wallet-sign.ts";
58
58
  export { activeWalletOf, walletCountOf, WALLET_INDEX_LIMIT } from "./shared/lib/drive/manifest-settings.ts";
59
+ export { classify } from "./shared/lib/drive/preview-classify.ts";
59
60
  export { discoverWallets, WALLET_SCAN_GAP } from "./shared/lib/wallet/discover.ts";
60
61
  export type { WalletProbe, WalletScan } from "./shared/lib/wallet/discover.ts";
61
62
  export { hasHistory } from "./wallet-list-chain.ts";