olbed-cli 0.0.1 → 0.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.
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 an image file to the service"
16
+ description: "Upload image files to the service"
16
17
  },
17
18
  args: {
18
- file: {
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: true
37
+ description: "URL prefix for the uploaded image (defaults to host)",
38
+ required: false
37
39
  },
38
40
  keepName: {
39
41
  type: "boolean",
@@ -41,15 +43,26 @@ runMain(defineCommand({
41
43
  default: false
42
44
  }
43
45
  },
44
- async run({ args }) {
45
- const filePath = args.file;
46
- try {
46
+ async run({ args, rawArgs }) {
47
+ const filePaths = [];
48
+ for (const arg of rawArgs) {
49
+ if (arg.startsWith("--") || arg.startsWith("-")) break;
50
+ if (arg !== "upload") filePaths.push(arg);
51
+ }
52
+ if (filePaths.length === 0) {
53
+ console.error("✗ No files specified");
54
+ process.exit(1);
55
+ }
56
+ const prefix = args.prefix || args.host;
57
+ const uploadUrl = `${args.host}/api/upload`;
58
+ console.log(`Uploading ${filePaths.length} file(s)...\n`);
59
+ let failCount = 0;
60
+ for (const filePath of filePaths) try {
47
61
  const fileBuffer = readFileSync(filePath);
48
62
  const filename = basename(filePath);
49
63
  const form = new FormData();
50
64
  form.append("image", new Blob([fileBuffer]), filename);
51
65
  form.append("keep_name", args.keepName.toString());
52
- const uploadUrl = `${args.host}/api/upload`;
53
66
  const response = await fetch(uploadUrl, {
54
67
  method: "POST",
55
68
  headers: { Authorization: args.key },
@@ -57,17 +70,15 @@ runMain(defineCommand({
57
70
  });
58
71
  if (!response.ok) {
59
72
  const errorText = await response.text();
60
- throw new Error(`Upload failed: ${response.status} ${errorText}`);
73
+ throw new Error(`${response.status} ${errorText}`);
61
74
  }
62
- const result = await response.text();
63
- console.log("✓ Upload successful!");
64
- console.log(`Image URL: ${args.prefix}/${filename}`);
65
- console.log(`Response: ${result}`);
75
+ console.log(`${prefix}${await response.text()}`);
66
76
  } catch (error) {
67
- console.error("✗ Upload failed:");
68
- console.error(error instanceof Error ? error.message : String(error));
69
- process.exit(1);
77
+ console.error(`✗ ${basename(filePath)}`);
78
+ console.error(` Error: ${error instanceof Error ? error.message : String(error)}`);
79
+ failCount++;
70
80
  }
81
+ if (failCount > 0) process.exit(1);
71
82
  }
72
83
  }) }
73
84
  }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "olbed-cli",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "CLI tool for OpenList EdgeOne image hosting service",
5
5
  "bin": {
6
6
  "olbed-cli": "./dist/index.mjs"
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";