olbed-cli 0.0.1 → 0.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/index.mjs +24 -17
- package/package.json +1 -1
- package/src/index.ts +5 -11
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
1
2
|
import { readFileSync } from "node:fs";
|
|
2
3
|
import { basename } from "node:path";
|
|
3
4
|
import { defineCommand, runMain } from "citty";
|
|
@@ -12,13 +13,14 @@ runMain(defineCommand({
|
|
|
12
13
|
subCommands: { upload: defineCommand({
|
|
13
14
|
meta: {
|
|
14
15
|
name: "upload",
|
|
15
|
-
description: "Upload
|
|
16
|
+
description: "Upload image files to the service"
|
|
16
17
|
},
|
|
17
18
|
args: {
|
|
18
|
-
|
|
19
|
+
files: {
|
|
19
20
|
type: "positional",
|
|
20
|
-
description: "Path to the image file to upload",
|
|
21
|
-
required: true
|
|
21
|
+
description: "Path(s) to the image file(s) to upload",
|
|
22
|
+
required: true,
|
|
23
|
+
valueHint: "file..."
|
|
22
24
|
},
|
|
23
25
|
host: {
|
|
24
26
|
type: "string",
|
|
@@ -32,8 +34,8 @@ runMain(defineCommand({
|
|
|
32
34
|
},
|
|
33
35
|
prefix: {
|
|
34
36
|
type: "string",
|
|
35
|
-
description: "URL prefix for the uploaded image",
|
|
36
|
-
required:
|
|
37
|
+
description: "URL prefix for the uploaded image (defaults to host)",
|
|
38
|
+
required: false
|
|
37
39
|
},
|
|
38
40
|
keepName: {
|
|
39
41
|
type: "boolean",
|
|
@@ -42,14 +44,21 @@ runMain(defineCommand({
|
|
|
42
44
|
}
|
|
43
45
|
},
|
|
44
46
|
async run({ args }) {
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
+
const filePaths = args._;
|
|
48
|
+
if (filePaths.length === 0) {
|
|
49
|
+
console.error("✗ No files specified");
|
|
50
|
+
process.exit(1);
|
|
51
|
+
}
|
|
52
|
+
const prefix = args.prefix || args.host;
|
|
53
|
+
const uploadUrl = `${args.host}/api/upload`;
|
|
54
|
+
console.log(`Uploading ${filePaths.length} file(s)...\n`);
|
|
55
|
+
let failCount = 0;
|
|
56
|
+
for (const filePath of filePaths) try {
|
|
47
57
|
const fileBuffer = readFileSync(filePath);
|
|
48
58
|
const filename = basename(filePath);
|
|
49
59
|
const form = new FormData();
|
|
50
60
|
form.append("image", new Blob([fileBuffer]), filename);
|
|
51
61
|
form.append("keep_name", args.keepName.toString());
|
|
52
|
-
const uploadUrl = `${args.host}/api/upload`;
|
|
53
62
|
const response = await fetch(uploadUrl, {
|
|
54
63
|
method: "POST",
|
|
55
64
|
headers: { Authorization: args.key },
|
|
@@ -57,17 +66,15 @@ runMain(defineCommand({
|
|
|
57
66
|
});
|
|
58
67
|
if (!response.ok) {
|
|
59
68
|
const errorText = await response.text();
|
|
60
|
-
throw new Error(
|
|
69
|
+
throw new Error(`${response.status} ${errorText}`);
|
|
61
70
|
}
|
|
62
|
-
|
|
63
|
-
console.log("✓ Upload successful!");
|
|
64
|
-
console.log(`Image URL: ${args.prefix}/${filename}`);
|
|
65
|
-
console.log(`Response: ${result}`);
|
|
71
|
+
console.log(`${prefix}${await response.text()}`);
|
|
66
72
|
} catch (error) {
|
|
67
|
-
console.error(
|
|
68
|
-
console.error(error instanceof Error ? error.message : String(error));
|
|
69
|
-
|
|
73
|
+
console.error(`✗ ${basename(filePath)}`);
|
|
74
|
+
console.error(` Error: ${error instanceof Error ? error.message : String(error)}`);
|
|
75
|
+
failCount++;
|
|
70
76
|
}
|
|
77
|
+
if (failCount > 0) process.exit(1);
|
|
71
78
|
}
|
|
72
79
|
}) }
|
|
73
80
|
}));
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
1
3
|
import { readFileSync } from "node:fs";
|
|
2
4
|
import { basename } from "node:path";
|
|
3
5
|
import { defineCommand, runMain } from "citty";
|
|
@@ -35,17 +37,9 @@ const uploadCommand = defineCommand({
|
|
|
35
37
|
default: false,
|
|
36
38
|
},
|
|
37
39
|
},
|
|
38
|
-
async run({ args
|
|
39
|
-
//
|
|
40
|
-
const filePaths: string[] =
|
|
41
|
-
for (const arg of rawArgs) {
|
|
42
|
-
if (arg.startsWith("--") || arg.startsWith("-")) {
|
|
43
|
-
break;
|
|
44
|
-
}
|
|
45
|
-
if (arg !== "upload") {
|
|
46
|
-
filePaths.push(arg);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
40
|
+
async run({ args }) {
|
|
41
|
+
// Parse file paths - collect all non-flag arguments after 'upload'
|
|
42
|
+
const filePaths: string[] = args._;
|
|
49
43
|
|
|
50
44
|
if (filePaths.length === 0) {
|
|
51
45
|
console.error("✗ No files specified");
|