stow-cli 2.0.4 → 2.2.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/LICENSE +21 -0
- package/README.md +363 -0
- package/dist/app-Q6EW7VSM.js +249 -0
- package/dist/backfill-EVZT7RH6.js +67 -0
- package/dist/buckets-ESAOL6CH.js +115 -0
- package/dist/buckets-ZHP3LBLC.js +137 -0
- package/dist/chunk-3BLL5SQJ.js +27 -0
- package/dist/chunk-FZGOTXTE.js +45 -0
- package/dist/chunk-OHAFRKN5.js +40 -0
- package/dist/chunk-P2BKGBQE.js +136 -0
- package/dist/chunk-PLZFHPLC.js +52 -0
- package/dist/chunk-XJDK2CBE.js +328 -0
- package/dist/cli.js +123 -398
- package/dist/delete-4JSVNETO.js +34 -0
- package/dist/delete-YEXSMG4I.js +34 -0
- package/dist/describe-J4ZMUXK7.js +79 -0
- package/dist/describe-UFMXNNUB.js +79 -0
- package/dist/drops-5VIEW3XZ.js +39 -0
- package/dist/files-TDIGJDN3.js +185 -0
- package/dist/files-UQODXWNT.js +206 -0
- package/dist/health-RICGWQGN.js +61 -0
- package/dist/jobs-PTV2W5PJ.js +102 -0
- package/dist/jobs-ZWSEXNFA.js +90 -0
- package/dist/maintenance-ZJW2ES4L.js +79 -0
- package/dist/mcp-RZT4TJEX.js +190 -0
- package/dist/profiles-CHBGKQOE.js +53 -0
- package/dist/queues-EZ2VZGXQ.js +61 -0
- package/dist/search-TRTPX2SQ.js +135 -0
- package/dist/tags-MCFL5M2J.js +82 -0
- package/dist/tags-VH44BGQL.js +90 -0
- package/dist/upload-5TAWJU5N.js +126 -0
- package/dist/upload-OS6Q6LW5.js +126 -0
- package/dist/whoami-TVRKBM74.js +28 -0
- package/package.json +14 -12
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isJsonOutput,
|
|
3
|
+
output
|
|
4
|
+
} from "./chunk-P2BKGBQE.js";
|
|
5
|
+
import {
|
|
6
|
+
formatBytes,
|
|
7
|
+
formatTable
|
|
8
|
+
} from "./chunk-FZGOTXTE.js";
|
|
9
|
+
import {
|
|
10
|
+
createStow
|
|
11
|
+
} from "./chunk-5LU25QZK.js";
|
|
12
|
+
import "./chunk-TOADDO2F.js";
|
|
13
|
+
|
|
14
|
+
// src/commands/search.ts
|
|
15
|
+
async function textSearch(query, options) {
|
|
16
|
+
const stow = createStow();
|
|
17
|
+
const parsedLimit = options.limit ? Number.parseInt(options.limit, 10) : null;
|
|
18
|
+
const data = await stow.search.text({
|
|
19
|
+
query,
|
|
20
|
+
...options.bucket ? { bucket: options.bucket } : {},
|
|
21
|
+
...parsedLimit && parsedLimit > 0 ? { limit: parsedLimit } : {}
|
|
22
|
+
});
|
|
23
|
+
if (data.results.length === 0) {
|
|
24
|
+
if (isJsonOutput() || options.json) {
|
|
25
|
+
output(data);
|
|
26
|
+
} else {
|
|
27
|
+
console.log("No results found.");
|
|
28
|
+
}
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
output(
|
|
32
|
+
data,
|
|
33
|
+
() => {
|
|
34
|
+
const rows = data.results.map((r) => [
|
|
35
|
+
r.key,
|
|
36
|
+
formatBytes(r.size),
|
|
37
|
+
r.similarity.toFixed(3)
|
|
38
|
+
]);
|
|
39
|
+
return formatTable(["Key", "Size", "Similarity"], rows);
|
|
40
|
+
},
|
|
41
|
+
{ json: options.json }
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
async function similarSearch(options) {
|
|
45
|
+
const stow = createStow();
|
|
46
|
+
const parsedLimit = options.limit ? Number.parseInt(options.limit, 10) : null;
|
|
47
|
+
const data = await stow.search.similar({
|
|
48
|
+
fileKey: options.file,
|
|
49
|
+
...options.bucket ? { bucket: options.bucket } : {},
|
|
50
|
+
...parsedLimit && parsedLimit > 0 ? { limit: parsedLimit } : {}
|
|
51
|
+
});
|
|
52
|
+
if (data.results.length === 0) {
|
|
53
|
+
if (isJsonOutput() || options.json) {
|
|
54
|
+
output(data);
|
|
55
|
+
} else {
|
|
56
|
+
console.log("No similar files found.");
|
|
57
|
+
}
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
output(
|
|
61
|
+
data,
|
|
62
|
+
() => {
|
|
63
|
+
const rows = data.results.map((r) => [
|
|
64
|
+
r.key,
|
|
65
|
+
formatBytes(r.size),
|
|
66
|
+
r.similarity.toFixed(3)
|
|
67
|
+
]);
|
|
68
|
+
return formatTable(["Key", "Size", "Similarity"], rows);
|
|
69
|
+
},
|
|
70
|
+
{ json: options.json }
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
async function colorSearch(options) {
|
|
74
|
+
const stow = createStow();
|
|
75
|
+
const parsedLimit = options.limit ? Number.parseInt(options.limit, 10) : null;
|
|
76
|
+
const data = await stow.search.color({
|
|
77
|
+
hex: options.hex,
|
|
78
|
+
...options.bucket ? { bucket: options.bucket } : {},
|
|
79
|
+
...parsedLimit && parsedLimit > 0 ? { limit: parsedLimit } : {}
|
|
80
|
+
});
|
|
81
|
+
if (data.results.length === 0) {
|
|
82
|
+
if (isJsonOutput() || options.json) {
|
|
83
|
+
output(data);
|
|
84
|
+
} else {
|
|
85
|
+
console.log("No results found.");
|
|
86
|
+
}
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
output(
|
|
90
|
+
data,
|
|
91
|
+
() => {
|
|
92
|
+
const rows = data.results.map((r) => [
|
|
93
|
+
r.key,
|
|
94
|
+
r.contentType,
|
|
95
|
+
r.colorDistance.toFixed(3)
|
|
96
|
+
]);
|
|
97
|
+
return formatTable(["Key", "Type", "Distance"], rows);
|
|
98
|
+
},
|
|
99
|
+
{ json: options.json }
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
async function diverseSearch(options) {
|
|
103
|
+
const stow = createStow();
|
|
104
|
+
const parsedLimit = options.limit ? Number.parseInt(options.limit, 10) : null;
|
|
105
|
+
const data = await stow.search.diverse({
|
|
106
|
+
...options.bucket ? { bucket: options.bucket } : {},
|
|
107
|
+
...parsedLimit && parsedLimit > 0 ? { limit: parsedLimit } : {}
|
|
108
|
+
});
|
|
109
|
+
if (data.results.length === 0) {
|
|
110
|
+
if (isJsonOutput() || options.json) {
|
|
111
|
+
output(data);
|
|
112
|
+
} else {
|
|
113
|
+
console.log("No results found.");
|
|
114
|
+
}
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
output(
|
|
118
|
+
data,
|
|
119
|
+
() => {
|
|
120
|
+
const rows = data.results.map((r) => [
|
|
121
|
+
r.key,
|
|
122
|
+
formatBytes(r.size),
|
|
123
|
+
r.similarity.toFixed(3)
|
|
124
|
+
]);
|
|
125
|
+
return formatTable(["Key", "Size", "Similarity"], rows);
|
|
126
|
+
},
|
|
127
|
+
{ json: options.json }
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
export {
|
|
131
|
+
colorSearch,
|
|
132
|
+
diverseSearch,
|
|
133
|
+
similarSearch,
|
|
134
|
+
textSearch
|
|
135
|
+
};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import {
|
|
2
|
+
validateInput
|
|
3
|
+
} from "./chunk-OHAFRKN5.js";
|
|
4
|
+
import {
|
|
5
|
+
formatTable,
|
|
6
|
+
outputJson
|
|
7
|
+
} from "./chunk-ELSDWMEB.js";
|
|
8
|
+
import {
|
|
9
|
+
createStow
|
|
10
|
+
} from "./chunk-5LU25QZK.js";
|
|
11
|
+
import "./chunk-TOADDO2F.js";
|
|
12
|
+
|
|
13
|
+
// src/commands/tags.ts
|
|
14
|
+
async function listTags(options) {
|
|
15
|
+
const stow = createStow();
|
|
16
|
+
const data = await stow.tags.list();
|
|
17
|
+
if (options.json) {
|
|
18
|
+
outputJson(data);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
if (data.tags.length === 0) {
|
|
22
|
+
console.log("No tags yet. Create one with: stow tags create <name>");
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const rows = data.tags.map((t) => [t.name, t.slug, t.color ?? "\u2014", t.id]);
|
|
26
|
+
console.log(formatTable(["Name", "Slug", "Color", "ID"], rows));
|
|
27
|
+
}
|
|
28
|
+
async function createTag(name, options) {
|
|
29
|
+
validateInput(name, "tag name");
|
|
30
|
+
if (options.dryRun) {
|
|
31
|
+
console.log(
|
|
32
|
+
JSON.stringify(
|
|
33
|
+
{
|
|
34
|
+
dryRun: true,
|
|
35
|
+
action: "createTag",
|
|
36
|
+
details: {
|
|
37
|
+
name,
|
|
38
|
+
color: options.color ?? null
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
null,
|
|
42
|
+
2
|
|
43
|
+
)
|
|
44
|
+
);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const stow = createStow();
|
|
48
|
+
const tag = await stow.tags.create({
|
|
49
|
+
name,
|
|
50
|
+
...options.color ? { color: options.color } : {}
|
|
51
|
+
});
|
|
52
|
+
if (options.json) {
|
|
53
|
+
outputJson(tag);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
console.log(`Created tag: ${tag.name}`);
|
|
57
|
+
}
|
|
58
|
+
async function deleteTag(id, options = {}) {
|
|
59
|
+
validateInput(id, "tag id");
|
|
60
|
+
if (options.dryRun) {
|
|
61
|
+
console.log(
|
|
62
|
+
JSON.stringify(
|
|
63
|
+
{
|
|
64
|
+
dryRun: true,
|
|
65
|
+
action: "deleteTag",
|
|
66
|
+
details: { id }
|
|
67
|
+
},
|
|
68
|
+
null,
|
|
69
|
+
2
|
|
70
|
+
)
|
|
71
|
+
);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const stow = createStow();
|
|
75
|
+
await stow.tags.delete(id);
|
|
76
|
+
console.log(`Deleted tag: ${id}`);
|
|
77
|
+
}
|
|
78
|
+
export {
|
|
79
|
+
createTag,
|
|
80
|
+
deleteTag,
|
|
81
|
+
listTags
|
|
82
|
+
};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import {
|
|
2
|
+
parseJsonInput
|
|
3
|
+
} from "./chunk-3BLL5SQJ.js";
|
|
4
|
+
import {
|
|
5
|
+
validateInput
|
|
6
|
+
} from "./chunk-PLZFHPLC.js";
|
|
7
|
+
import {
|
|
8
|
+
isJsonOutput,
|
|
9
|
+
output
|
|
10
|
+
} from "./chunk-P2BKGBQE.js";
|
|
11
|
+
import {
|
|
12
|
+
formatTable
|
|
13
|
+
} from "./chunk-FZGOTXTE.js";
|
|
14
|
+
import {
|
|
15
|
+
createStow
|
|
16
|
+
} from "./chunk-5LU25QZK.js";
|
|
17
|
+
import "./chunk-TOADDO2F.js";
|
|
18
|
+
|
|
19
|
+
// src/commands/tags.ts
|
|
20
|
+
async function listTags(options) {
|
|
21
|
+
const stow = createStow();
|
|
22
|
+
const data = await stow.tags.list();
|
|
23
|
+
if (data.tags.length === 0) {
|
|
24
|
+
if (isJsonOutput() || options.json) {
|
|
25
|
+
output(data);
|
|
26
|
+
} else {
|
|
27
|
+
console.log("No tags yet. Create one with: stow tags create <name>");
|
|
28
|
+
}
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
output(data, () => {
|
|
32
|
+
const rows = data.tags.map((t) => [t.name, t.slug, t.color ?? "\u2014", t.id]);
|
|
33
|
+
return formatTable(["Name", "Slug", "Color", "ID"], rows);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
async function createTag(name, options) {
|
|
37
|
+
const input = parseJsonInput(
|
|
38
|
+
options.inputJson,
|
|
39
|
+
{ name, color: options.color }
|
|
40
|
+
);
|
|
41
|
+
validateInput(input.name, "tag name");
|
|
42
|
+
if (options.dryRun) {
|
|
43
|
+
console.log(
|
|
44
|
+
JSON.stringify(
|
|
45
|
+
{
|
|
46
|
+
dryRun: true,
|
|
47
|
+
action: "createTag",
|
|
48
|
+
details: {
|
|
49
|
+
name: input.name,
|
|
50
|
+
color: input.color ?? null
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
null,
|
|
54
|
+
2
|
|
55
|
+
)
|
|
56
|
+
);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const stow = createStow();
|
|
60
|
+
const tag = await stow.tags.create({
|
|
61
|
+
name: input.name,
|
|
62
|
+
...input.color ? { color: input.color } : {}
|
|
63
|
+
});
|
|
64
|
+
output(tag, () => `Created tag: ${tag.name}`);
|
|
65
|
+
}
|
|
66
|
+
async function deleteTag(id, options = {}) {
|
|
67
|
+
validateInput(id, "tag id");
|
|
68
|
+
if (options.dryRun) {
|
|
69
|
+
console.log(
|
|
70
|
+
JSON.stringify(
|
|
71
|
+
{
|
|
72
|
+
dryRun: true,
|
|
73
|
+
action: "deleteTag",
|
|
74
|
+
details: { id }
|
|
75
|
+
},
|
|
76
|
+
null,
|
|
77
|
+
2
|
|
78
|
+
)
|
|
79
|
+
);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const stow = createStow();
|
|
83
|
+
await stow.tags.delete(id);
|
|
84
|
+
console.log(`Deleted tag: ${id}`);
|
|
85
|
+
}
|
|
86
|
+
export {
|
|
87
|
+
createTag,
|
|
88
|
+
deleteTag,
|
|
89
|
+
listTags
|
|
90
|
+
};
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import {
|
|
2
|
+
validateBucketName
|
|
3
|
+
} from "./chunk-OHAFRKN5.js";
|
|
4
|
+
import {
|
|
5
|
+
formatBytes
|
|
6
|
+
} from "./chunk-ELSDWMEB.js";
|
|
7
|
+
import {
|
|
8
|
+
createStow
|
|
9
|
+
} from "./chunk-5LU25QZK.js";
|
|
10
|
+
import "./chunk-TOADDO2F.js";
|
|
11
|
+
|
|
12
|
+
// src/commands/upload.ts
|
|
13
|
+
import { existsSync, readFileSync, statSync } from "fs";
|
|
14
|
+
import { basename, resolve } from "path";
|
|
15
|
+
var CONTENT_TYPES = {
|
|
16
|
+
png: "image/png",
|
|
17
|
+
jpg: "image/jpeg",
|
|
18
|
+
jpeg: "image/jpeg",
|
|
19
|
+
gif: "image/gif",
|
|
20
|
+
webp: "image/webp",
|
|
21
|
+
svg: "image/svg+xml",
|
|
22
|
+
ico: "image/x-icon",
|
|
23
|
+
avif: "image/avif",
|
|
24
|
+
pdf: "application/pdf",
|
|
25
|
+
mp4: "video/mp4",
|
|
26
|
+
webm: "video/webm",
|
|
27
|
+
mov: "video/quicktime",
|
|
28
|
+
mp3: "audio/mpeg",
|
|
29
|
+
wav: "audio/wav",
|
|
30
|
+
ogg: "audio/ogg",
|
|
31
|
+
zip: "application/zip",
|
|
32
|
+
tar: "application/x-tar",
|
|
33
|
+
gz: "application/gzip",
|
|
34
|
+
txt: "text/plain",
|
|
35
|
+
json: "application/json",
|
|
36
|
+
xml: "application/xml",
|
|
37
|
+
html: "text/html",
|
|
38
|
+
css: "text/css",
|
|
39
|
+
js: "application/javascript"
|
|
40
|
+
};
|
|
41
|
+
function getContentType(filename) {
|
|
42
|
+
const ext = filename.toLowerCase().split(".").pop();
|
|
43
|
+
return CONTENT_TYPES[ext || ""] || "application/octet-stream";
|
|
44
|
+
}
|
|
45
|
+
function readFile(filePath) {
|
|
46
|
+
const resolvedPath = resolve(filePath);
|
|
47
|
+
if (!existsSync(resolvedPath)) {
|
|
48
|
+
console.error(`Error: File not found: ${filePath}`);
|
|
49
|
+
process.exit(1);
|
|
50
|
+
}
|
|
51
|
+
const buffer = readFileSync(resolvedPath);
|
|
52
|
+
const filename = basename(resolvedPath);
|
|
53
|
+
const contentType = getContentType(filename);
|
|
54
|
+
return { buffer, filename, contentType };
|
|
55
|
+
}
|
|
56
|
+
function printUploadResult(url, options, opts) {
|
|
57
|
+
if (options.quiet) {
|
|
58
|
+
console.log(url);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
console.error(opts?.deduped ? "Done! (deduped)" : "Done!");
|
|
62
|
+
console.log("");
|
|
63
|
+
console.log(url);
|
|
64
|
+
}
|
|
65
|
+
async function uploadDrop(filePath, options) {
|
|
66
|
+
const { buffer, filename, contentType } = readFile(filePath);
|
|
67
|
+
if (!options.quiet) {
|
|
68
|
+
console.error(`Uploading ${filename} (${formatBytes(buffer.length)})...`);
|
|
69
|
+
}
|
|
70
|
+
const stow = createStow();
|
|
71
|
+
const result = await stow.drop(buffer, {
|
|
72
|
+
filename,
|
|
73
|
+
contentType
|
|
74
|
+
});
|
|
75
|
+
printUploadResult(result.url, options);
|
|
76
|
+
}
|
|
77
|
+
async function uploadFile(filePath, options) {
|
|
78
|
+
if (options.bucket) {
|
|
79
|
+
validateBucketName(options.bucket);
|
|
80
|
+
}
|
|
81
|
+
const resolvedPath = resolve(filePath);
|
|
82
|
+
if (!existsSync(resolvedPath)) {
|
|
83
|
+
console.error(`Error: File not found: ${filePath}`);
|
|
84
|
+
process.exit(1);
|
|
85
|
+
}
|
|
86
|
+
const filename = basename(resolvedPath);
|
|
87
|
+
const contentType = getContentType(filename);
|
|
88
|
+
const size = statSync(resolvedPath).size;
|
|
89
|
+
if (options.dryRun) {
|
|
90
|
+
console.log(
|
|
91
|
+
JSON.stringify(
|
|
92
|
+
{
|
|
93
|
+
dryRun: true,
|
|
94
|
+
action: "upload",
|
|
95
|
+
details: {
|
|
96
|
+
file: resolvedPath,
|
|
97
|
+
filename,
|
|
98
|
+
contentType,
|
|
99
|
+
size,
|
|
100
|
+
bucket: options.bucket ?? null
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
null,
|
|
104
|
+
2
|
|
105
|
+
)
|
|
106
|
+
);
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
const buffer = readFileSync(resolvedPath);
|
|
110
|
+
if (!options.quiet) {
|
|
111
|
+
console.error(`Uploading ${filename} (${formatBytes(buffer.length)})...`);
|
|
112
|
+
}
|
|
113
|
+
const stow = createStow();
|
|
114
|
+
const result = await stow.uploadFile(buffer, {
|
|
115
|
+
...options.bucket ? { bucket: options.bucket } : {},
|
|
116
|
+
filename,
|
|
117
|
+
contentType
|
|
118
|
+
});
|
|
119
|
+
printUploadResult(result.url ?? result.key, options, {
|
|
120
|
+
deduped: result.deduped
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
export {
|
|
124
|
+
uploadDrop,
|
|
125
|
+
uploadFile
|
|
126
|
+
};
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import {
|
|
2
|
+
validateBucketName
|
|
3
|
+
} from "./chunk-PLZFHPLC.js";
|
|
4
|
+
import {
|
|
5
|
+
formatBytes
|
|
6
|
+
} from "./chunk-FZGOTXTE.js";
|
|
7
|
+
import {
|
|
8
|
+
createStow
|
|
9
|
+
} from "./chunk-5LU25QZK.js";
|
|
10
|
+
import "./chunk-TOADDO2F.js";
|
|
11
|
+
|
|
12
|
+
// src/commands/upload.ts
|
|
13
|
+
import { existsSync, readFileSync, statSync } from "fs";
|
|
14
|
+
import { basename, resolve } from "path";
|
|
15
|
+
var CONTENT_TYPES = {
|
|
16
|
+
png: "image/png",
|
|
17
|
+
jpg: "image/jpeg",
|
|
18
|
+
jpeg: "image/jpeg",
|
|
19
|
+
gif: "image/gif",
|
|
20
|
+
webp: "image/webp",
|
|
21
|
+
svg: "image/svg+xml",
|
|
22
|
+
ico: "image/x-icon",
|
|
23
|
+
avif: "image/avif",
|
|
24
|
+
pdf: "application/pdf",
|
|
25
|
+
mp4: "video/mp4",
|
|
26
|
+
webm: "video/webm",
|
|
27
|
+
mov: "video/quicktime",
|
|
28
|
+
mp3: "audio/mpeg",
|
|
29
|
+
wav: "audio/wav",
|
|
30
|
+
ogg: "audio/ogg",
|
|
31
|
+
zip: "application/zip",
|
|
32
|
+
tar: "application/x-tar",
|
|
33
|
+
gz: "application/gzip",
|
|
34
|
+
txt: "text/plain",
|
|
35
|
+
json: "application/json",
|
|
36
|
+
xml: "application/xml",
|
|
37
|
+
html: "text/html",
|
|
38
|
+
css: "text/css",
|
|
39
|
+
js: "application/javascript"
|
|
40
|
+
};
|
|
41
|
+
function getContentType(filename) {
|
|
42
|
+
const ext = filename.toLowerCase().split(".").pop();
|
|
43
|
+
return CONTENT_TYPES[ext || ""] || "application/octet-stream";
|
|
44
|
+
}
|
|
45
|
+
function readFile(filePath) {
|
|
46
|
+
const resolvedPath = resolve(filePath);
|
|
47
|
+
if (!existsSync(resolvedPath)) {
|
|
48
|
+
console.error(`Error: File not found: ${filePath}`);
|
|
49
|
+
process.exit(1);
|
|
50
|
+
}
|
|
51
|
+
const buffer = readFileSync(resolvedPath);
|
|
52
|
+
const filename = basename(resolvedPath);
|
|
53
|
+
const contentType = getContentType(filename);
|
|
54
|
+
return { buffer, filename, contentType };
|
|
55
|
+
}
|
|
56
|
+
function printUploadResult(url, options, opts) {
|
|
57
|
+
if (options.quiet) {
|
|
58
|
+
console.log(url);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
console.error(opts?.deduped ? "Done! (deduped)" : "Done!");
|
|
62
|
+
console.log("");
|
|
63
|
+
console.log(url);
|
|
64
|
+
}
|
|
65
|
+
async function uploadDrop(filePath, options) {
|
|
66
|
+
const { buffer, filename, contentType } = readFile(filePath);
|
|
67
|
+
if (!options.quiet) {
|
|
68
|
+
console.error(`Uploading ${filename} (${formatBytes(buffer.length)})...`);
|
|
69
|
+
}
|
|
70
|
+
const stow = createStow();
|
|
71
|
+
const result = await stow.drop(buffer, {
|
|
72
|
+
filename,
|
|
73
|
+
contentType
|
|
74
|
+
});
|
|
75
|
+
printUploadResult(result.url, options);
|
|
76
|
+
}
|
|
77
|
+
async function uploadFile(filePath, options) {
|
|
78
|
+
if (options.bucket) {
|
|
79
|
+
validateBucketName(options.bucket);
|
|
80
|
+
}
|
|
81
|
+
const resolvedPath = resolve(filePath);
|
|
82
|
+
if (!existsSync(resolvedPath)) {
|
|
83
|
+
console.error(`Error: File not found: ${filePath}`);
|
|
84
|
+
process.exit(1);
|
|
85
|
+
}
|
|
86
|
+
const filename = basename(resolvedPath);
|
|
87
|
+
const contentType = getContentType(filename);
|
|
88
|
+
const size = statSync(resolvedPath).size;
|
|
89
|
+
if (options.dryRun) {
|
|
90
|
+
console.log(
|
|
91
|
+
JSON.stringify(
|
|
92
|
+
{
|
|
93
|
+
dryRun: true,
|
|
94
|
+
action: "upload",
|
|
95
|
+
details: {
|
|
96
|
+
file: resolvedPath,
|
|
97
|
+
filename,
|
|
98
|
+
contentType,
|
|
99
|
+
size,
|
|
100
|
+
bucket: options.bucket ?? null
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
null,
|
|
104
|
+
2
|
|
105
|
+
)
|
|
106
|
+
);
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
const buffer = readFileSync(resolvedPath);
|
|
110
|
+
if (!options.quiet) {
|
|
111
|
+
console.error(`Uploading ${filename} (${formatBytes(buffer.length)})...`);
|
|
112
|
+
}
|
|
113
|
+
const stow = createStow();
|
|
114
|
+
const result = await stow.uploadFile(buffer, {
|
|
115
|
+
...options.bucket ? { bucket: options.bucket } : {},
|
|
116
|
+
filename,
|
|
117
|
+
contentType
|
|
118
|
+
});
|
|
119
|
+
printUploadResult(result.url ?? result.key, options, {
|
|
120
|
+
deduped: result.deduped
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
export {
|
|
124
|
+
uploadDrop,
|
|
125
|
+
uploadFile
|
|
126
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import {
|
|
2
|
+
formatBytes
|
|
3
|
+
} from "./chunk-FZGOTXTE.js";
|
|
4
|
+
import {
|
|
5
|
+
createStow
|
|
6
|
+
} from "./chunk-5LU25QZK.js";
|
|
7
|
+
import "./chunk-TOADDO2F.js";
|
|
8
|
+
|
|
9
|
+
// src/commands/whoami.ts
|
|
10
|
+
async function whoami() {
|
|
11
|
+
const stow = createStow();
|
|
12
|
+
const data = await stow.whoami();
|
|
13
|
+
console.log(`Account: ${data.user.email}`);
|
|
14
|
+
console.log("");
|
|
15
|
+
console.log(`Buckets: ${data.stats.bucketCount}`);
|
|
16
|
+
console.log(`Files: ${data.stats.totalFiles}`);
|
|
17
|
+
console.log(`Storage: ${formatBytes(data.stats.totalBytes)}`);
|
|
18
|
+
if (data.key) {
|
|
19
|
+
console.log("");
|
|
20
|
+
console.log(`API Key: ${data.key.name}`);
|
|
21
|
+
console.log(`Scope: ${data.key.scope}`);
|
|
22
|
+
const perms = Object.entries(data.key.permissions).filter(([, v]) => v).map(([k]) => k);
|
|
23
|
+
console.log(`Perms: ${perms.join(", ")}`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
export {
|
|
27
|
+
whoami
|
|
28
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stow-cli",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "CLI for Stow file storage",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,14 +22,8 @@
|
|
|
22
22
|
"files": [
|
|
23
23
|
"dist"
|
|
24
24
|
],
|
|
25
|
-
"scripts": {
|
|
26
|
-
"build": "tsup src/cli.ts --format esm --shims",
|
|
27
|
-
"dev": "tsup src/cli.ts --format esm --shims --watch",
|
|
28
|
-
"test": "vitest run",
|
|
29
|
-
"test:watch": "vitest"
|
|
30
|
-
},
|
|
31
25
|
"dependencies": {
|
|
32
|
-
"@
|
|
26
|
+
"@modelcontextprotocol/sdk": "^1.27.1",
|
|
33
27
|
"clipboardy": "^5.3.1",
|
|
34
28
|
"commander": "^14.0.3",
|
|
35
29
|
"ink": "^6.8.0",
|
|
@@ -37,14 +31,22 @@
|
|
|
37
31
|
"ink-spinner": "^5.0.0",
|
|
38
32
|
"ink-text-input": "^6.0.0",
|
|
39
33
|
"open": "^11.0.0",
|
|
40
|
-
"react": "^19.2.4"
|
|
34
|
+
"react": "^19.2.4",
|
|
35
|
+
"zod": "^4.3.6",
|
|
36
|
+
"@howells/stow-server": "2.2.0"
|
|
41
37
|
},
|
|
42
38
|
"devDependencies": {
|
|
43
|
-
"@stow/typescript-config": "workspace:*",
|
|
44
39
|
"@types/node": "^25.5.0",
|
|
45
40
|
"@types/react": "19.2.14",
|
|
46
41
|
"tsup": "^8.5.1",
|
|
47
42
|
"typescript": "^5.9.3",
|
|
48
|
-
"vitest": "^4.1.0"
|
|
43
|
+
"vitest": "^4.1.0",
|
|
44
|
+
"@stow/typescript-config": "0.0.0"
|
|
45
|
+
},
|
|
46
|
+
"scripts": {
|
|
47
|
+
"build": "tsup src/cli.ts --format esm --shims",
|
|
48
|
+
"dev": "tsup src/cli.ts --format esm --shims --watch",
|
|
49
|
+
"test": "vitest run",
|
|
50
|
+
"test:watch": "vitest"
|
|
49
51
|
}
|
|
50
|
-
}
|
|
52
|
+
}
|