stow-cli 1.0.2 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,108 @@
1
+ import {
2
+ formatBytes,
3
+ formatTable,
4
+ outputJson
5
+ } from "./chunk-ELSDWMEB.js";
6
+ import {
7
+ createStow
8
+ } from "./chunk-5LU25QZK.js";
9
+ import "./chunk-TOADDO2F.js";
10
+
11
+ // src/commands/search.ts
12
+ async function textSearch(query, options) {
13
+ const stow = createStow();
14
+ const parsedLimit = options.limit ? Number.parseInt(options.limit, 10) : null;
15
+ const data = await stow.search.text({
16
+ query,
17
+ ...options.bucket ? { bucket: options.bucket } : {},
18
+ ...parsedLimit && parsedLimit > 0 ? { limit: parsedLimit } : {}
19
+ });
20
+ if (options.json) {
21
+ outputJson(data);
22
+ return;
23
+ }
24
+ if (data.results.length === 0) {
25
+ console.log("No results found.");
26
+ return;
27
+ }
28
+ const rows = data.results.map((r) => [
29
+ r.key,
30
+ formatBytes(r.size),
31
+ r.similarity.toFixed(3)
32
+ ]);
33
+ console.log(formatTable(["Key", "Size", "Similarity"], rows));
34
+ }
35
+ async function similarSearch(options) {
36
+ const stow = createStow();
37
+ const parsedLimit = options.limit ? Number.parseInt(options.limit, 10) : null;
38
+ const data = await stow.search.similar({
39
+ fileKey: options.file,
40
+ ...options.bucket ? { bucket: options.bucket } : {},
41
+ ...parsedLimit && parsedLimit > 0 ? { limit: parsedLimit } : {}
42
+ });
43
+ if (options.json) {
44
+ outputJson(data);
45
+ return;
46
+ }
47
+ if (data.results.length === 0) {
48
+ console.log("No similar files found.");
49
+ return;
50
+ }
51
+ const rows = data.results.map((r) => [
52
+ r.key,
53
+ formatBytes(r.size),
54
+ r.similarity.toFixed(3)
55
+ ]);
56
+ console.log(formatTable(["Key", "Size", "Similarity"], rows));
57
+ }
58
+ async function colorSearch(options) {
59
+ const stow = createStow();
60
+ const parsedLimit = options.limit ? Number.parseInt(options.limit, 10) : null;
61
+ const data = await stow.search.color({
62
+ hex: options.hex,
63
+ ...options.bucket ? { bucket: options.bucket } : {},
64
+ ...parsedLimit && parsedLimit > 0 ? { limit: parsedLimit } : {}
65
+ });
66
+ if (options.json) {
67
+ outputJson(data);
68
+ return;
69
+ }
70
+ if (data.results.length === 0) {
71
+ console.log("No results found.");
72
+ return;
73
+ }
74
+ const rows = data.results.map((r) => [
75
+ r.key,
76
+ r.contentType,
77
+ r.colorDistance.toFixed(3)
78
+ ]);
79
+ console.log(formatTable(["Key", "Type", "Distance"], rows));
80
+ }
81
+ async function diverseSearch(options) {
82
+ const stow = createStow();
83
+ const parsedLimit = options.limit ? Number.parseInt(options.limit, 10) : null;
84
+ const data = await stow.search.diverse({
85
+ ...options.bucket ? { bucket: options.bucket } : {},
86
+ ...parsedLimit && parsedLimit > 0 ? { limit: parsedLimit } : {}
87
+ });
88
+ if (options.json) {
89
+ outputJson(data);
90
+ return;
91
+ }
92
+ if (data.results.length === 0) {
93
+ console.log("No results found.");
94
+ return;
95
+ }
96
+ const rows = data.results.map((r) => [
97
+ r.key,
98
+ formatBytes(r.size),
99
+ r.similarity.toFixed(3)
100
+ ]);
101
+ console.log(formatTable(["Key", "Size", "Similarity"], rows));
102
+ }
103
+ export {
104
+ colorSearch,
105
+ diverseSearch,
106
+ similarSearch,
107
+ textSearch
108
+ };
@@ -0,0 +1,46 @@
1
+ import {
2
+ formatTable,
3
+ outputJson
4
+ } from "./chunk-ELSDWMEB.js";
5
+ import {
6
+ createStow
7
+ } from "./chunk-5LU25QZK.js";
8
+ import "./chunk-TOADDO2F.js";
9
+
10
+ // src/commands/tags.ts
11
+ async function listTags(options) {
12
+ const stow = createStow();
13
+ const data = await stow.tags.list();
14
+ if (options.json) {
15
+ outputJson(data);
16
+ return;
17
+ }
18
+ if (data.tags.length === 0) {
19
+ console.log("No tags yet. Create one with: stow tags create <name>");
20
+ return;
21
+ }
22
+ const rows = data.tags.map((t) => [t.name, t.slug, t.color ?? "\u2014", t.id]);
23
+ console.log(formatTable(["Name", "Slug", "Color", "ID"], rows));
24
+ }
25
+ async function createTag(name, options) {
26
+ const stow = createStow();
27
+ const tag = await stow.tags.create({
28
+ name,
29
+ ...options.color ? { color: options.color } : {}
30
+ });
31
+ if (options.json) {
32
+ outputJson(tag);
33
+ return;
34
+ }
35
+ console.log(`Created tag: ${tag.name}`);
36
+ }
37
+ async function deleteTag(id) {
38
+ const stow = createStow();
39
+ await stow.tags.delete(id);
40
+ console.log(`Deleted tag: ${id}`);
41
+ }
42
+ export {
43
+ createTag,
44
+ deleteTag,
45
+ listTags
46
+ };
@@ -0,0 +1,92 @@
1
+ import {
2
+ formatBytes
3
+ } from "./chunk-ELSDWMEB.js";
4
+ import {
5
+ createStow
6
+ } from "./chunk-5LU25QZK.js";
7
+ import "./chunk-TOADDO2F.js";
8
+
9
+ // src/commands/upload.ts
10
+ import { existsSync, readFileSync } from "fs";
11
+ import { basename, resolve } from "path";
12
+ var CONTENT_TYPES = {
13
+ png: "image/png",
14
+ jpg: "image/jpeg",
15
+ jpeg: "image/jpeg",
16
+ gif: "image/gif",
17
+ webp: "image/webp",
18
+ svg: "image/svg+xml",
19
+ ico: "image/x-icon",
20
+ avif: "image/avif",
21
+ pdf: "application/pdf",
22
+ mp4: "video/mp4",
23
+ webm: "video/webm",
24
+ mov: "video/quicktime",
25
+ mp3: "audio/mpeg",
26
+ wav: "audio/wav",
27
+ ogg: "audio/ogg",
28
+ zip: "application/zip",
29
+ tar: "application/x-tar",
30
+ gz: "application/gzip",
31
+ txt: "text/plain",
32
+ json: "application/json",
33
+ xml: "application/xml",
34
+ html: "text/html",
35
+ css: "text/css",
36
+ js: "application/javascript"
37
+ };
38
+ function getContentType(filename) {
39
+ const ext = filename.toLowerCase().split(".").pop();
40
+ return CONTENT_TYPES[ext || ""] || "application/octet-stream";
41
+ }
42
+ function readFile(filePath) {
43
+ const resolvedPath = resolve(filePath);
44
+ if (!existsSync(resolvedPath)) {
45
+ console.error(`Error: File not found: ${filePath}`);
46
+ process.exit(1);
47
+ }
48
+ const buffer = readFileSync(resolvedPath);
49
+ const filename = basename(resolvedPath);
50
+ const contentType = getContentType(filename);
51
+ return { buffer, filename, contentType };
52
+ }
53
+ function printUploadResult(url, options, opts) {
54
+ if (options.quiet) {
55
+ console.log(url);
56
+ return;
57
+ }
58
+ console.error(opts?.deduped ? "Done! (deduped)" : "Done!");
59
+ console.log("");
60
+ console.log(url);
61
+ }
62
+ async function uploadDrop(filePath, options) {
63
+ const { buffer, filename, contentType } = readFile(filePath);
64
+ if (!options.quiet) {
65
+ console.error(`Uploading ${filename} (${formatBytes(buffer.length)})...`);
66
+ }
67
+ const stow = createStow();
68
+ const result = await stow.drop(buffer, {
69
+ filename,
70
+ contentType
71
+ });
72
+ printUploadResult(result.url, options);
73
+ }
74
+ async function uploadFile(filePath, options) {
75
+ const { buffer, filename, contentType } = readFile(filePath);
76
+ if (!options.quiet) {
77
+ console.error(`Uploading ${filename} (${formatBytes(buffer.length)})...`);
78
+ }
79
+ const stow = createStow();
80
+ const result = await stow.uploadFile(buffer, {
81
+ ...options.bucket ? { bucket: options.bucket } : {},
82
+ filename,
83
+ contentType
84
+ });
85
+ printUploadResult(result.url ?? result.key, options, {
86
+ deduped: result.deduped
87
+ });
88
+ }
89
+ export {
90
+ uploadDrop,
91
+ uploadFile
92
+ };
@@ -0,0 +1,28 @@
1
+ import {
2
+ formatBytes
3
+ } from "./chunk-ELSDWMEB.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": "1.0.2",
3
+ "version": "2.0.1",
4
4
  "type": "module",
5
5
  "description": "CLI for Stow file storage",
6
6
  "license": "MIT",