@doufunao123/asset-gateway 0.1.0 → 0.2.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.
- package/dist/index.js +70 -5
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// src/index.ts
|
|
4
|
-
import { Command as
|
|
4
|
+
import { Command as Command7 } from "commander";
|
|
5
5
|
|
|
6
6
|
// src/commands/auth.ts
|
|
7
7
|
import { existsSync as existsSync2, unlinkSync } from "fs";
|
|
@@ -70,7 +70,7 @@ function normalizeError(error2) {
|
|
|
70
70
|
|
|
71
71
|
// src/meta.ts
|
|
72
72
|
var CLI_NAME = "asset-gateway";
|
|
73
|
-
var CLI_VERSION = "0.
|
|
73
|
+
var CLI_VERSION = "0.2.0";
|
|
74
74
|
var CLI_DESCRIPTION = "Universal asset generation gateway CLI";
|
|
75
75
|
var DEFAULT_GATEWAY_URL = "https://assets.xiaomao.chat";
|
|
76
76
|
|
|
@@ -167,6 +167,8 @@ ${formatHuman(val, indent + 2)}`;
|
|
|
167
167
|
}
|
|
168
168
|
|
|
169
169
|
// src/client.ts
|
|
170
|
+
import { readFile } from "fs/promises";
|
|
171
|
+
import { basename } from "path";
|
|
170
172
|
var GatewayClient = class {
|
|
171
173
|
constructor(baseUrl, token) {
|
|
172
174
|
this.baseUrl = baseUrl;
|
|
@@ -181,6 +183,26 @@ var GatewayClient = class {
|
|
|
181
183
|
async put(path, body) {
|
|
182
184
|
return this.request("PUT", path, { body });
|
|
183
185
|
}
|
|
186
|
+
async delete(path) {
|
|
187
|
+
return this.request("DELETE", path);
|
|
188
|
+
}
|
|
189
|
+
async uploadFile(filePath) {
|
|
190
|
+
let content;
|
|
191
|
+
try {
|
|
192
|
+
content = await readFile(filePath);
|
|
193
|
+
} catch (error2) {
|
|
194
|
+
throw configError(
|
|
195
|
+
`Failed to read file ${filePath}: ${error2 instanceof Error ? error2.message : String(error2)}`
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
const form = new FormData();
|
|
199
|
+
const arrayBuffer = content.buffer.slice(
|
|
200
|
+
content.byteOffset,
|
|
201
|
+
content.byteOffset + content.byteLength
|
|
202
|
+
);
|
|
203
|
+
form.append("file", new Blob([arrayBuffer]), basename(filePath));
|
|
204
|
+
return this.request("POST", "/api/assets/upload", { form });
|
|
205
|
+
}
|
|
184
206
|
async request(method, path, options = {}) {
|
|
185
207
|
const url = new URL(path, ensureTrailingSlash(this.baseUrl));
|
|
186
208
|
const headers = new Headers(options.headers);
|
|
@@ -188,7 +210,9 @@ var GatewayClient = class {
|
|
|
188
210
|
headers.set("authorization", `Bearer ${this.token}`);
|
|
189
211
|
}
|
|
190
212
|
let body;
|
|
191
|
-
if (options.
|
|
213
|
+
if (options.form) {
|
|
214
|
+
body = options.form;
|
|
215
|
+
} else if (options.body !== void 0) {
|
|
192
216
|
headers.set("content-type", "application/json");
|
|
193
217
|
body = JSON.stringify(options.body);
|
|
194
218
|
}
|
|
@@ -567,7 +591,7 @@ function createGenerateCommand() {
|
|
|
567
591
|
const body = {
|
|
568
592
|
asset_type: "model3d"
|
|
569
593
|
};
|
|
570
|
-
if (options.image) body.
|
|
594
|
+
if (options.image) body.input_file = options.image;
|
|
571
595
|
if (options.prompt) body.prompt = options.prompt;
|
|
572
596
|
const data = await ctx.client.post("/api/generate", body);
|
|
573
597
|
const localPath = await saveOutput(data, "model3d", options.outputDir);
|
|
@@ -675,14 +699,55 @@ function createProviderCommand() {
|
|
|
675
699
|
return command;
|
|
676
700
|
}
|
|
677
701
|
|
|
702
|
+
// src/commands/upload.ts
|
|
703
|
+
import { Command as Command6 } from "commander";
|
|
704
|
+
function createUploadCommand() {
|
|
705
|
+
const command = new Command6("upload").description("Upload and manage assets");
|
|
706
|
+
command.addCommand(
|
|
707
|
+
new Command6("file").description("Upload a file and get a public URL").argument("<path>", "Path to file to upload").action(async function(filePath) {
|
|
708
|
+
const ctx = createContext(this);
|
|
709
|
+
try {
|
|
710
|
+
const data = await ctx.client.uploadFile(filePath);
|
|
711
|
+
printSuccess("asset.upload", data, ctx);
|
|
712
|
+
} catch (error2) {
|
|
713
|
+
printError("asset.upload", error2, ctx.human);
|
|
714
|
+
}
|
|
715
|
+
})
|
|
716
|
+
);
|
|
717
|
+
command.addCommand(
|
|
718
|
+
new Command6("list").description("List uploaded assets").action(async function() {
|
|
719
|
+
const ctx = createContext(this);
|
|
720
|
+
try {
|
|
721
|
+
const data = await ctx.client.get("/api/assets");
|
|
722
|
+
printSuccess("asset.list", data, ctx);
|
|
723
|
+
} catch (error2) {
|
|
724
|
+
printError("asset.list", error2, ctx.human);
|
|
725
|
+
}
|
|
726
|
+
})
|
|
727
|
+
);
|
|
728
|
+
command.addCommand(
|
|
729
|
+
new Command6("delete").description("Delete an uploaded asset (admin only)").argument("<filename>", "Filename to delete").action(async function(filename) {
|
|
730
|
+
const ctx = createContext(this);
|
|
731
|
+
try {
|
|
732
|
+
const data = await ctx.client.delete(`/api/assets/${encodeURIComponent(filename)}`);
|
|
733
|
+
printSuccess("asset.delete", data, ctx);
|
|
734
|
+
} catch (error2) {
|
|
735
|
+
printError("asset.delete", error2, ctx.human);
|
|
736
|
+
}
|
|
737
|
+
})
|
|
738
|
+
);
|
|
739
|
+
return command;
|
|
740
|
+
}
|
|
741
|
+
|
|
678
742
|
// src/index.ts
|
|
679
|
-
var program = new
|
|
743
|
+
var program = new Command7().name("asset-gateway").description("Universal asset generation gateway CLI").version(CLI_VERSION).option(
|
|
680
744
|
"--gateway-url <url>",
|
|
681
745
|
`Gateway URL (default: $ASSET_GATEWAY_URL, auth config, or ${DEFAULT_GATEWAY_URL})`
|
|
682
746
|
).option("--token <token>", "API token for authentication").option("--human", "Human-readable output instead of JSON").option("--fields <fields>", "Comma-separated list of output fields");
|
|
683
747
|
program.addCommand(createAuthCommand());
|
|
684
748
|
program.addCommand(createGenerateCommand());
|
|
685
749
|
program.addCommand(createProviderCommand());
|
|
750
|
+
program.addCommand(createUploadCommand());
|
|
686
751
|
program.addCommand(createJobCommand());
|
|
687
752
|
program.addCommand(createDescribeCommand());
|
|
688
753
|
await program.parseAsync(process.argv);
|