stow-cli 1.0.3 → 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.
Files changed (63) hide show
  1. package/dist/{app-JPUDM4LJ.js → app-2A2CFVBC.js} +1 -1
  2. package/dist/app-2H4TLSN7.js +239 -0
  3. package/dist/app-DTW2LNXW.js +249 -0
  4. package/dist/app-HYCPA7GA.js +239 -0
  5. package/dist/app-IZGSPZPX.js +239 -0
  6. package/dist/app-UGUM75MC.js +239 -0
  7. package/dist/app-XPOEAZJC.js +239 -0
  8. package/dist/app-YITP5APT.js +233 -0
  9. package/dist/{backfill-QZTVNJZM.js → backfill-G57M2BRA.js} +3 -3
  10. package/dist/{buckets-JQKZ3PH3.js → buckets-NXIVHPW5.js} +2 -2
  11. package/dist/chunk-2AORPTQB.js +23 -0
  12. package/dist/chunk-5LU25QZK.js +17 -0
  13. package/dist/chunk-FEMMZ4YZ.js +125 -0
  14. package/dist/chunk-LYCXXF2T.js +79 -0
  15. package/dist/chunk-MHRMBH4Y.js +36 -0
  16. package/dist/{chunk-WAQSCS57.js → chunk-QF7PVPWQ.js} +1 -1
  17. package/dist/chunk-R5CCBTXZ.js +79 -0
  18. package/dist/chunk-TOADDO2F.js +23 -0
  19. package/dist/chunk-YRHPOFJT.js +115 -0
  20. package/dist/chunk-ZDVARBCV.js +43 -0
  21. package/dist/cli.d.ts +1 -0
  22. package/dist/cli.js +43 -43
  23. package/dist/delete-AECEJX5W.js +18 -0
  24. package/dist/delete-GEX3O7YS.js +14 -0
  25. package/dist/delete-KYOZEODD.js +18 -0
  26. package/dist/delete-OLOAJRRO.js +18 -0
  27. package/dist/delete-V4EY4UBG.js +18 -0
  28. package/dist/{drops-QXGTYB5E.js → drops-RD55IDZ4.js} +2 -2
  29. package/dist/{files-OCYICIAM.js → files-E662TXUP.js} +3 -3
  30. package/dist/{health-YMZTZUFX.js → health-6LWM7KAT.js} +3 -3
  31. package/dist/{jobs-6JY4SVV5.js → jobs-CLXYKZ3B.js} +4 -4
  32. package/dist/{jobs-OKKGKSIH.js → jobs-K3LTNETU.js} +5 -5
  33. package/dist/list-7A3VZA2T.js +97 -0
  34. package/dist/list-DHXVIMRI.js +94 -0
  35. package/dist/list-DJEAKEZJ.js +106 -0
  36. package/dist/list-DQRU6QHO.js +106 -0
  37. package/dist/list-I5A6LTHX.js +106 -0
  38. package/dist/list-KEQPJY7I.js +109 -0
  39. package/dist/list-Z3MPT6MI.js +109 -0
  40. package/dist/{maintenance-EZUHQK5Q.js → maintenance-7LOAGG6J.js} +6 -6
  41. package/dist/open-2YNHG3MA.js +15 -0
  42. package/dist/open-F73Q2OHD.js +15 -0
  43. package/dist/{profiles-GWLBEEIT.js → profiles-C6SCFXS6.js} +2 -2
  44. package/dist/{queues-EQX7EJZF.js → queues-2GJAMMNF.js} +4 -4
  45. package/dist/{search-2PXM6XQ6.js → search-DV4VV62L.js} +2 -2
  46. package/dist/{tags-LSVEIIUF.js → tags-URHK2YH5.js} +2 -2
  47. package/dist/upload-3NS5O3UL.js +120 -0
  48. package/dist/upload-5RIDB2C5.js +92 -0
  49. package/dist/upload-B2PGW3AN.js +125 -0
  50. package/dist/{upload-ESYKBYHA.js → upload-DQDBDIDI.js} +1 -1
  51. package/dist/upload-FGNGNPC3.js +93 -0
  52. package/dist/upload-HKUPWTK2.js +173 -0
  53. package/dist/upload-JDVSJVWK.js +173 -0
  54. package/dist/upload-K4H7ZVRW.js +98 -0
  55. package/dist/upload-MI6VFGTC.js +92 -0
  56. package/dist/whoami-2SLCNVKP.js +27 -0
  57. package/dist/whoami-5IYRZKWS.js +28 -0
  58. package/dist/{whoami-4UYMSRVP.js → whoami-754O5IML.js} +1 -1
  59. package/dist/whoami-DOMX3Z5K.js +28 -0
  60. package/dist/whoami-IPMCUEUH.js +27 -0
  61. package/dist/whoami-JSQA2IDN.js +27 -0
  62. package/dist/whoami-RKH5HHPR.js +27 -0
  63. package/package.json +1 -1
@@ -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
+ };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  formatBytes
3
- } from "./chunk-ELSDWMEB.js";
3
+ } from "./chunk-ZDVARBCV.js";
4
4
  import {
5
5
  createStow
6
6
  } from "./chunk-JYOMHKFS.js";
@@ -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
+ };
@@ -0,0 +1,173 @@
1
+ import {
2
+ formatBytes
3
+ } from "./chunk-ZDVARBCV.js";
4
+ import {
5
+ apiRequest
6
+ } from "./chunk-LYCXXF2T.js";
7
+ import "./chunk-OZ7QQTIZ.js";
8
+
9
+ // src/commands/upload.ts
10
+ import { existsSync, readFileSync } from "fs";
11
+ import { createHash } from "crypto";
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 uploadToPresignedUrl(uploadUrl, contentType, buffer) {
55
+ const putRes = await fetch(uploadUrl, {
56
+ method: "PUT",
57
+ headers: { "Content-Type": contentType },
58
+ body: new Uint8Array(buffer)
59
+ });
60
+ if (!putRes.ok) {
61
+ throw new Error(`Upload to storage failed (${putRes.status})`);
62
+ }
63
+ }
64
+ async function runUploadPipeline(options) {
65
+ const presign = await apiRequest(options.presignPath, {
66
+ method: "POST",
67
+ body: JSON.stringify(options.presignBody)
68
+ });
69
+ const resolved = options.resolvePresign(presign);
70
+ if ("dedupedUrl" in resolved) {
71
+ return { url: resolved.dedupedUrl, deduped: true };
72
+ }
73
+ await uploadToPresignedUrl(
74
+ resolved.uploadUrl,
75
+ options.contentType,
76
+ options.buffer
77
+ );
78
+ const confirm = await apiRequest(resolved.confirmPath, {
79
+ method: "POST",
80
+ body: JSON.stringify(resolved.confirmBody)
81
+ });
82
+ return { url: options.getResultUrl(confirm), deduped: false };
83
+ }
84
+ function printUploadResult(url, options, opts) {
85
+ if (options.quiet) {
86
+ console.log(url);
87
+ return;
88
+ }
89
+ console.error(opts?.deduped ? "Done! (deduped)" : "Done!");
90
+ console.log("");
91
+ console.log(url);
92
+ }
93
+ function withBucket(path, bucket) {
94
+ if (!bucket) {
95
+ return path;
96
+ }
97
+ const joiner = path.includes("?") ? "&" : "?";
98
+ return `${path}${joiner}bucket=${encodeURIComponent(bucket)}`;
99
+ }
100
+ async function uploadDrop(filePath, options) {
101
+ const { buffer, filename, contentType } = readFile(filePath);
102
+ if (!options.quiet) {
103
+ console.error(`Uploading ${filename} (${formatBytes(buffer.length)})...`);
104
+ }
105
+ const result = await runUploadPipeline({
106
+ presignPath: "/api/drops/presign",
107
+ presignBody: {
108
+ filename,
109
+ contentType,
110
+ size: buffer.length
111
+ },
112
+ contentType,
113
+ buffer,
114
+ resolvePresign: (presign) => ({
115
+ uploadUrl: presign.uploadUrl,
116
+ confirmPath: presign.confirmUrl || "/api/drops/presign/confirm",
117
+ confirmBody: {
118
+ shortId: presign.shortId,
119
+ r2Key: presign.r2Key,
120
+ size: buffer.length,
121
+ contentType,
122
+ filename,
123
+ ...presign.uploadToken ? { uploadToken: presign.uploadToken } : {}
124
+ }
125
+ }),
126
+ getResultUrl: (confirm) => confirm.url
127
+ });
128
+ printUploadResult(result.url, options, { deduped: result.deduped });
129
+ }
130
+ async function uploadFile(filePath, options) {
131
+ const { buffer, filename, contentType } = readFile(filePath);
132
+ if (!options.quiet) {
133
+ console.error(`Uploading ${filename} (${formatBytes(buffer.length)})...`);
134
+ }
135
+ const contentHash = createHash("sha256").update(buffer).digest("hex");
136
+ const result = await runUploadPipeline({
137
+ presignPath: withBucket("/api/presign", options.bucket),
138
+ presignBody: {
139
+ filename,
140
+ contentType,
141
+ size: buffer.length,
142
+ contentHash
143
+ },
144
+ contentType,
145
+ buffer,
146
+ resolvePresign: (presign) => {
147
+ if ("dedupe" in presign && presign.dedupe) {
148
+ return { dedupedUrl: presign.url };
149
+ }
150
+ return {
151
+ uploadUrl: presign.uploadUrl,
152
+ confirmPath: withBucket(
153
+ presign.confirmUrl || "/api/presign/confirm",
154
+ options.bucket
155
+ ),
156
+ confirmBody: {
157
+ fileKey: presign.fileKey,
158
+ size: buffer.length,
159
+ contentType,
160
+ filename,
161
+ contentHash,
162
+ skipVerify: true
163
+ }
164
+ };
165
+ },
166
+ getResultUrl: (confirm) => confirm.url
167
+ });
168
+ printUploadResult(result.url, options, { deduped: result.deduped });
169
+ }
170
+ export {
171
+ uploadDrop,
172
+ uploadFile
173
+ };
@@ -0,0 +1,173 @@
1
+ import {
2
+ formatBytes
3
+ } from "./chunk-ZDVARBCV.js";
4
+ import {
5
+ apiRequest
6
+ } from "./chunk-R5CCBTXZ.js";
7
+ import "./chunk-2AORPTQB.js";
8
+
9
+ // src/commands/upload.ts
10
+ import { existsSync, readFileSync } from "fs";
11
+ import { createHash } from "crypto";
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 uploadToPresignedUrl(uploadUrl, contentType, buffer) {
55
+ const putRes = await fetch(uploadUrl, {
56
+ method: "PUT",
57
+ headers: { "Content-Type": contentType },
58
+ body: new Uint8Array(buffer)
59
+ });
60
+ if (!putRes.ok) {
61
+ throw new Error(`Upload to storage failed (${putRes.status})`);
62
+ }
63
+ }
64
+ async function runUploadPipeline(options) {
65
+ const presign = await apiRequest(options.presignPath, {
66
+ method: "POST",
67
+ body: JSON.stringify(options.presignBody)
68
+ });
69
+ const resolved = options.resolvePresign(presign);
70
+ if ("dedupedUrl" in resolved) {
71
+ return { url: resolved.dedupedUrl, deduped: true };
72
+ }
73
+ await uploadToPresignedUrl(
74
+ resolved.uploadUrl,
75
+ options.contentType,
76
+ options.buffer
77
+ );
78
+ const confirm = await apiRequest(resolved.confirmPath, {
79
+ method: "POST",
80
+ body: JSON.stringify(resolved.confirmBody)
81
+ });
82
+ return { url: options.getResultUrl(confirm), deduped: false };
83
+ }
84
+ function printUploadResult(url, options, opts) {
85
+ if (options.quiet) {
86
+ console.log(url);
87
+ return;
88
+ }
89
+ console.error(opts?.deduped ? "Done! (deduped)" : "Done!");
90
+ console.log("");
91
+ console.log(url);
92
+ }
93
+ function withBucket(path, bucket) {
94
+ if (!bucket) {
95
+ return path;
96
+ }
97
+ const joiner = path.includes("?") ? "&" : "?";
98
+ return `${path}${joiner}bucket=${encodeURIComponent(bucket)}`;
99
+ }
100
+ async function uploadDrop(filePath, options) {
101
+ const { buffer, filename, contentType } = readFile(filePath);
102
+ if (!options.quiet) {
103
+ console.error(`Uploading ${filename} (${formatBytes(buffer.length)})...`);
104
+ }
105
+ const result = await runUploadPipeline({
106
+ presignPath: "/api/drops/presign",
107
+ presignBody: {
108
+ filename,
109
+ contentType,
110
+ size: buffer.length
111
+ },
112
+ contentType,
113
+ buffer,
114
+ resolvePresign: (presign) => ({
115
+ uploadUrl: presign.uploadUrl,
116
+ confirmPath: presign.confirmUrl || "/api/drops/presign/confirm",
117
+ confirmBody: {
118
+ shortId: presign.shortId,
119
+ r2Key: presign.r2Key,
120
+ size: buffer.length,
121
+ contentType,
122
+ filename,
123
+ ...presign.uploadToken ? { uploadToken: presign.uploadToken } : {}
124
+ }
125
+ }),
126
+ getResultUrl: (confirm) => confirm.url
127
+ });
128
+ printUploadResult(result.url, options, { deduped: result.deduped });
129
+ }
130
+ async function uploadFile(filePath, options) {
131
+ const { buffer, filename, contentType } = readFile(filePath);
132
+ if (!options.quiet) {
133
+ console.error(`Uploading ${filename} (${formatBytes(buffer.length)})...`);
134
+ }
135
+ const contentHash = createHash("sha256").update(buffer).digest("hex");
136
+ const result = await runUploadPipeline({
137
+ presignPath: withBucket("/api/presign", options.bucket),
138
+ presignBody: {
139
+ filename,
140
+ contentType,
141
+ size: buffer.length,
142
+ contentHash
143
+ },
144
+ contentType,
145
+ buffer,
146
+ resolvePresign: (presign) => {
147
+ if ("dedupe" in presign && presign.dedupe) {
148
+ return { dedupedUrl: presign.url };
149
+ }
150
+ return {
151
+ uploadUrl: presign.uploadUrl,
152
+ confirmPath: withBucket(
153
+ presign.confirmUrl || "/api/presign/confirm",
154
+ options.bucket
155
+ ),
156
+ confirmBody: {
157
+ fileKey: presign.fileKey,
158
+ size: buffer.length,
159
+ contentType,
160
+ filename,
161
+ contentHash,
162
+ skipVerify: true
163
+ }
164
+ };
165
+ },
166
+ getResultUrl: (confirm) => confirm.url
167
+ });
168
+ printUploadResult(result.url, options, { deduped: result.deduped });
169
+ }
170
+ export {
171
+ uploadDrop,
172
+ uploadFile
173
+ };
@@ -0,0 +1,98 @@
1
+ import {
2
+ formatBytes
3
+ } from "./chunk-MHRMBH4Y.js";
4
+ import {
5
+ apiUpload
6
+ } from "./chunk-YRHPOFJT.js";
7
+ import "./chunk-2AORPTQB.js";
8
+
9
+ // src/commands/upload.ts
10
+ import { readFileSync, existsSync } 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(
59
+ "/api/drops/upload",
60
+ buffer,
61
+ filename,
62
+ contentType
63
+ );
64
+ if (options.quiet) {
65
+ console.log(result.url);
66
+ } else {
67
+ console.error("Done!");
68
+ console.log("");
69
+ console.log(result.url);
70
+ }
71
+ }
72
+ async function uploadFile(filePath, options) {
73
+ const { buffer, filename, contentType } = readFile(filePath);
74
+ if (!options.quiet) {
75
+ console.error(`Uploading ${filename} (${formatBytes(buffer.length)})...`);
76
+ }
77
+ let path = "/api/upload";
78
+ if (options.bucket) {
79
+ path += `?bucket=${encodeURIComponent(options.bucket)}`;
80
+ }
81
+ const result = await apiUpload(
82
+ path,
83
+ buffer,
84
+ filename,
85
+ contentType
86
+ );
87
+ if (options.quiet) {
88
+ console.log(result.url);
89
+ } else {
90
+ console.error("Done!");
91
+ console.log("");
92
+ console.log(result.url);
93
+ }
94
+ }
95
+ export {
96
+ uploadDrop,
97
+ uploadFile
98
+ };