@needmoretruth/nmts-cli 0.44.0 → 0.46.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.
- package/AGENTS.md +2 -2
- package/CHANGELOG.md +73 -0
- package/README.ko.md +6 -3
- package/README.md +15 -3
- package/dist/api-advice.js +17 -2
- package/dist/api.d.ts +22 -0
- package/dist/api.js +49 -1
- package/dist/arg-options.d.ts +14 -0
- package/dist/args.js +11 -2
- package/dist/artifact-about.d.ts +1 -1
- package/dist/collision.d.ts +20 -3
- package/dist/collision.js +21 -3
- package/dist/commands/erase.js +1 -0
- package/dist/commands/get.d.ts +2 -0
- package/dist/commands/get.js +13 -1
- package/dist/commands/handover.d.ts +13 -0
- package/dist/commands/handover.js +328 -0
- package/dist/commands/heavy-run.d.ts +59 -0
- package/dist/commands/heavy-run.js +247 -0
- package/dist/commands/heavy.d.ts +7 -0
- package/dist/commands/heavy.js +123 -0
- package/dist/commands/ls.d.ts +7 -0
- package/dist/commands/ls.js +27 -6
- package/dist/commands/public-code.d.ts +6 -0
- package/dist/commands/public-code.js +46 -0
- package/dist/commands/push-heavy.d.ts +6 -0
- package/dist/commands/push-heavy.js +128 -0
- package/dist/commands/push-tree.d.ts +24 -0
- package/dist/commands/push-tree.js +91 -0
- package/dist/commands/push.d.ts +4 -13
- package/dist/commands/push.js +7 -77
- package/dist/commands/put-heavy.d.ts +9 -0
- package/dist/commands/put-heavy.js +120 -0
- package/dist/commands/put-payer.d.ts +21 -0
- package/dist/commands/put-payer.js +24 -0
- package/dist/commands/put-thumbnail.d.ts +4 -0
- package/dist/commands/put-thumbnail.js +119 -0
- package/dist/commands/put-wallet.d.ts +2 -0
- package/dist/commands/put-wallet.js +3 -2
- package/dist/commands/put.d.ts +10 -2
- package/dist/commands/put.js +13 -7
- package/dist/commands/receive.js +3 -3
- package/dist/commands/s3.js +44 -10
- package/dist/crypto-surface.d.ts +8 -0
- package/dist/crypto-surface.js +3 -0
- package/dist/crypto.d.ts +3 -0
- package/dist/crypto.js +3 -0
- package/dist/download-part.d.ts +32 -1
- package/dist/download-part.js +95 -6
- package/dist/download-range.d.ts +19 -0
- package/dist/download-range.js +108 -0
- package/dist/download-sink.d.ts +15 -0
- package/dist/download.d.ts +14 -0
- package/dist/download.js +19 -4
- package/dist/drive-edit/trash.js +5 -3
- package/dist/drive-edit/tree.d.ts +6 -0
- package/dist/drive-edit/tree.js +10 -0
- package/dist/drive-erase.js +2 -2
- package/dist/drive-paths.d.ts +2 -2
- package/dist/drive-paths.js +2 -2
- package/dist/handover.d.ts +44 -0
- package/dist/handover.js +199 -0
- package/dist/heavy-api.d.ts +36 -0
- package/dist/heavy-api.js +107 -0
- package/dist/heavy-copy.d.ts +72 -0
- package/dist/heavy-copy.js +108 -0
- package/dist/heavy-evm.d.ts +20 -0
- package/dist/heavy-evm.js +106 -0
- package/dist/heavy-self-pay.d.ts +92 -0
- package/dist/heavy-self-pay.js +167 -0
- package/dist/heavy-upload.d.ts +87 -0
- package/dist/heavy-upload.js +154 -0
- package/dist/heavy-wallet-pay.d.ts +39 -0
- package/dist/heavy-wallet-pay.js +73 -0
- package/dist/help-options.js +8 -2
- package/dist/help.js +16 -3
- package/dist/list-tier.d.ts +7 -0
- package/dist/list-tier.js +47 -0
- package/dist/main.js +14 -9
- package/dist/manifest-write.d.ts +4 -3
- package/dist/mcp-tools/files.js +21 -2
- package/dist/mcp-tools/reads.js +9 -1
- package/dist/platform-sign.d.ts +4 -4
- package/dist/platform-sign.js +3 -3
- package/dist/portable.d.ts +17 -1
- package/dist/portable.js +13 -1
- package/dist/product.d.ts +1 -1
- package/dist/product.js +1 -1
- package/dist/recovery-build.js +16 -0
- package/dist/recovery-map-part.d.ts +82 -0
- package/dist/recovery-map-part.js +83 -0
- package/dist/recovery-map.d.ts +5 -40
- package/dist/recovery-map.js +18 -1
- package/dist/recovery-source.d.ts +3 -0
- package/dist/recovery-source.js +9 -0
- package/dist/risk.d.ts +30 -0
- package/dist/risk.js +23 -2
- package/dist/run-log.d.ts +1 -1
- package/dist/run-log.js +7 -1
- package/dist/s3/address.d.ts +20 -0
- package/dist/s3/address.js +97 -0
- package/dist/s3/answer.d.ts +48 -0
- package/dist/s3/answer.js +330 -0
- package/dist/s3/body-deframe.d.ts +49 -0
- package/dist/s3/body-deframe.js +264 -0
- package/dist/s3/body-measure.d.ts +13 -0
- package/dist/s3/body-measure.js +48 -0
- package/dist/s3/body-plan.d.ts +31 -0
- package/dist/s3/body-plan.js +159 -0
- package/dist/s3/body.d.ts +46 -0
- package/dist/s3/body.js +117 -0
- package/dist/s3/call.d.ts +36 -0
- package/dist/s3/call.js +42 -0
- package/dist/s3/checksum.d.ts +26 -0
- package/dist/s3/checksum.js +176 -0
- package/dist/s3/content-type.d.ts +3 -0
- package/dist/s3/content-type.js +49 -0
- package/dist/s3/contract.d.ts +91 -14
- package/dist/s3/drive-conditions.d.ts +47 -0
- package/dist/s3/drive-conditions.js +134 -0
- package/dist/s3/drive-key.d.ts +11 -0
- package/dist/s3/drive-key.js +58 -0
- package/dist/s3/drive-limits.d.ts +33 -0
- package/dist/s3/drive-limits.js +53 -0
- package/dist/s3/drive-lock.d.ts +11 -0
- package/dist/s3/drive-lock.js +47 -0
- package/dist/s3/drive-trashed-name.d.ts +13 -0
- package/dist/s3/drive-trashed-name.js +59 -0
- package/dist/s3/drive-write.d.ts +38 -0
- package/dist/s3/drive-write.js +258 -0
- package/dist/s3/drive.d.ts +59 -25
- package/dist/s3/drive.js +46 -77
- package/dist/s3/listing.d.ts +27 -1
- package/dist/s3/listing.js +62 -20
- package/dist/s3/long-answer.d.ts +12 -0
- package/dist/s3/long-answer.js +104 -0
- package/dist/s3/multipart-assemble.d.ts +17 -0
- package/dist/s3/multipart-assemble.js +68 -0
- package/dist/s3/multipart-sweep.d.ts +15 -0
- package/dist/s3/multipart-sweep.js +87 -0
- package/dist/s3/multipart-view.d.ts +45 -0
- package/dist/s3/multipart-view.js +232 -0
- package/dist/s3/multipart.d.ts +26 -19
- package/dist/s3/multipart.js +193 -78
- package/dist/s3/object-read.d.ts +17 -0
- package/dist/s3/object-read.js +127 -0
- package/dist/s3/object-write.d.ts +35 -0
- package/dist/s3/object-write.js +198 -0
- package/dist/s3/range.d.ts +14 -0
- package/dist/s3/range.js +80 -0
- package/dist/s3/response-sink.d.ts +12 -2
- package/dist/s3/response-sink.js +71 -7
- package/dist/s3/routes.d.ts +0 -1
- package/dist/s3/routes.js +242 -217
- package/dist/s3/same-file.d.ts +4 -1
- package/dist/s3/same-file.js +12 -3
- package/dist/s3/server.d.ts +54 -4
- package/dist/s3/server.js +174 -14
- package/dist/s3/sigv4-canonical.d.ts +91 -0
- package/dist/s3/sigv4-canonical.js +148 -0
- package/dist/s3/sigv4-presigned.d.ts +13 -0
- package/dist/s3/sigv4-presigned.js +82 -0
- package/dist/s3/sigv4.d.ts +26 -27
- package/dist/s3/sigv4.js +137 -102
- package/dist/s3/spool.d.ts +37 -0
- package/dist/s3/spool.js +104 -0
- package/dist/s3/staging.d.ts +90 -7
- package/dist/s3/staging.js +97 -66
- package/dist/s3/xml-multipart.d.ts +38 -0
- package/dist/s3/xml-multipart.js +47 -0
- package/dist/s3/xml-read.d.ts +28 -0
- package/dist/s3/xml-read.js +235 -0
- package/dist/s3/xml.d.ts +45 -2
- package/dist/s3/xml.js +72 -13
- package/dist/s3-gateway.d.ts +11 -5
- package/dist/s3-gateway.js +5 -2
- package/dist/seal.d.ts +1 -1
- package/dist/share.d.ts +5 -0
- package/dist/share.js +1 -1
- package/dist/shared/lib/api/types-heavy.d.ts +167 -0
- package/dist/shared/lib/api/types-heavy.js +60 -0
- package/dist/shared/lib/drive/manifest-codec.d.ts +11 -31
- package/dist/shared/lib/drive/manifest-codec.js +15 -23
- package/dist/shared/lib/drive/manifest-index.d.ts +10 -1
- package/dist/shared/lib/drive/manifest-index.js +30 -8
- package/dist/shared/lib/drive/manifest-wire-extras.d.ts +50 -0
- package/dist/shared/lib/drive/manifest-wire-extras.js +65 -0
- package/dist/shared/lib/drive/preview-classify.d.ts +17 -0
- package/dist/shared/lib/drive/preview-classify.js +96 -0
- package/dist/shared/lib/drive/rebuild-verify.js +1 -0
- package/dist/shared/lib/filecoin/providers.d.ts +25 -0
- package/dist/shared/lib/filecoin/providers.js +58 -0
- package/dist/shared/lib/heavy/download.d.ts +48 -0
- package/dist/shared/lib/heavy/download.js +116 -0
- package/dist/shared/lib/heavy/order-plan.d.ts +77 -0
- package/dist/shared/lib/heavy/order-plan.js +83 -0
- package/dist/shared/lib/heavy/order-runner.d.ts +9 -0
- package/dist/shared/lib/heavy/order-runner.js +300 -0
- package/dist/shared/lib/heavy/order-types.d.ts +90 -0
- package/dist/shared/lib/heavy/order-types.js +6 -0
- package/dist/shared/lib/heavy/order-wire.d.ts +55 -0
- package/dist/shared/lib/heavy/order-wire.js +113 -0
- package/dist/shared/lib/heavy/piece-cid.d.ts +24 -0
- package/dist/shared/lib/heavy/piece-cid.js +55 -0
- package/dist/shared/lib/heavy/sp-upload.d.ts +37 -0
- package/dist/shared/lib/heavy/sp-upload.js +112 -0
- package/dist/shared/lib/heavy/synapse-piece.d.ts +1 -0
- package/dist/shared/lib/heavy/synapse-piece.js +8 -0
- package/dist/shared/lib/share/handover-format.d.ts +129 -0
- package/dist/shared/lib/share/handover-format.js +323 -0
- package/dist/shared/lib/share/shared-file-info.js +1 -0
- package/dist/shared/lib/storage-network.d.ts +4 -4
- package/dist/shared/lib/storage-network.js +7 -7
- package/dist/shared/lib/storage-tier.d.ts +28 -0
- package/dist/shared/lib/storage-tier.js +63 -0
- package/dist/shared/lib/wallet/send-rules.js +1 -0
- package/dist/upload-file.d.ts +8 -0
- package/dist/upload-file.js +57 -25
- package/dist/upload-price-node.d.ts +3 -0
- package/dist/upload-price-node.js +3 -6
- package/dist/upload-price.d.ts +10 -0
- package/dist/upload-price.js +13 -1
- package/dist/upload-run.d.ts +80 -0
- package/dist/upload-run.js +173 -0
- package/dist/upload-steps.js +15 -4
- package/dist/upload-store.d.ts +15 -6
- package/dist/upload-store.js +6 -0
- package/dist/upload-wallet-put.d.ts +11 -4
- package/dist/upload-wallet-put.js +17 -6
- package/dist/upload-wallet.js +4 -0
- package/dist/upload-wire.d.ts +25 -0
- package/dist/upload-wire.js +20 -1
- package/dist/upload.js +28 -13
- package/dist/wallet-sign.js +2 -2
- package/docs/commands/get.md +3 -0
- package/docs/commands/handover.md +38 -0
- package/docs/commands/heavy.md +35 -0
- package/docs/commands/ls.md +5 -0
- package/docs/commands/public-code.md +7 -0
- package/docs/commands/push.md +4 -1
- package/docs/commands/put.md +23 -1
- package/docs/commands/share.md +3 -1
- package/package.json +5 -2
- package/server.json +2 -2
- package/vendor/nmts-crypto/nmts_crypto_wasm.d.ts +17 -1
- package/vendor/nmts-crypto/nmts_crypto_wasm.js +28 -0
- package/vendor/nmts-crypto/nmts_crypto_wasm_bg.wasm +0 -0
- package/vendor/nmts-crypto/nmts_crypto_wasm_bg.wasm.d.ts +2 -1
package/dist/commands/push.js
CHANGED
|
@@ -16,10 +16,7 @@
|
|
|
16
16
|
// ⛔ NOTHING HIDDEN IS SENT. Entries whose name begins with a dot are left alone unless they are
|
|
17
17
|
// asked for: a directory of source code carries credentials in exactly those files, and an
|
|
18
18
|
// upload goes to a public storage network. `--hidden` includes them.
|
|
19
|
-
import { readdirSync, statSync } from "node:fs";
|
|
20
|
-
import { basename, join, resolve } from "node:path";
|
|
21
19
|
import { DERIVED, loadCrypto } from "../crypto.js";
|
|
22
|
-
import { normaliseName, normalisePath } from "../drive-paths.js";
|
|
23
20
|
import { NmtsError } from "../errors.js";
|
|
24
21
|
import { addEntry } from "../manifest-write.js";
|
|
25
22
|
import { parseAsked } from "../collision.js";
|
|
@@ -38,6 +35,8 @@ import { CREDIT_BYTES, partSizeFor, planAndPrice, UPLOAD_EPOCHS } from "../uploa
|
|
|
38
35
|
import { createBlobProtocol, readCurrentEpoch } from "../walrus-write.js";
|
|
39
36
|
import { ensureFolderPath } from "../drive-edit.js";
|
|
40
37
|
import { payerOf, refuseWalletOnlyOptions } from "./put.js";
|
|
38
|
+
import { tierOf } from "./put-payer.js";
|
|
39
|
+
import { filesUnderDirectory, localTree, splitAlready } from "./push-tree.js";
|
|
41
40
|
export async function push(target, options = {}) {
|
|
42
41
|
const say = options.write ?? ((line) => process.stdout.write(`${line}\n`));
|
|
43
42
|
if (target === undefined || target === "") {
|
|
@@ -46,6 +45,8 @@ export async function push(target, options = {}) {
|
|
|
46
45
|
nextStep: `\`${BINARY_NAME} push <directory>\` — a directory on this machine.`,
|
|
47
46
|
});
|
|
48
47
|
}
|
|
48
|
+
if (tierOf(options) === "heavy")
|
|
49
|
+
return (await import("./push-heavy.js")).pushHeavy(target, options);
|
|
49
50
|
const payer = payerOf(options.pay);
|
|
50
51
|
if (payer === "wallet")
|
|
51
52
|
refuseDepositWithWallet(options.deposit);
|
|
@@ -59,23 +60,7 @@ export async function push(target, options = {}) {
|
|
|
59
60
|
nextStep: `Nothing was sent. Leave --storage off to buy new storage for each file.`,
|
|
60
61
|
});
|
|
61
62
|
}
|
|
62
|
-
const root =
|
|
63
|
-
let rootStat;
|
|
64
|
-
try {
|
|
65
|
-
rootStat = statSync(root);
|
|
66
|
-
}
|
|
67
|
-
catch {
|
|
68
|
-
throw new NmtsError(`There is nothing at ${root}.`, { exitCode: 4 });
|
|
69
|
-
}
|
|
70
|
-
if (!rootStat.isDirectory()) {
|
|
71
|
-
throw new NmtsError(`${root} is a file.`, {
|
|
72
|
-
exitCode: 4,
|
|
73
|
-
nextStep: `Nothing was sent. \`${BINARY_NAME} put\` uploads one file.`,
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
const under = normalisePath(options.to ?? "");
|
|
77
|
-
const base = under === "" ? basename(root) : `${under}/${basename(root)}`;
|
|
78
|
-
const found = walk(root, base, options.hidden === true);
|
|
63
|
+
const { root, found } = localTree(target, options.to, options.hidden === true);
|
|
79
64
|
if (found.length === 0) {
|
|
80
65
|
if (options.json) {
|
|
81
66
|
say(JSON.stringify({ files: 0, uploaded: 0, skipped: 0, credits: 0 }));
|
|
@@ -92,20 +77,7 @@ export async function push(target, options = {}) {
|
|
|
92
77
|
const rule = paddingRuleOf(list.manifest?.settings);
|
|
93
78
|
// ⛔ WHAT IS ALREADY THERE IS DECIDED BEFORE ANYTHING IS PRICED, so the number printed is what
|
|
94
79
|
// this run will actually spend rather than what a first run would have.
|
|
95
|
-
const
|
|
96
|
-
const taken = new Set(entries
|
|
97
|
-
.filter((e) => e.deletedAt === undefined)
|
|
98
|
-
.map((e) => `${e.parentId ?? ""} ${normaliseName(e.name)}`));
|
|
99
|
-
const folderIds = new Map();
|
|
100
|
-
const already = [];
|
|
101
|
-
const todo = [];
|
|
102
|
-
for (const one of found) {
|
|
103
|
-
const parentId = knownFolderId(entries, one.folder);
|
|
104
|
-
if (parentId !== undefined)
|
|
105
|
-
folderIds.set(one.folder, parentId);
|
|
106
|
-
const there = parentId !== undefined && taken.has(`${parentId ?? ""} ${normaliseName(one.name)}`);
|
|
107
|
-
(there ? already : todo).push(one);
|
|
108
|
-
}
|
|
80
|
+
const { folderIds, already, todo } = splitAlready(list.manifest?.entries ?? [], found);
|
|
109
81
|
const credits = todo.reduce((sum, one) => sum + planAndPrice(one.size, partSize, rule).credits, 0);
|
|
110
82
|
const bytes = todo.reduce((sum, one) => sum + one.size, 0);
|
|
111
83
|
// Per FILE, not per run: every file in the tree sets the same amount aside.
|
|
@@ -265,46 +237,4 @@ export async function folderFor(session, known, folder) {
|
|
|
265
237
|
known.set(folder, parentId);
|
|
266
238
|
return parentId;
|
|
267
239
|
}
|
|
268
|
-
|
|
269
|
-
function knownFolderId(entries, folder) {
|
|
270
|
-
if (folder === "")
|
|
271
|
-
return null;
|
|
272
|
-
let parentId = null;
|
|
273
|
-
for (const name of folder.split("/")) {
|
|
274
|
-
const there = entries.find((e) => e.parentId === parentId &&
|
|
275
|
-
e.kind === 0 &&
|
|
276
|
-
e.deletedAt === undefined &&
|
|
277
|
-
normaliseName(e.name) === normaliseName(name));
|
|
278
|
-
if (there === undefined)
|
|
279
|
-
return undefined;
|
|
280
|
-
parentId = there.id;
|
|
281
|
-
}
|
|
282
|
-
return parentId;
|
|
283
|
-
}
|
|
284
|
-
export { walk as filesUnderDirectory };
|
|
285
|
-
/** Every file under a local directory, with the drive folder each one belongs in. */
|
|
286
|
-
function walk(dir, driveFolder, hidden) {
|
|
287
|
-
const out = [];
|
|
288
|
-
const items = readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name));
|
|
289
|
-
for (const item of items) {
|
|
290
|
-
if (!hidden && item.name.startsWith("."))
|
|
291
|
-
continue;
|
|
292
|
-
const local = join(dir, item.name);
|
|
293
|
-
// ⛔ SYMBOLIC LINKS ARE NOT FOLLOWED. One pointing at a parent directory would walk forever,
|
|
294
|
-
// and one pointing outside would upload a file nobody meant to send.
|
|
295
|
-
if (item.isSymbolicLink())
|
|
296
|
-
continue;
|
|
297
|
-
if (item.isDirectory()) {
|
|
298
|
-
out.push(...walk(local, `${driveFolder}/${item.name}`, hidden));
|
|
299
|
-
continue;
|
|
300
|
-
}
|
|
301
|
-
if (!item.isFile())
|
|
302
|
-
continue;
|
|
303
|
-
const size = statSync(local).size;
|
|
304
|
-
// An empty file has nothing to store, and the storage network would refuse the reservation.
|
|
305
|
-
if (size === 0)
|
|
306
|
-
continue;
|
|
307
|
-
out.push({ local, folder: driveFolder, name: item.name, size });
|
|
308
|
-
}
|
|
309
|
-
return out;
|
|
310
|
-
}
|
|
240
|
+
export { filesUnderDirectory, localTree, splitAlready };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type Session } from "../session.ts";
|
|
2
|
+
import { type AccountSettings } from "../shared/lib/drive/manifest-settings.ts";
|
|
3
|
+
import { type HeavyPayer } from "./heavy-run.ts";
|
|
4
|
+
import { type PutOptions } from "./put.ts";
|
|
5
|
+
/** Who would pay, by address, for a dry run — derived offline, nothing signed. */
|
|
6
|
+
export declare function payerAddressOf(session: Session, payer: HeavyPayer, options: PutOptions, settings: AccountSettings | undefined): Promise<Record<string, unknown>>;
|
|
7
|
+
/** The dry run's words for a person: one plan line per payer, and the closing line. */
|
|
8
|
+
export declare function sayDryRun(say: (line: string) => void, name: string, facts: Record<string, unknown>): void;
|
|
9
|
+
export declare function putHeavy(target: string | undefined, options: PutOptions): Promise<number>;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
// `nmts put <file> --tier heavy` — one file into NMTS Heavy: whole copies kept by two separate
|
|
2
|
+
// storage companies on Filecoin. Paid with credits (the default), with WAL from the wallet
|
|
3
|
+
// (`--pay wallet`), or — developer mode — by this key's own EVM wallet (`--pay evm`).
|
|
4
|
+
//
|
|
5
|
+
// ⛔ EVERYTHING BUT THE ONE FILE IS `heavy-run.ts`: the payer, the review, the agreement, the progress
|
|
6
|
+
// and the failure words are the same for `push --tier heavy`, so they live once.
|
|
7
|
+
import { basename, resolve } from "node:path";
|
|
8
|
+
import { parseAsked } from "../collision.js";
|
|
9
|
+
import { loadCrypto } from "../crypto.js";
|
|
10
|
+
import { NmtsError } from "../errors.js";
|
|
11
|
+
import { HEAVY_COPY } from "../heavy-copy.js";
|
|
12
|
+
import { evmAddressFor, evmIndexOf } from "../heavy-evm.js";
|
|
13
|
+
import { copiesOf } from "../heavy-self-pay.js";
|
|
14
|
+
import { paddingRuleOf, readFileList } from "../manifest.js";
|
|
15
|
+
import { resolveNetwork } from "../network.js";
|
|
16
|
+
import { BINARY_NAME } from "../product.js";
|
|
17
|
+
import { Progress, silentSink } from "../progress.js";
|
|
18
|
+
import { stderrSink } from "../progress-node.js";
|
|
19
|
+
import { openSession } from "../session.js";
|
|
20
|
+
import { activeWalletOf } from "../shared/lib/drive/manifest-settings.js";
|
|
21
|
+
import { fileSource } from "../upload-file-node.js";
|
|
22
|
+
import { measureLocal } from "../upload-price-node.js";
|
|
23
|
+
import { walletAddress } from "../wallet.js";
|
|
24
|
+
import { payingWalletIndex } from "../wallet-pay-index.js";
|
|
25
|
+
import { heavyDryRun, heavyPayerOf, recordHeavy, refuseHeavyClashes, runHeavy, termDaysOf } from "./heavy-run.js";
|
|
26
|
+
import { folderIdFor } from "./put.js";
|
|
27
|
+
/** Who would pay, by address, for a dry run — derived offline, nothing signed. */
|
|
28
|
+
export async function payerAddressOf(session, payer, options, settings) {
|
|
29
|
+
if (payer === "evm") {
|
|
30
|
+
return { payer: await evmAddressFor(session.code, evmIndexOf(options.evmWallet)), copies: copiesOf(options.copies) };
|
|
31
|
+
}
|
|
32
|
+
if (payer === "credits")
|
|
33
|
+
return {};
|
|
34
|
+
const wallet = await payingWalletIndex({ wallet: options.wallet, readActiveWallet: async () => activeWalletOf(settings) });
|
|
35
|
+
return { wallet: await walletAddress(session.code, wallet), termDays: termDaysOf(options.days) };
|
|
36
|
+
}
|
|
37
|
+
/** The dry run's words for a person: one plan line per payer, and the closing line. */
|
|
38
|
+
export function sayDryRun(say, name, facts) {
|
|
39
|
+
const bytes = typeof facts["bytes"] === "number" ? facts["bytes"] : 0;
|
|
40
|
+
if (typeof facts["credits"] === "number")
|
|
41
|
+
say(HEAVY_COPY.creditsPlan(name, bytes, facts["credits"]));
|
|
42
|
+
if (typeof facts["payer"] === "string")
|
|
43
|
+
say(HEAVY_COPY.evmPlan(name, bytes, Number(facts["copies"]), facts["payer"]));
|
|
44
|
+
if (typeof facts["wallet"] === "string")
|
|
45
|
+
say(HEAVY_COPY.walletDryPlan(name, bytes, Number(facts["termDays"]), facts["wallet"]));
|
|
46
|
+
say(HEAVY_COPY.dryRunEnd);
|
|
47
|
+
}
|
|
48
|
+
export async function putHeavy(target, options) {
|
|
49
|
+
const say = options.write ?? ((line) => process.stdout.write(`${line}\n`));
|
|
50
|
+
const payer = heavyPayerOf(options.pay);
|
|
51
|
+
refuseHeavyClashes(options, payer);
|
|
52
|
+
if (target === undefined || target === "") {
|
|
53
|
+
throw new NmtsError("Say which file to put.", {
|
|
54
|
+
exitCode: 2,
|
|
55
|
+
nextStep: `\`${BINARY_NAME} put <file>\` — a path on this machine.`,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
const localPath = resolve(target);
|
|
59
|
+
const size = measureLocal(localPath);
|
|
60
|
+
const session = await openSession({ server: options.server, network: options.network });
|
|
61
|
+
const network = resolveNetwork(session.server, session.network);
|
|
62
|
+
const asked = parseAsked(options.onCollision);
|
|
63
|
+
const list = await readFileList(session.server, session.apiKey, session.code, session.accountId);
|
|
64
|
+
const rule = paddingRuleOf(list.manifest?.settings);
|
|
65
|
+
const name = options.name ?? basename(localPath);
|
|
66
|
+
const destination = (options.to ?? "").replace(/^\.?\//, "").replace(/\/$/, "");
|
|
67
|
+
const parentId = folderIdFor(options.to, list.manifest?.entries ?? []);
|
|
68
|
+
const file = { source: fileSource(localPath, size), name, parentId, destination };
|
|
69
|
+
if (options.dryRun === true) {
|
|
70
|
+
const facts = { ...heavyDryRun([file], rule, payer), ...(await payerAddressOf(session, payer, options, list.manifest?.settings)) };
|
|
71
|
+
if (options.json)
|
|
72
|
+
say(JSON.stringify({ name, ...facts }));
|
|
73
|
+
else
|
|
74
|
+
sayDryRun(say, name, facts);
|
|
75
|
+
return 0;
|
|
76
|
+
}
|
|
77
|
+
const json = options.json === true;
|
|
78
|
+
const report = await runHeavy({
|
|
79
|
+
session,
|
|
80
|
+
network,
|
|
81
|
+
crypt: await loadCrypto(),
|
|
82
|
+
rule,
|
|
83
|
+
settings: list.manifest?.settings,
|
|
84
|
+
say,
|
|
85
|
+
json,
|
|
86
|
+
progress: new Progress(json ? silentSink() : stderrSink(), "uploading"),
|
|
87
|
+
}, [file], payer, options);
|
|
88
|
+
const done = report.files[0];
|
|
89
|
+
if (done === undefined)
|
|
90
|
+
throw new NmtsError(HEAVY_COPY.commitNoId, { nextStep: HEAVY_COPY.commitNoIdNext });
|
|
91
|
+
const added = await recordHeavy(session, done, asked);
|
|
92
|
+
if (json) {
|
|
93
|
+
say(JSON.stringify({
|
|
94
|
+
id: done.itemId,
|
|
95
|
+
name: added.name,
|
|
96
|
+
bytes: size,
|
|
97
|
+
sealedBytes: done.sealedBytes,
|
|
98
|
+
parts: done.parts,
|
|
99
|
+
...report.facts,
|
|
100
|
+
renamed: added.name !== name,
|
|
101
|
+
...(added.replaced === null ? {} : { replacedIntoTrash: added.replaced }),
|
|
102
|
+
fileListVersion: added.seq,
|
|
103
|
+
}));
|
|
104
|
+
return 0;
|
|
105
|
+
}
|
|
106
|
+
say(` saved as ${added.name}`);
|
|
107
|
+
if (typeof report.facts["expiryEpoch"] === "number")
|
|
108
|
+
say(HEAVY_COPY.stored(report.facts["expiryEpoch"]));
|
|
109
|
+
if (added.replaced !== null) {
|
|
110
|
+
say(``);
|
|
111
|
+
say(` A file called ${name} was already there. It is in the trash now — ${BINARY_NAME} restore`);
|
|
112
|
+
say(` brings it back for 30 days. This machine is set to overwrite: ${BINARY_NAME} on-collision`);
|
|
113
|
+
}
|
|
114
|
+
else if (added.name !== name) {
|
|
115
|
+
say(``);
|
|
116
|
+
say(` A file called ${name} was already there, so this one was numbered rather than`);
|
|
117
|
+
say(` replacing it. This machine is set to rename: ${BINARY_NAME} on-collision`);
|
|
118
|
+
}
|
|
119
|
+
return 0;
|
|
120
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type StorageTier } from "../shared/lib/storage-tier.ts";
|
|
1
2
|
/** Who pays, or a refusal for a payer this tool does not know. */
|
|
2
3
|
export declare function payerOf(pay: string | undefined): "credits" | "wallet";
|
|
3
4
|
/** The options that only mean something when the wallet pays, refused when it does not. */
|
|
@@ -8,3 +9,23 @@ export declare function refuseWalletOnlyOptions(options: {
|
|
|
8
9
|
trustServerTipAddress?: boolean;
|
|
9
10
|
from?: string | undefined;
|
|
10
11
|
}): void;
|
|
12
|
+
/** What NMTS Heavy adds to an upload command line: the tier, and the self-paid knobs. */
|
|
13
|
+
export interface HeavyFlags {
|
|
14
|
+
/** `--tier standard|heavy`. Absent = standard. */
|
|
15
|
+
tier?: string | undefined;
|
|
16
|
+
/** `--tier heavy --pay evm`: how many copies, 1..12 (default 2). */
|
|
17
|
+
copies?: string | undefined;
|
|
18
|
+
/** `--tier heavy --pay evm`: which storage companies, by id, comma-separated. */
|
|
19
|
+
providers?: string | undefined;
|
|
20
|
+
/** `--tier heavy --pay evm`: which of this key's EVM wallets pays. Absent = 0. */
|
|
21
|
+
evmWallet?: string | undefined;
|
|
22
|
+
/** `--tier heavy --pay wallet`: how many days to keep it, 1..365 (default 28). */
|
|
23
|
+
days?: string | undefined;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Which tier this upload goes to — the same reader the browser and the SDK use — and a refusal for
|
|
27
|
+
* every option that means nothing on that tier. Decided before a file is measured.
|
|
28
|
+
*/
|
|
29
|
+
export declare function tierOf(options: HeavyFlags & {
|
|
30
|
+
pay?: string | undefined;
|
|
31
|
+
}): StorageTier;
|
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
// ⚠ They moved out of `put.ts` on 2026-09-16 (`--wallet` joined them and that file has a ceiling).
|
|
8
8
|
// `put.ts` re-exports them, so `push.ts` and the tests spell the same path they always did.
|
|
9
9
|
import { NmtsError } from "../errors.js";
|
|
10
|
+
import { HEAVY_COPY } from "../heavy-copy.js";
|
|
11
|
+
import { DEFAULT_STORAGE_TIER, parseStorageTier } from "../shared/lib/storage-tier.js";
|
|
10
12
|
/** Who pays, or a refusal for a payer this tool does not know. */
|
|
11
13
|
export function payerOf(pay) {
|
|
12
14
|
if (pay === undefined || pay === "credits")
|
|
@@ -51,3 +53,25 @@ export function refuseWalletOnlyOptions(options) {
|
|
|
51
53
|
});
|
|
52
54
|
}
|
|
53
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* Which tier this upload goes to — the same reader the browser and the SDK use — and a refusal for
|
|
58
|
+
* every option that means nothing on that tier. Decided before a file is measured.
|
|
59
|
+
*/
|
|
60
|
+
export function tierOf(options) {
|
|
61
|
+
let tier;
|
|
62
|
+
try {
|
|
63
|
+
tier = options.tier === undefined ? DEFAULT_STORAGE_TIER : parseStorageTier(options.tier);
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
throw new NmtsError(error instanceof Error ? error.message : String(error), { exitCode: 2 });
|
|
67
|
+
}
|
|
68
|
+
if (tier === "standard") {
|
|
69
|
+
if (options.pay === "evm")
|
|
70
|
+
throw new NmtsError(HEAVY_COPY.evmNeedsHeavy, { exitCode: 2 });
|
|
71
|
+
for (const [flag, value] of [["--copies", options.copies], ["--providers", options.providers], ["--evm-wallet", options.evmWallet], ["--days", options.days]]) {
|
|
72
|
+
if (value !== undefined)
|
|
73
|
+
throw new NmtsError(HEAVY_COPY.heavyOnlyFlag(flag), { exitCode: 2 });
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return tier;
|
|
77
|
+
}
|
|
@@ -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,
|
package/dist/commands/put.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ManifestEntry } from "../shared/lib/drive/manifest-codec.ts";
|
|
2
|
-
export interface PutOptions {
|
|
2
|
+
export interface PutOptions extends HeavyFlags {
|
|
3
3
|
server?: string | undefined;
|
|
4
4
|
network?: string | undefined;
|
|
5
5
|
/** The name it gets in the drive. Defaults to the local file's own name. */
|
|
@@ -44,9 +44,17 @@ 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
|
-
import { payerOf, refuseWalletOnlyOptions } from "./put-payer.ts";
|
|
57
|
+
import { payerOf, refuseWalletOnlyOptions, type HeavyFlags } from "./put-payer.ts";
|
|
50
58
|
export { payerOf, refuseWalletOnlyOptions };
|
|
51
59
|
/**
|
|
52
60
|
* The folder id `--to` names, or null for the root. Refuses rather than guessing.
|
package/dist/commands/put.js
CHANGED
|
@@ -27,15 +27,15 @@ import { paddingRuleOf, readFileList } from "../manifest.js";
|
|
|
27
27
|
import { resolveNetwork } from "../network.js";
|
|
28
28
|
import { BINARY_NAME } from "../product.js";
|
|
29
29
|
import { resolveServer } from "../server.js";
|
|
30
|
-
import {
|
|
30
|
+
import { forgetUpload } from "../upload-run.js";
|
|
31
31
|
import { createUploadApi } from "../upload-api.js";
|
|
32
|
-
import {
|
|
32
|
+
import { uploadFile } from "../upload-file.js";
|
|
33
33
|
import { fileSource } from "../upload-file-node.js";
|
|
34
34
|
import { CREDIT_BYTES, creditsFor, partSizeFor, planAndPrice, UPLOAD_EPOCHS } from "../upload-price.js";
|
|
35
35
|
import { measureLocal } from "../upload-price-node.js";
|
|
36
36
|
import { createBlobProtocol, readCurrentEpoch } from "../walrus-write.js";
|
|
37
37
|
/** Who pays, and the options that lose their meaning under that answer — the rule is in `put-payer.ts`; this is its one road. */
|
|
38
|
-
import { payerOf, refuseWalletOnlyOptions } from "./put-payer.js";
|
|
38
|
+
import { payerOf, refuseWalletOnlyOptions, tierOf } from "./put-payer.js";
|
|
39
39
|
export { payerOf, refuseWalletOnlyOptions };
|
|
40
40
|
/**
|
|
41
41
|
* The folder id `--to` names, or null for the root. Refuses rather than guessing.
|
|
@@ -69,6 +69,12 @@ export function folderIdFor(wanted, entries) {
|
|
|
69
69
|
return folder.id;
|
|
70
70
|
}
|
|
71
71
|
export async function put(target, options = {}) {
|
|
72
|
+
// NMTS Heavy is its own road (`put-heavy.ts`), taken before the preview picture: Heavy refuses one.
|
|
73
|
+
if (tierOf(options) === "heavy")
|
|
74
|
+
return (await import("./put-heavy.js")).putHeavy(target, options);
|
|
75
|
+
if (options.thumbnail === true || options.thumbnailFile !== undefined) {
|
|
76
|
+
return (await import("./put-thumbnail.js")).putWithThumbnail(target, options, put);
|
|
77
|
+
}
|
|
72
78
|
// ⛔ DECIDED BEFORE ANYTHING IS READ. The wallet path prices in WAL and signs; nothing below this
|
|
73
79
|
// line knows how to do either, and it must not learn.
|
|
74
80
|
if (payerOf(options.pay) === "wallet") {
|
|
@@ -258,14 +264,14 @@ export async function put(target, options = {}) {
|
|
|
258
264
|
updatedAt: now,
|
|
259
265
|
dekWrapped: result.entry.dekWrapped,
|
|
260
266
|
contentHashCt: result.entry.contentHashCt,
|
|
267
|
+
...(options.thumbOf !== undefined ? { thumbOf: options.thumbOf } : {}),
|
|
261
268
|
},
|
|
262
269
|
});
|
|
270
|
+
options.onStored?.(result.itemId, added.name);
|
|
263
271
|
// ⛔ ONLY NOW, AND EVERY PART. Until the entry is in the list the file is paid for and invisible,
|
|
264
272
|
// and the records are the only thing that lets a second run finish the job without spending
|
|
265
|
-
// again.
|
|
266
|
-
await
|
|
267
|
-
for (const record of partKeysOf(result.fileKey, result.parts))
|
|
268
|
-
await clearReservation(record);
|
|
273
|
+
// again. The order they are forgotten in is `forgetUpload`'s.
|
|
274
|
+
await forgetUpload(result.fileKey, result.parts);
|
|
269
275
|
// ⛔ THE DISPLACED FILE IS TOLD TO THE SERVER ONLY NOW, and only after the new one is in the
|
|
270
276
|
// list. Until this line the person still had the file they started with.
|
|
271
277
|
// ⚠ A failure here leaves it hidden in this account's trash while the server still counts it as
|
package/dist/commands/receive.js
CHANGED
|
@@ -81,9 +81,9 @@ export async function receive(id, options = {}) {
|
|
|
81
81
|
? null
|
|
82
82
|
: options.out !== undefined
|
|
83
83
|
? resolve(options.out)
|
|
84
|
-
:
|
|
85
|
-
|
|
86
|
-
|
|
84
|
+
: // ⛔ The name is the SENDER'S choice, so it lands in a directory by its last segment only:
|
|
85
|
+
// `../x` or an absolute path must not put a file outside where this tool was run.
|
|
86
|
+
destinationFor(options.intoDir ?? ".", opened.name);
|
|
87
87
|
// ⛔ `--force` has nothing to overwrite on the stdout branch and is ignored there on purpose.
|
|
88
88
|
// On the disk branch the file streams into a temporary name beside the destination and is
|
|
89
89
|
// renamed into place only once the sender's digest matches, so a share that turns out to be
|