stow-cli 1.0.2 → 1.0.3
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/dist/{app-2A2CFVBC.js → app-JPUDM4LJ.js} +1 -1
- package/dist/backfill-QZTVNJZM.js +61 -0
- package/dist/buckets-JQKZ3PH3.js +63 -0
- package/dist/{chunk-ZDVARBCV.js → chunk-ELSDWMEB.js} +8 -2
- package/dist/chunk-WAQSCS57.js +38 -0
- package/dist/cli.js +508 -15
- package/dist/drops-QXGTYB5E.js +39 -0
- package/dist/files-OCYICIAM.js +165 -0
- package/dist/health-YMZTZUFX.js +52 -0
- package/dist/jobs-6JY4SVV5.js +92 -0
- package/dist/jobs-OKKGKSIH.js +83 -0
- package/dist/maintenance-EZUHQK5Q.js +86 -0
- package/dist/profiles-GWLBEEIT.js +50 -0
- package/dist/queues-EQX7EJZF.js +51 -0
- package/dist/search-2PXM6XQ6.js +108 -0
- package/dist/tags-LSVEIIUF.js +46 -0
- package/dist/{upload-MI6VFGTC.js → upload-ESYKBYHA.js} +3 -3
- package/dist/{whoami-754O5IML.js → whoami-4UYMSRVP.js} +1 -1
- package/package.json +1 -1
- package/dist/app-2H4TLSN7.js +0 -239
- package/dist/app-HYCPA7GA.js +0 -239
- package/dist/app-IZGSPZPX.js +0 -239
- package/dist/app-UGUM75MC.js +0 -239
- package/dist/app-XPOEAZJC.js +0 -239
- package/dist/app-YITP5APT.js +0 -233
- package/dist/chunk-2AORPTQB.js +0 -23
- package/dist/chunk-FEMMZ4YZ.js +0 -125
- package/dist/chunk-LYCXXF2T.js +0 -79
- package/dist/chunk-MHRMBH4Y.js +0 -36
- package/dist/chunk-R5CCBTXZ.js +0 -79
- package/dist/chunk-YRHPOFJT.js +0 -115
- package/dist/cli.d.ts +0 -1
- package/dist/delete-AECEJX5W.js +0 -18
- package/dist/delete-KYOZEODD.js +0 -18
- package/dist/delete-OLOAJRRO.js +0 -18
- package/dist/delete-V4EY4UBG.js +0 -18
- package/dist/list-7A3VZA2T.js +0 -97
- package/dist/list-DHXVIMRI.js +0 -94
- package/dist/list-DJEAKEZJ.js +0 -106
- package/dist/list-DQRU6QHO.js +0 -106
- package/dist/list-I5A6LTHX.js +0 -106
- package/dist/list-KEQPJY7I.js +0 -109
- package/dist/list-Z3MPT6MI.js +0 -109
- package/dist/open-2YNHG3MA.js +0 -15
- package/dist/upload-3NS5O3UL.js +0 -120
- package/dist/upload-B2PGW3AN.js +0 -125
- package/dist/upload-DQDBDIDI.js +0 -92
- package/dist/upload-FGNGNPC3.js +0 -93
- package/dist/upload-HKUPWTK2.js +0 -173
- package/dist/upload-JDVSJVWK.js +0 -173
- package/dist/upload-K4H7ZVRW.js +0 -98
- package/dist/whoami-2SLCNVKP.js +0 -27
- package/dist/whoami-DOMX3Z5K.js +0 -28
- package/dist/whoami-IPMCUEUH.js +0 -27
- package/dist/whoami-JSQA2IDN.js +0 -27
- package/dist/whoami-RKH5HHPR.js +0 -27
package/dist/upload-DQDBDIDI.js
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
formatBytes
|
|
3
|
-
} from "./chunk-ZDVARBCV.js";
|
|
4
|
-
import {
|
|
5
|
-
createStow
|
|
6
|
-
} from "./chunk-JYOMHKFS.js";
|
|
7
|
-
import "./chunk-OZ7QQTIZ.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
|
-
};
|
package/dist/upload-FGNGNPC3.js
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
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
|
-
};
|
package/dist/upload-HKUPWTK2.js
DELETED
|
@@ -1,173 +0,0 @@
|
|
|
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
|
-
};
|
package/dist/upload-JDVSJVWK.js
DELETED
|
@@ -1,173 +0,0 @@
|
|
|
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
|
-
};
|
package/dist/upload-K4H7ZVRW.js
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
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
|
-
};
|
package/dist/whoami-2SLCNVKP.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
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/whoami.ts
|
|
10
|
-
async function whoami() {
|
|
11
|
-
const data = await apiRequest("/api/whoami");
|
|
12
|
-
console.log(`Account: ${data.user.email}`);
|
|
13
|
-
console.log("");
|
|
14
|
-
console.log(`Buckets: ${data.stats.bucketCount}`);
|
|
15
|
-
console.log(`Files: ${data.stats.totalFiles}`);
|
|
16
|
-
console.log(`Storage: ${formatBytes(data.stats.totalBytes)}`);
|
|
17
|
-
if (data.key) {
|
|
18
|
-
console.log("");
|
|
19
|
-
console.log(`API Key: ${data.key.name}`);
|
|
20
|
-
console.log(`Scope: ${data.key.scope}`);
|
|
21
|
-
const perms = Object.entries(data.key.permissions).filter(([, v]) => v).map(([k]) => k);
|
|
22
|
-
console.log(`Perms: ${perms.join(", ")}`);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
export {
|
|
26
|
-
whoami
|
|
27
|
-
};
|
package/dist/whoami-DOMX3Z5K.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createStow
|
|
3
|
-
} from "./chunk-JYOMHKFS.js";
|
|
4
|
-
import {
|
|
5
|
-
formatBytes
|
|
6
|
-
} from "./chunk-ZDVARBCV.js";
|
|
7
|
-
import "./chunk-OZ7QQTIZ.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
|
-
};
|