stow-cli 1.0.0 → 1.0.2

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,106 @@
1
+ import {
2
+ formatBytes,
3
+ formatTable,
4
+ usageBar
5
+ } from "./chunk-ZDVARBCV.js";
6
+ import {
7
+ apiRequest
8
+ } from "./chunk-R5CCBTXZ.js";
9
+ import "./chunk-2AORPTQB.js";
10
+
11
+ // src/commands/list.ts
12
+ async function listBuckets() {
13
+ const data = await apiRequest("/api/buckets");
14
+ if (data.buckets.length === 0) {
15
+ console.log("No buckets yet. Create one with: stow buckets create <name>");
16
+ return;
17
+ }
18
+ const rows = data.buckets.map((b) => [
19
+ b.name,
20
+ b.isPublic ? "public" : "private",
21
+ `${b.fileCount} files`,
22
+ formatBytes(b.usageBytes),
23
+ b.description || ""
24
+ ]);
25
+ console.log(
26
+ formatTable(["Name", "Access", "Files", "Size", "Description"], rows)
27
+ );
28
+ }
29
+ async function createBucket(name, options) {
30
+ const body = { name };
31
+ if (options.description) {
32
+ body.description = options.description;
33
+ }
34
+ if (options.public) {
35
+ body.isPublic = true;
36
+ }
37
+ const data = await apiRequest("/api/buckets", {
38
+ method: "POST",
39
+ body: JSON.stringify(body)
40
+ });
41
+ console.log(`Created bucket: ${data.bucket.name}`);
42
+ }
43
+ async function renameBucket(name, newName, options) {
44
+ if (!options.yes) {
45
+ console.error(
46
+ "Warning: Renaming a bucket will break any existing URLs using the old name."
47
+ );
48
+ console.error("Use --yes to skip this warning.");
49
+ }
50
+ const data = await apiRequest(
51
+ `/api/buckets/_?bucket=${encodeURIComponent(name)}`,
52
+ {
53
+ method: "PATCH",
54
+ body: JSON.stringify({ name: newName })
55
+ }
56
+ );
57
+ console.log(`Renamed bucket: ${name} \u2192 ${data.bucket.name}`);
58
+ }
59
+ async function listFiles(bucket, options) {
60
+ const params = new URLSearchParams({ bucket });
61
+ if (options.search) {
62
+ params.set("prefix", options.search);
63
+ }
64
+ if (options.limit) {
65
+ params.set("limit", options.limit);
66
+ }
67
+ const data = await apiRequest(`/api/files?${params}`);
68
+ if (data.files.length === 0) {
69
+ console.log(`No files in bucket '${bucket}'.`);
70
+ return;
71
+ }
72
+ const rows = data.files.map((f) => [
73
+ f.key,
74
+ formatBytes(f.size),
75
+ f.lastModified.split("T")[0]
76
+ ]);
77
+ console.log(formatTable(["Key", "Size", "Modified"], rows));
78
+ if (data.nextCursor) {
79
+ console.log("\n(more files available \u2014 use --limit to see more)");
80
+ }
81
+ }
82
+ async function listDrops() {
83
+ const data = await apiRequest("/api/drops");
84
+ if (data.drops.length === 0) {
85
+ console.log("No drops yet. Create one with: stow drop <file>");
86
+ return;
87
+ }
88
+ const rows = data.drops.map((d) => [
89
+ d.filename,
90
+ formatBytes(Number(d.size)),
91
+ d.contentType,
92
+ d.url
93
+ ]);
94
+ console.log(formatTable(["Filename", "Size", "Type", "URL"], rows));
95
+ console.log(
96
+ `
97
+ Storage: ${usageBar(data.usage.bytes, data.usage.limit)} ${formatBytes(data.usage.bytes)} / ${formatBytes(data.usage.limit)}`
98
+ );
99
+ }
100
+ export {
101
+ createBucket,
102
+ listBuckets,
103
+ listDrops,
104
+ listFiles,
105
+ renameBucket
106
+ };
@@ -0,0 +1,106 @@
1
+ import {
2
+ formatBytes,
3
+ formatTable,
4
+ usageBar
5
+ } from "./chunk-ZDVARBCV.js";
6
+ import {
7
+ apiRequest
8
+ } from "./chunk-LYCXXF2T.js";
9
+ import "./chunk-OZ7QQTIZ.js";
10
+
11
+ // src/commands/list.ts
12
+ async function listBuckets() {
13
+ const data = await apiRequest("/api/buckets");
14
+ if (data.buckets.length === 0) {
15
+ console.log("No buckets yet. Create one with: stow buckets create <name>");
16
+ return;
17
+ }
18
+ const rows = data.buckets.map((b) => [
19
+ b.name,
20
+ b.isPublic ? "public" : "private",
21
+ `${b.fileCount} files`,
22
+ formatBytes(b.usageBytes),
23
+ b.description || ""
24
+ ]);
25
+ console.log(
26
+ formatTable(["Name", "Access", "Files", "Size", "Description"], rows)
27
+ );
28
+ }
29
+ async function createBucket(name, options) {
30
+ const body = { name };
31
+ if (options.description) {
32
+ body.description = options.description;
33
+ }
34
+ if (options.public) {
35
+ body.isPublic = true;
36
+ }
37
+ const data = await apiRequest("/api/buckets", {
38
+ method: "POST",
39
+ body: JSON.stringify(body)
40
+ });
41
+ console.log(`Created bucket: ${data.bucket.name}`);
42
+ }
43
+ async function renameBucket(name, newName, options) {
44
+ if (!options.yes) {
45
+ console.error(
46
+ "Warning: Renaming a bucket will break any existing URLs using the old name."
47
+ );
48
+ console.error("Use --yes to skip this warning.");
49
+ }
50
+ const data = await apiRequest(
51
+ `/api/buckets/_?bucket=${encodeURIComponent(name)}`,
52
+ {
53
+ method: "PATCH",
54
+ body: JSON.stringify({ name: newName })
55
+ }
56
+ );
57
+ console.log(`Renamed bucket: ${name} \u2192 ${data.bucket.name}`);
58
+ }
59
+ async function listFiles(bucket, options) {
60
+ const params = new URLSearchParams({ bucket });
61
+ if (options.search) {
62
+ params.set("prefix", options.search);
63
+ }
64
+ if (options.limit) {
65
+ params.set("limit", options.limit);
66
+ }
67
+ const data = await apiRequest(`/api/files?${params}`);
68
+ if (data.files.length === 0) {
69
+ console.log(`No files in bucket '${bucket}'.`);
70
+ return;
71
+ }
72
+ const rows = data.files.map((f) => [
73
+ f.key,
74
+ formatBytes(f.size),
75
+ f.lastModified.split("T")[0]
76
+ ]);
77
+ console.log(formatTable(["Key", "Size", "Modified"], rows));
78
+ if (data.nextCursor) {
79
+ console.log("\n(more files available \u2014 use --limit to see more)");
80
+ }
81
+ }
82
+ async function listDrops() {
83
+ const data = await apiRequest("/api/drops");
84
+ if (data.drops.length === 0) {
85
+ console.log("No drops yet. Create one with: stow drop <file>");
86
+ return;
87
+ }
88
+ const rows = data.drops.map((d) => [
89
+ d.filename,
90
+ formatBytes(Number(d.size)),
91
+ d.contentType,
92
+ d.url
93
+ ]);
94
+ console.log(formatTable(["Filename", "Size", "Type", "URL"], rows));
95
+ console.log(
96
+ `
97
+ Storage: ${usageBar(data.usage.bytes, data.usage.limit)} ${formatBytes(data.usage.bytes)} / ${formatBytes(data.usage.limit)}`
98
+ );
99
+ }
100
+ export {
101
+ createBucket,
102
+ listBuckets,
103
+ listDrops,
104
+ listFiles,
105
+ renameBucket
106
+ };
@@ -0,0 +1,109 @@
1
+ import {
2
+ createStow
3
+ } from "./chunk-JYOMHKFS.js";
4
+ import {
5
+ formatBytes,
6
+ formatTable,
7
+ usageBar
8
+ } from "./chunk-ZDVARBCV.js";
9
+ import "./chunk-OZ7QQTIZ.js";
10
+
11
+ // src/commands/list.ts
12
+ async function listBuckets() {
13
+ const stow = createStow();
14
+ const data = await stow.listBuckets();
15
+ if (data.buckets.length === 0) {
16
+ console.log("No buckets yet. Create one with: stow buckets create <name>");
17
+ return;
18
+ }
19
+ const rows = data.buckets.map((b) => [
20
+ b.name,
21
+ b.isPublic ? "public" : "private",
22
+ `${b.fileCount ?? 0} files`,
23
+ formatBytes(b.usageBytes ?? 0),
24
+ b.description || ""
25
+ ]);
26
+ console.log(
27
+ formatTable(["Name", "Access", "Files", "Size", "Description"], rows)
28
+ );
29
+ }
30
+ async function createBucket(name, options) {
31
+ const stow = createStow();
32
+ const bucket = await stow.createBucket({
33
+ name,
34
+ ...options.description ? { description: options.description } : {},
35
+ ...options.public ? { isPublic: true } : {}
36
+ });
37
+ console.log(`Created bucket: ${bucket.name}`);
38
+ }
39
+ async function renameBucket(name, newName, options) {
40
+ if (!options.yes) {
41
+ console.error(
42
+ "Warning: Renaming a bucket will break any existing URLs using the old name."
43
+ );
44
+ console.error("Use --yes to skip this warning.");
45
+ }
46
+ const stow = createStow();
47
+ const bucket = await stow.renameBucket(name, newName);
48
+ console.log(`Renamed bucket: ${name} \u2192 ${bucket.name}`);
49
+ }
50
+ async function listFiles(bucket, options) {
51
+ const stow = createStow();
52
+ const parsedLimit = options.limit ? Number.parseInt(options.limit, 10) : null;
53
+ const data = await stow.listFiles({
54
+ bucket,
55
+ ...options.search ? { prefix: options.search } : {},
56
+ ...parsedLimit && Number.isFinite(parsedLimit) && parsedLimit > 0 ? { limit: parsedLimit } : {}
57
+ });
58
+ if (data.files.length === 0) {
59
+ console.log(`No files in bucket '${bucket}'.`);
60
+ return;
61
+ }
62
+ const rows = data.files.map((f) => [
63
+ f.key,
64
+ formatBytes(f.size),
65
+ f.lastModified.split("T")[0]
66
+ ]);
67
+ console.log(formatTable(["Key", "Size", "Modified"], rows));
68
+ if (data.nextCursor) {
69
+ console.log("\n(more files available \u2014 use --limit to see more)");
70
+ }
71
+ }
72
+ async function listDrops() {
73
+ const stow = createStow();
74
+ const data = await stow.listDrops();
75
+ if (data.drops.length === 0) {
76
+ console.log("No drops yet. Create one with: stow drop <file>");
77
+ return;
78
+ }
79
+ const rows = data.drops.map((d) => [
80
+ d.filename,
81
+ formatBytes(Number(d.size)),
82
+ d.contentType,
83
+ d.url
84
+ ]);
85
+ console.log(formatTable(["Filename", "Size", "Type", "URL"], rows));
86
+ console.log(
87
+ `
88
+ Storage: ${usageBar(data.usage.bytes, data.usage.limit)} ${formatBytes(data.usage.bytes)} / ${formatBytes(data.usage.limit)}`
89
+ );
90
+ }
91
+ async function deleteBucket(id) {
92
+ const stow = createStow();
93
+ await stow.deleteBucket(id);
94
+ console.log(`Deleted bucket: ${id}`);
95
+ }
96
+ async function deleteDrop(id) {
97
+ const stow = createStow();
98
+ await stow.deleteDrop(id);
99
+ console.log(`Deleted drop: ${id}`);
100
+ }
101
+ export {
102
+ createBucket,
103
+ deleteBucket,
104
+ deleteDrop,
105
+ listBuckets,
106
+ listDrops,
107
+ listFiles,
108
+ renameBucket
109
+ };
@@ -0,0 +1,15 @@
1
+ import {
2
+ getBaseUrl
3
+ } from "./chunk-2AORPTQB.js";
4
+
5
+ // src/commands/open.ts
6
+ async function openBucket(bucket) {
7
+ const baseUrl = getBaseUrl();
8
+ const url = `${baseUrl}/dashboard/buckets/${encodeURIComponent(bucket)}`;
9
+ const { default: open } = await import("open");
10
+ await open(url);
11
+ console.log(`Opened: ${url}`);
12
+ }
13
+ export {
14
+ openBucket
15
+ };
@@ -0,0 +1,120 @@
1
+ import {
2
+ formatBytes
3
+ } from "./chunk-ZDVARBCV.js";
4
+ import {
5
+ apiRequest,
6
+ apiUpload
7
+ } from "./chunk-FEMMZ4YZ.js";
8
+ import "./chunk-2AORPTQB.js";
9
+
10
+ // src/commands/upload.ts
11
+ import { existsSync, readFileSync } from "fs";
12
+ import { basename, resolve } from "path";
13
+ var CONTENT_TYPES = {
14
+ png: "image/png",
15
+ jpg: "image/jpeg",
16
+ jpeg: "image/jpeg",
17
+ gif: "image/gif",
18
+ webp: "image/webp",
19
+ svg: "image/svg+xml",
20
+ ico: "image/x-icon",
21
+ avif: "image/avif",
22
+ pdf: "application/pdf",
23
+ mp4: "video/mp4",
24
+ webm: "video/webm",
25
+ mov: "video/quicktime",
26
+ mp3: "audio/mpeg",
27
+ wav: "audio/wav",
28
+ ogg: "audio/ogg",
29
+ zip: "application/zip",
30
+ tar: "application/x-tar",
31
+ gz: "application/gzip",
32
+ txt: "text/plain",
33
+ json: "application/json",
34
+ xml: "application/xml",
35
+ html: "text/html",
36
+ css: "text/css",
37
+ js: "application/javascript"
38
+ };
39
+ function getContentType(filename) {
40
+ const ext = filename.toLowerCase().split(".").pop();
41
+ return CONTENT_TYPES[ext || ""] || "application/octet-stream";
42
+ }
43
+ function readFile(filePath) {
44
+ const resolvedPath = resolve(filePath);
45
+ if (!existsSync(resolvedPath)) {
46
+ console.error(`Error: File not found: ${filePath}`);
47
+ process.exit(1);
48
+ }
49
+ const buffer = readFileSync(resolvedPath);
50
+ const filename = basename(resolvedPath);
51
+ const contentType = getContentType(filename);
52
+ return { buffer, filename, contentType };
53
+ }
54
+ async function uploadDrop(filePath, options) {
55
+ const { buffer, filename, contentType } = readFile(filePath);
56
+ if (!options.quiet) {
57
+ console.error(`Uploading ${filename} (${formatBytes(buffer.length)})...`);
58
+ }
59
+ const presign = await apiRequest("/api/drops/presign", {
60
+ method: "POST",
61
+ body: JSON.stringify({
62
+ filename,
63
+ contentType,
64
+ size: buffer.length
65
+ })
66
+ });
67
+ const putRes = await fetch(presign.uploadUrl, {
68
+ method: "PUT",
69
+ headers: { "Content-Type": contentType },
70
+ body: new Uint8Array(buffer)
71
+ });
72
+ if (!putRes.ok) {
73
+ throw new Error(`Upload to storage failed (${putRes.status})`);
74
+ }
75
+ const result = await apiRequest("/api/drops/presign/confirm", {
76
+ method: "POST",
77
+ body: JSON.stringify({
78
+ shortId: presign.shortId,
79
+ r2Key: presign.r2Key,
80
+ size: buffer.length,
81
+ contentType,
82
+ filename,
83
+ ...presign.uploadToken ? { uploadToken: presign.uploadToken } : {}
84
+ })
85
+ });
86
+ if (options.quiet) {
87
+ console.log(result.url);
88
+ } else {
89
+ console.error("Done!");
90
+ console.log("");
91
+ console.log(result.url);
92
+ }
93
+ }
94
+ async function uploadFile(filePath, options) {
95
+ const { buffer, filename, contentType } = readFile(filePath);
96
+ if (!options.quiet) {
97
+ console.error(`Uploading ${filename} (${formatBytes(buffer.length)})...`);
98
+ }
99
+ let path = "/api/upload";
100
+ if (options.bucket) {
101
+ path += `?bucket=${encodeURIComponent(options.bucket)}`;
102
+ }
103
+ const result = await apiUpload(
104
+ path,
105
+ buffer,
106
+ filename,
107
+ contentType
108
+ );
109
+ if (options.quiet) {
110
+ console.log(result.url);
111
+ } else {
112
+ console.error("Done!");
113
+ console.log("");
114
+ console.log(result.url);
115
+ }
116
+ }
117
+ export {
118
+ uploadDrop,
119
+ uploadFile
120
+ };
@@ -0,0 +1,125 @@
1
+ import {
2
+ formatBytes
3
+ } from "./chunk-ZDVARBCV.js";
4
+ import {
5
+ apiRequest,
6
+ apiUpload
7
+ } from "./chunk-FEMMZ4YZ.js";
8
+ import "./chunk-2AORPTQB.js";
9
+
10
+ // src/commands/upload.ts
11
+ import { createHash } from "crypto";
12
+ import { existsSync, readFileSync } from "fs";
13
+ import { basename, resolve } from "path";
14
+ var CONTENT_TYPES = {
15
+ png: "image/png",
16
+ jpg: "image/jpeg",
17
+ jpeg: "image/jpeg",
18
+ gif: "image/gif",
19
+ webp: "image/webp",
20
+ svg: "image/svg+xml",
21
+ ico: "image/x-icon",
22
+ avif: "image/avif",
23
+ pdf: "application/pdf",
24
+ mp4: "video/mp4",
25
+ webm: "video/webm",
26
+ mov: "video/quicktime",
27
+ mp3: "audio/mpeg",
28
+ wav: "audio/wav",
29
+ ogg: "audio/ogg",
30
+ zip: "application/zip",
31
+ tar: "application/x-tar",
32
+ gz: "application/gzip",
33
+ txt: "text/plain",
34
+ json: "application/json",
35
+ xml: "application/xml",
36
+ html: "text/html",
37
+ css: "text/css",
38
+ js: "application/javascript"
39
+ };
40
+ function getContentType(filename) {
41
+ const ext = filename.toLowerCase().split(".").pop();
42
+ return CONTENT_TYPES[ext || ""] || "application/octet-stream";
43
+ }
44
+ function readFile(filePath) {
45
+ const resolvedPath = resolve(filePath);
46
+ if (!existsSync(resolvedPath)) {
47
+ console.error(`Error: File not found: ${filePath}`);
48
+ process.exit(1);
49
+ }
50
+ const buffer = readFileSync(resolvedPath);
51
+ const filename = basename(resolvedPath);
52
+ const contentType = getContentType(filename);
53
+ return { buffer, filename, contentType };
54
+ }
55
+ async function uploadDrop(filePath, options) {
56
+ const { buffer, filename, contentType } = readFile(filePath);
57
+ if (!options.quiet) {
58
+ console.error(`Uploading ${filename} (${formatBytes(buffer.length)})...`);
59
+ }
60
+ const contentHash = createHash("sha256").update(buffer).digest("hex");
61
+ const presign = await apiRequest("/api/drops/presign", {
62
+ method: "POST",
63
+ body: JSON.stringify({
64
+ filename,
65
+ contentType,
66
+ contentHash,
67
+ size: buffer.length
68
+ })
69
+ });
70
+ if (!presign.isDuplicate && presign.uploadUrl) {
71
+ const putRes = await fetch(presign.uploadUrl, {
72
+ method: "PUT",
73
+ headers: { "Content-Type": contentType },
74
+ body: new Uint8Array(buffer)
75
+ });
76
+ if (!putRes.ok) {
77
+ throw new Error(`Upload to storage failed (${putRes.status})`);
78
+ }
79
+ }
80
+ const result = await apiRequest("/api/drops/presign/confirm", {
81
+ method: "POST",
82
+ body: JSON.stringify({
83
+ shortId: presign.shortId,
84
+ contentHash,
85
+ size: buffer.length,
86
+ contentType,
87
+ filename,
88
+ contentBlobId: presign.contentBlobId
89
+ })
90
+ });
91
+ if (options.quiet) {
92
+ console.log(result.url);
93
+ } else {
94
+ console.error("Done!");
95
+ console.log("");
96
+ console.log(result.url);
97
+ }
98
+ }
99
+ async function uploadFile(filePath, options) {
100
+ const { buffer, filename, contentType } = readFile(filePath);
101
+ if (!options.quiet) {
102
+ console.error(`Uploading ${filename} (${formatBytes(buffer.length)})...`);
103
+ }
104
+ let path = "/api/upload";
105
+ if (options.bucket) {
106
+ path += `?bucket=${encodeURIComponent(options.bucket)}`;
107
+ }
108
+ const result = await apiUpload(
109
+ path,
110
+ buffer,
111
+ filename,
112
+ contentType
113
+ );
114
+ if (options.quiet) {
115
+ console.log(result.url);
116
+ } else {
117
+ console.error("Done!");
118
+ console.log("");
119
+ console.log(result.url);
120
+ }
121
+ }
122
+ export {
123
+ uploadDrop,
124
+ uploadFile
125
+ };
@@ -0,0 +1,93 @@
1
+ import {
2
+ formatBytes
3
+ } from "./chunk-ZDVARBCV.js";
4
+ import {
5
+ apiUpload
6
+ } from "./chunk-FEMMZ4YZ.js";
7
+ import "./chunk-2AORPTQB.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
+ async function uploadDrop(filePath, options) {
54
+ const { buffer, filename, contentType } = readFile(filePath);
55
+ if (!options.quiet) {
56
+ console.error(`Uploading ${filename} (${formatBytes(buffer.length)})...`);
57
+ }
58
+ const result = await apiUpload("/api/drops/upload", buffer, filename, contentType);
59
+ if (options.quiet) {
60
+ console.log(result.url);
61
+ } else {
62
+ console.error("Done!");
63
+ console.log("");
64
+ console.log(result.url);
65
+ }
66
+ }
67
+ async function uploadFile(filePath, options) {
68
+ const { buffer, filename, contentType } = readFile(filePath);
69
+ if (!options.quiet) {
70
+ console.error(`Uploading ${filename} (${formatBytes(buffer.length)})...`);
71
+ }
72
+ let path = "/api/upload";
73
+ if (options.bucket) {
74
+ path += `?bucket=${encodeURIComponent(options.bucket)}`;
75
+ }
76
+ const result = await apiUpload(
77
+ path,
78
+ buffer,
79
+ filename,
80
+ contentType
81
+ );
82
+ if (options.quiet) {
83
+ console.log(result.url);
84
+ } else {
85
+ console.error("Done!");
86
+ console.log("");
87
+ console.log(result.url);
88
+ }
89
+ }
90
+ export {
91
+ uploadDrop,
92
+ uploadFile
93
+ };