vibedgames 0.4.1 → 0.5.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/README.md +1 -1
- package/dist/commands/completions.d.ts +1 -1
- package/dist/commands/completions.js +21 -20
- package/dist/commands/credits.d.ts +5 -5
- package/dist/commands/credits.js +45 -47
- package/dist/commands/deploy.d.ts +10 -10
- package/dist/commands/deploy.js +157 -137
- package/dist/commands/factory.d.ts +1 -1
- package/dist/commands/factory.js +18 -15
- package/dist/commands/fork.d.ts +14 -14
- package/dist/commands/fork.js +53 -45
- package/dist/commands/generate.js +343 -286
- package/dist/commands/init.d.ts +8 -8
- package/dist/commands/init.js +31 -24
- package/dist/commands/login.js +14 -14
- package/dist/commands/logout.js +2 -2
- package/dist/commands/new.d.ts +16 -16
- package/dist/commands/new.js +191 -165
- package/dist/commands/playtest.d.ts +5 -5
- package/dist/commands/playtest.js +103 -97
- package/dist/commands/update.d.ts +7 -7
- package/dist/commands/update.js +22 -17
- package/dist/commands/whoami.d.ts +5 -5
- package/dist/commands/whoami.js +11 -10
- package/dist/index.js +12 -10
- package/dist/lib/api.d.ts +16 -4
- package/dist/lib/api.js +20 -32
- package/dist/lib/archive.d.ts +4 -4
- package/dist/lib/archive.js +123 -102
- package/dist/lib/codex.d.ts +46 -15
- package/dist/lib/codex.js +178 -108
- package/dist/lib/config-file.d.ts +6 -6
- package/dist/lib/config-file.js +33 -30
- package/dist/lib/config.d.ts +8 -8
- package/dist/lib/config.js +38 -30
- package/dist/lib/manifest.d.ts +3 -3
- package/dist/lib/manifest.js +44 -40
- package/dist/lib/media-args.d.ts +8 -6
- package/dist/lib/media-args.js +113 -94
- package/dist/lib/media-download.d.ts +9 -8
- package/dist/lib/media-download.js +158 -144
- package/dist/lib/media-poll.d.ts +8 -7
- package/dist/lib/media-poll.js +38 -32
- package/dist/lib/media-upload.d.ts +1 -1
- package/dist/lib/media-upload.js +30 -29
- package/dist/lib/output.d.ts +34 -11
- package/dist/lib/output.js +28 -20
- package/dist/lib/package-manager.d.ts +3 -3
- package/dist/lib/package-manager.js +27 -22
- package/dist/lib/run.d.ts +4 -4
- package/dist/lib/run.js +7 -4
- package/dist/lib/strict-args.d.ts +4 -4
- package/dist/lib/strict-args.js +29 -19
- package/dist/lib/types.d.ts +16 -2
- package/dist/lib/types.js +10 -4
- package/dist/lib/update.d.ts +4 -4
- package/dist/lib/update.js +47 -35
- package/dist/lib/upload.d.ts +4 -4
- package/dist/lib/upload.js +14 -9
- package/package.json +7 -8
package/dist/lib/config.js
CHANGED
|
@@ -1,46 +1,54 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, readFileSync, writeFileSync, unlinkSync } from "node:fs";
|
|
2
2
|
import { homedir } from "node:os";
|
|
3
|
-
import
|
|
4
|
-
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { isJsonObject, isJsonString } from "./types.js";
|
|
5
|
+
export const getConfigDir = () => {
|
|
5
6
|
const xdg = process.env.XDG_CONFIG_HOME;
|
|
6
|
-
const base = xdg ?? join(homedir(), ".config");
|
|
7
|
-
return join(base, "vg");
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const path = getConfigPath();
|
|
14
|
-
if (!existsSync(path))
|
|
7
|
+
const base = xdg ?? path.join(homedir(), ".config");
|
|
8
|
+
return path.join(base, "vg");
|
|
9
|
+
};
|
|
10
|
+
const getConfigPath = () => path.join(getConfigDir(), "auth.json");
|
|
11
|
+
export const getConfig = () => {
|
|
12
|
+
const file = getConfigPath();
|
|
13
|
+
if (!existsSync(file)) {
|
|
15
14
|
return null;
|
|
15
|
+
}
|
|
16
|
+
let raw;
|
|
16
17
|
try {
|
|
17
|
-
|
|
18
|
+
raw = JSON.parse(readFileSync(file, "utf-8"));
|
|
18
19
|
}
|
|
19
20
|
catch {
|
|
20
21
|
return null;
|
|
21
22
|
}
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
// auth.json is only ever written by saveConfig, so both fields are present
|
|
24
|
+
// in practice; a hand-corrupted file reads as "not logged in".
|
|
25
|
+
if (!isJsonObject(raw)) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
const { token, baseUrl } = raw;
|
|
29
|
+
if (!isJsonString(token) || !isJsonString(baseUrl)) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
return { baseUrl, token };
|
|
33
|
+
};
|
|
34
|
+
export const saveConfig = (config) => {
|
|
24
35
|
const dir = getConfigDir();
|
|
25
36
|
if (!existsSync(dir)) {
|
|
26
|
-
mkdirSync(dir, {
|
|
37
|
+
mkdirSync(dir, { mode: 0o700, recursive: true });
|
|
27
38
|
}
|
|
28
39
|
writeFileSync(getConfigPath(), JSON.stringify(config, null, 2), {
|
|
29
40
|
mode: 0o600,
|
|
30
41
|
});
|
|
31
|
-
}
|
|
32
|
-
export
|
|
33
|
-
const
|
|
34
|
-
if (existsSync(
|
|
35
|
-
unlinkSync(
|
|
42
|
+
};
|
|
43
|
+
export const clearConfig = () => {
|
|
44
|
+
const file = getConfigPath();
|
|
45
|
+
if (existsSync(file)) {
|
|
46
|
+
unlinkSync(file);
|
|
36
47
|
}
|
|
37
|
-
}
|
|
38
|
-
export
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
// the user's real `vg login` credentials.
|
|
45
|
-
return process.env.VG_TOKEN ?? getConfig()?.token ?? null;
|
|
46
|
-
}
|
|
48
|
+
};
|
|
49
|
+
export const getBaseUrl = () => process.env.VG_API_URL ?? getConfig()?.baseUrl ?? "https://vibedgames.com";
|
|
50
|
+
export const getToken = () =>
|
|
51
|
+
// VG_TOKEN lets local/CI runs authenticate without touching the saved
|
|
52
|
+
// login (e.g. a seeded dev session), so headless testing never clobbers
|
|
53
|
+
// the user's real `vg login` credentials.
|
|
54
|
+
process.env.VG_TOKEN ?? getConfig()?.token ?? null;
|
package/dist/lib/manifest.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export
|
|
1
|
+
export interface ManifestFile {
|
|
2
2
|
/** forward-slash relative path, e.g. "assets/sprite.png" */
|
|
3
3
|
path: string;
|
|
4
4
|
/** absolute filesystem path */
|
|
@@ -6,5 +6,5 @@ export type ManifestFile = {
|
|
|
6
6
|
size: number;
|
|
7
7
|
sha256: string;
|
|
8
8
|
contentType: string;
|
|
9
|
-
}
|
|
10
|
-
export declare
|
|
9
|
+
}
|
|
10
|
+
export declare const buildManifest: (rootDir: string) => ManifestFile[];
|
package/dist/lib/manifest.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
import { readFileSync, readdirSync, statSync } from "node:fs";
|
|
3
|
-
import
|
|
3
|
+
import path from "node:path";
|
|
4
4
|
const IGNORED_TOP_LEVEL = new Set([
|
|
5
5
|
"node_modules",
|
|
6
6
|
".git",
|
|
@@ -9,79 +9,83 @@ const IGNORED_TOP_LEVEL = new Set([
|
|
|
9
9
|
".DS_Store",
|
|
10
10
|
"vibedgames.json",
|
|
11
11
|
]);
|
|
12
|
-
const CONTENT_TYPES = {
|
|
13
|
-
|
|
14
|
-
htm: "text/html; charset=utf-8",
|
|
15
|
-
js: "application/javascript; charset=utf-8",
|
|
16
|
-
mjs: "application/javascript; charset=utf-8",
|
|
12
|
+
const CONTENT_TYPES = new Map(Object.entries({
|
|
13
|
+
avif: "image/avif",
|
|
17
14
|
cjs: "application/javascript; charset=utf-8",
|
|
18
15
|
css: "text/css; charset=utf-8",
|
|
19
|
-
json: "application/json; charset=utf-8",
|
|
20
|
-
map: "application/json; charset=utf-8",
|
|
21
|
-
svg: "image/svg+xml",
|
|
22
|
-
png: "image/png",
|
|
23
|
-
jpg: "image/jpeg",
|
|
24
|
-
jpeg: "image/jpeg",
|
|
25
16
|
gif: "image/gif",
|
|
26
|
-
webp: "image/webp",
|
|
27
|
-
avif: "image/avif",
|
|
28
|
-
ico: "image/x-icon",
|
|
29
|
-
wasm: "application/wasm",
|
|
30
17
|
glb: "model/gltf-binary",
|
|
31
18
|
gltf: "model/gltf+json",
|
|
19
|
+
htm: "text/html; charset=utf-8",
|
|
20
|
+
html: "text/html; charset=utf-8",
|
|
21
|
+
ico: "image/x-icon",
|
|
22
|
+
jpeg: "image/jpeg",
|
|
23
|
+
jpg: "image/jpeg",
|
|
24
|
+
js: "application/javascript; charset=utf-8",
|
|
25
|
+
json: "application/json; charset=utf-8",
|
|
26
|
+
m4a: "audio/mp4",
|
|
27
|
+
map: "application/json; charset=utf-8",
|
|
28
|
+
mjs: "application/javascript; charset=utf-8",
|
|
32
29
|
mp3: "audio/mpeg",
|
|
30
|
+
mp4: "video/mp4",
|
|
33
31
|
ogg: "audio/ogg",
|
|
32
|
+
otf: "font/otf",
|
|
33
|
+
png: "image/png",
|
|
34
|
+
svg: "image/svg+xml",
|
|
35
|
+
ttf: "font/ttf",
|
|
36
|
+
txt: "text/plain; charset=utf-8",
|
|
37
|
+
wasm: "application/wasm",
|
|
34
38
|
wav: "audio/wav",
|
|
35
|
-
m4a: "audio/mp4",
|
|
36
|
-
mp4: "video/mp4",
|
|
37
39
|
webm: "video/webm",
|
|
38
|
-
|
|
39
|
-
otf: "font/otf",
|
|
40
|
+
webp: "image/webp",
|
|
40
41
|
woff: "font/woff",
|
|
41
42
|
woff2: "font/woff2",
|
|
42
|
-
txt: "text/plain; charset=utf-8",
|
|
43
43
|
xml: "application/xml",
|
|
44
|
+
}));
|
|
45
|
+
const contentTypeForPath = (file) => {
|
|
46
|
+
const ext = file.split(".").pop()?.toLowerCase() ?? "";
|
|
47
|
+
return CONTENT_TYPES.get(ext) ?? "application/octet-stream";
|
|
44
48
|
};
|
|
45
|
-
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
function shouldIgnore(relPath) {
|
|
50
|
-
const top = relPath.split(sep)[0] ?? "";
|
|
51
|
-
if (IGNORED_TOP_LEVEL.has(top))
|
|
49
|
+
const shouldIgnore = (relPath) => {
|
|
50
|
+
const top = relPath.split(path.sep)[0] ?? "";
|
|
51
|
+
if (IGNORED_TOP_LEVEL.has(top)) {
|
|
52
52
|
return true;
|
|
53
|
+
}
|
|
53
54
|
// skip hidden files anywhere in the tree
|
|
54
|
-
if (relPath.split(sep).some((seg) => seg.startsWith(".")))
|
|
55
|
+
if (relPath.split(path.sep).some((seg) => seg.startsWith("."))) {
|
|
55
56
|
return true;
|
|
57
|
+
}
|
|
56
58
|
return false;
|
|
57
|
-
}
|
|
58
|
-
export
|
|
59
|
+
};
|
|
60
|
+
export const buildManifest = (rootDir) => {
|
|
59
61
|
const files = [];
|
|
60
62
|
const walk = (dir) => {
|
|
61
63
|
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
62
|
-
const abs = join(dir, entry.name);
|
|
63
|
-
const rel = relative(rootDir, abs);
|
|
64
|
-
if (shouldIgnore(rel))
|
|
64
|
+
const abs = path.join(dir, entry.name);
|
|
65
|
+
const rel = path.relative(rootDir, abs);
|
|
66
|
+
if (shouldIgnore(rel)) {
|
|
65
67
|
continue;
|
|
68
|
+
}
|
|
66
69
|
if (entry.isDirectory()) {
|
|
67
70
|
walk(abs);
|
|
68
71
|
continue;
|
|
69
72
|
}
|
|
70
|
-
if (!entry.isFile())
|
|
73
|
+
if (!entry.isFile()) {
|
|
71
74
|
continue;
|
|
75
|
+
}
|
|
72
76
|
const stat = statSync(abs);
|
|
73
77
|
const buf = readFileSync(abs);
|
|
74
78
|
const sha256 = createHash("sha256").update(buf).digest("hex");
|
|
75
|
-
const posixPath = rel.split(sep).join("/");
|
|
79
|
+
const posixPath = rel.split(path.sep).join("/");
|
|
76
80
|
files.push({
|
|
77
|
-
path: posixPath,
|
|
78
81
|
absolutePath: abs,
|
|
79
|
-
size: stat.size,
|
|
80
|
-
sha256,
|
|
81
82
|
contentType: contentTypeForPath(posixPath),
|
|
83
|
+
path: posixPath,
|
|
84
|
+
sha256,
|
|
85
|
+
size: stat.size,
|
|
82
86
|
});
|
|
83
87
|
}
|
|
84
88
|
};
|
|
85
89
|
walk(rootDir);
|
|
86
90
|
return files;
|
|
87
|
-
}
|
|
91
|
+
};
|
package/dist/lib/media-args.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { JsonObject } from "./types.js";
|
|
1
2
|
/**
|
|
2
3
|
* Parse `--<key> value` pairs from argv into a JS object, JSON-decoding
|
|
3
4
|
* values that look like JSON (true/false/null/numbers/objects/arrays) and
|
|
@@ -9,20 +10,21 @@
|
|
|
9
10
|
* `"prompt=hello"` upstream, and `--async=true` would slip past the
|
|
10
11
|
* RUN_RESERVED_FLAGS guard as a bogus model param.
|
|
11
12
|
*/
|
|
12
|
-
export declare
|
|
13
|
-
export
|
|
13
|
+
export declare const parseRunInput: (argv: string[]) => JsonObject;
|
|
14
|
+
export interface LocalFile {
|
|
14
15
|
path: string;
|
|
15
16
|
filename: string;
|
|
16
17
|
contentType: string;
|
|
17
|
-
}
|
|
18
|
+
}
|
|
18
19
|
/**
|
|
19
20
|
* Probe a path the user explicitly asked us to read (e.g.
|
|
20
21
|
* `vg generate upload <path>`). Skips the path-shape heuristic so a bare
|
|
21
22
|
* filename with a non-media extension — `model.glb`, `scene.fbx`,
|
|
22
23
|
* `data.ply`, even `LICENSE` — still works.
|
|
23
24
|
*/
|
|
24
|
-
export declare
|
|
25
|
-
export
|
|
25
|
+
export declare const readExplicitLocalFile: (value: string) => LocalFile | null;
|
|
26
|
+
export interface DownloadFlag {
|
|
26
27
|
mode: "off" | "on";
|
|
27
28
|
template?: string;
|
|
28
|
-
}
|
|
29
|
+
}
|
|
30
|
+
export declare const parseDownloadFlag: (argv: string[]) => DownloadFlag;
|
package/dist/lib/media-args.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { statSync } from "node:fs";
|
|
2
2
|
import { homedir } from "node:os";
|
|
3
|
-
import
|
|
3
|
+
import path from "node:path";
|
|
4
4
|
// `--json`/`--help`/`--quiet` are global; `--async` switches the run path
|
|
5
5
|
// in citty; `--download` takes an optional template. None of them should
|
|
6
6
|
// leak through to fal as model parameters. `--logs` is intentionally NOT
|
|
@@ -15,6 +15,46 @@ const RUN_RESERVED_FLAGS = new Set([
|
|
|
15
15
|
"--download",
|
|
16
16
|
"--provider",
|
|
17
17
|
]);
|
|
18
|
+
const assign = (out, key, value) => {
|
|
19
|
+
const existing = out[key];
|
|
20
|
+
if (existing !== undefined) {
|
|
21
|
+
if (Array.isArray(existing)) {
|
|
22
|
+
existing.push(value);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
out[key] = [existing, value];
|
|
26
|
+
}
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
out[key] = value;
|
|
30
|
+
};
|
|
31
|
+
const parseValue = (raw) => {
|
|
32
|
+
if (raw === "true") {
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
if (raw === "false") {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
if (raw === "null") {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
if (raw.length > 0 && (raw[0] === "{" || raw[0] === "[")) {
|
|
42
|
+
try {
|
|
43
|
+
// SAFETY: JSON.parse output is structurally JsonValue.
|
|
44
|
+
return JSON.parse(raw);
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return raw;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (/^-?\d+(?:\.\d+)?$/u.test(raw)) {
|
|
51
|
+
const n = Number(raw);
|
|
52
|
+
if (Number.isFinite(n)) {
|
|
53
|
+
return n;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return raw;
|
|
57
|
+
};
|
|
18
58
|
/**
|
|
19
59
|
* Parse `--<key> value` pairs from argv into a JS object, JSON-decoding
|
|
20
60
|
* values that look like JSON (true/false/null/numbers/objects/arrays) and
|
|
@@ -26,17 +66,19 @@ const RUN_RESERVED_FLAGS = new Set([
|
|
|
26
66
|
* `"prompt=hello"` upstream, and `--async=true` would slip past the
|
|
27
67
|
* RUN_RESERVED_FLAGS guard as a bogus model param.
|
|
28
68
|
*/
|
|
29
|
-
export
|
|
69
|
+
export const parseRunInput = (argv) => {
|
|
30
70
|
const out = {};
|
|
31
|
-
for (let i = 0; i < argv.length; i
|
|
71
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
32
72
|
const arg = argv[i];
|
|
33
|
-
if (!arg || !arg.startsWith("--"))
|
|
73
|
+
if (!arg || !arg.startsWith("--")) {
|
|
34
74
|
continue;
|
|
75
|
+
}
|
|
35
76
|
// POSIX `--` argument terminator: stop interpreting subsequent
|
|
36
77
|
// tokens as flags. Without this guard, `--` itself parses as
|
|
37
78
|
// `{ "": <next token> }` and pollutes the request body.
|
|
38
|
-
if (arg === "--")
|
|
79
|
+
if (arg === "--") {
|
|
39
80
|
break;
|
|
81
|
+
}
|
|
40
82
|
const eqIdx = arg.indexOf("=");
|
|
41
83
|
const name = eqIdx === -1 ? arg : arg.slice(0, eqIdx);
|
|
42
84
|
const inlineValue = eqIdx === -1 ? undefined : arg.slice(eqIdx + 1);
|
|
@@ -46,8 +88,9 @@ export function parseRunInput(argv) {
|
|
|
46
88
|
// already attached and we move on without skipping anything.
|
|
47
89
|
if (name === "--download" && inlineValue === undefined) {
|
|
48
90
|
const next = argv[i + 1];
|
|
49
|
-
if (next && !next.startsWith("--"))
|
|
50
|
-
i
|
|
91
|
+
if (next && !next.startsWith("--")) {
|
|
92
|
+
i += 1;
|
|
93
|
+
}
|
|
51
94
|
}
|
|
52
95
|
continue;
|
|
53
96
|
}
|
|
@@ -62,58 +105,67 @@ export function parseRunInput(argv) {
|
|
|
62
105
|
continue;
|
|
63
106
|
}
|
|
64
107
|
assign(out, key, parseValue(next));
|
|
65
|
-
i
|
|
108
|
+
i += 1;
|
|
66
109
|
}
|
|
67
110
|
return out;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
else
|
|
75
|
-
out[key] = [existing, value];
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
out[key] = value;
|
|
79
|
-
}
|
|
80
|
-
function parseValue(raw) {
|
|
81
|
-
if (raw === "true")
|
|
82
|
-
return true;
|
|
83
|
-
if (raw === "false")
|
|
84
|
-
return false;
|
|
85
|
-
if (raw === "null")
|
|
86
|
-
return null;
|
|
87
|
-
if (raw.length > 0 && (raw[0] === "{" || raw[0] === "[")) {
|
|
88
|
-
try {
|
|
89
|
-
return JSON.parse(raw);
|
|
90
|
-
}
|
|
91
|
-
catch {
|
|
92
|
-
return raw;
|
|
93
|
-
}
|
|
111
|
+
};
|
|
112
|
+
const expandHome = (value) => {
|
|
113
|
+
// node:path's resolve() doesn't expand `~` — that's a shell feature.
|
|
114
|
+
// We expand it ourselves so quoted paths like `"~/photo.png"` work.
|
|
115
|
+
if (value === "~") {
|
|
116
|
+
return homedir();
|
|
94
117
|
}
|
|
95
|
-
if (
|
|
96
|
-
|
|
97
|
-
if (Number.isFinite(n))
|
|
98
|
-
return n;
|
|
118
|
+
if (value.startsWith("~/") || value.startsWith("~\\")) {
|
|
119
|
+
return path.join(homedir(), value.slice(2));
|
|
99
120
|
}
|
|
100
|
-
return
|
|
101
|
-
}
|
|
121
|
+
return value;
|
|
122
|
+
};
|
|
123
|
+
const contentTypeForPath = (file) => {
|
|
124
|
+
// extname splits on basename, so a dotted directory like
|
|
125
|
+
// "/home/user/my.project/texture" correctly yields "" instead of
|
|
126
|
+
// mistaking "project/texture" for the extension.
|
|
127
|
+
const ext = path.extname(file).slice(1).toLowerCase();
|
|
128
|
+
const map = new Map(Object.entries({
|
|
129
|
+
avif: "image/avif",
|
|
130
|
+
bmp: "image/bmp",
|
|
131
|
+
flac: "audio/flac",
|
|
132
|
+
gif: "image/gif",
|
|
133
|
+
jpeg: "image/jpeg",
|
|
134
|
+
jpg: "image/jpeg",
|
|
135
|
+
json: "application/json",
|
|
136
|
+
m4a: "audio/mp4",
|
|
137
|
+
mov: "video/quicktime",
|
|
138
|
+
mp3: "audio/mpeg",
|
|
139
|
+
mp4: "video/mp4",
|
|
140
|
+
ogg: "audio/ogg",
|
|
141
|
+
png: "image/png",
|
|
142
|
+
tif: "image/tiff",
|
|
143
|
+
tiff: "image/tiff",
|
|
144
|
+
txt: "text/plain",
|
|
145
|
+
wav: "audio/wav",
|
|
146
|
+
webm: "video/webm",
|
|
147
|
+
webp: "image/webp",
|
|
148
|
+
}));
|
|
149
|
+
return map.get(ext) ?? "application/octet-stream";
|
|
150
|
+
};
|
|
102
151
|
/**
|
|
103
152
|
* Probe a path the user explicitly asked us to read (e.g.
|
|
104
153
|
* `vg generate upload <path>`). Skips the path-shape heuristic so a bare
|
|
105
154
|
* filename with a non-media extension — `model.glb`, `scene.fbx`,
|
|
106
155
|
* `data.ply`, even `LICENSE` — still works.
|
|
107
156
|
*/
|
|
108
|
-
export
|
|
109
|
-
if (value.startsWith("http://") || value.startsWith("https://"))
|
|
157
|
+
export const readExplicitLocalFile = (value) => {
|
|
158
|
+
if (value.startsWith("http://") || value.startsWith("https://")) {
|
|
110
159
|
return null;
|
|
111
|
-
|
|
160
|
+
}
|
|
161
|
+
if (value.startsWith("data:")) {
|
|
112
162
|
return null;
|
|
113
|
-
|
|
163
|
+
}
|
|
164
|
+
if (value.length === 0) {
|
|
114
165
|
return null;
|
|
166
|
+
}
|
|
115
167
|
const expanded = expandHome(value);
|
|
116
|
-
const abs = isAbsolute(expanded) ? expanded : resolve(expanded);
|
|
168
|
+
const abs = path.isAbsolute(expanded) ? expanded : path.resolve(expanded);
|
|
117
169
|
let stat;
|
|
118
170
|
try {
|
|
119
171
|
stat = statSync(abs);
|
|
@@ -121,61 +173,26 @@ export function readExplicitLocalFile(value) {
|
|
|
121
173
|
catch {
|
|
122
174
|
return null;
|
|
123
175
|
}
|
|
124
|
-
if (!stat.isFile())
|
|
176
|
+
if (!stat.isFile()) {
|
|
125
177
|
return null;
|
|
178
|
+
}
|
|
126
179
|
return {
|
|
127
|
-
path: abs,
|
|
128
|
-
filename: basename(abs),
|
|
129
180
|
contentType: contentTypeForPath(abs),
|
|
181
|
+
filename: path.basename(abs),
|
|
182
|
+
path: abs,
|
|
130
183
|
};
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
// node:path's resolve() doesn't expand `~` — that's a shell feature.
|
|
134
|
-
// We expand it ourselves so quoted paths like `"~/photo.png"` work.
|
|
135
|
-
if (value === "~")
|
|
136
|
-
return homedir();
|
|
137
|
-
if (value.startsWith("~/") || value.startsWith("~\\")) {
|
|
138
|
-
return join(homedir(), value.slice(2));
|
|
139
|
-
}
|
|
140
|
-
return value;
|
|
141
|
-
}
|
|
142
|
-
function contentTypeForPath(path) {
|
|
143
|
-
// extname splits on basename, so a dotted directory like
|
|
144
|
-
// "/home/user/my.project/texture" correctly yields "" instead of
|
|
145
|
-
// mistaking "project/texture" for the extension.
|
|
146
|
-
const ext = extname(path).slice(1).toLowerCase();
|
|
147
|
-
const map = {
|
|
148
|
-
png: "image/png",
|
|
149
|
-
jpg: "image/jpeg",
|
|
150
|
-
jpeg: "image/jpeg",
|
|
151
|
-
webp: "image/webp",
|
|
152
|
-
gif: "image/gif",
|
|
153
|
-
bmp: "image/bmp",
|
|
154
|
-
tif: "image/tiff",
|
|
155
|
-
tiff: "image/tiff",
|
|
156
|
-
avif: "image/avif",
|
|
157
|
-
mp4: "video/mp4",
|
|
158
|
-
mov: "video/quicktime",
|
|
159
|
-
webm: "video/webm",
|
|
160
|
-
mp3: "audio/mpeg",
|
|
161
|
-
wav: "audio/wav",
|
|
162
|
-
ogg: "audio/ogg",
|
|
163
|
-
flac: "audio/flac",
|
|
164
|
-
m4a: "audio/mp4",
|
|
165
|
-
txt: "text/plain",
|
|
166
|
-
json: "application/json",
|
|
167
|
-
};
|
|
168
|
-
return map[ext] ?? "application/octet-stream";
|
|
169
|
-
}
|
|
170
|
-
export function parseDownloadFlag(argv) {
|
|
184
|
+
};
|
|
185
|
+
export const parseDownloadFlag = (argv) => {
|
|
171
186
|
let lastIdx = -1;
|
|
172
187
|
let inlineValue;
|
|
173
|
-
for (let i = 0; i < argv.length; i
|
|
188
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
174
189
|
const arg = argv[i];
|
|
175
|
-
if (!arg)
|
|
190
|
+
if (!arg) {
|
|
176
191
|
continue;
|
|
177
|
-
|
|
192
|
+
}
|
|
193
|
+
if (arg === "--") {
|
|
178
194
|
break;
|
|
195
|
+
}
|
|
179
196
|
if (arg === "--download") {
|
|
180
197
|
lastIdx = i;
|
|
181
198
|
inlineValue = undefined;
|
|
@@ -185,11 +202,13 @@ export function parseDownloadFlag(argv) {
|
|
|
185
202
|
inlineValue = arg.slice("--download=".length);
|
|
186
203
|
}
|
|
187
204
|
}
|
|
188
|
-
if (lastIdx === -1)
|
|
205
|
+
if (lastIdx === -1) {
|
|
189
206
|
return { mode: "off" };
|
|
207
|
+
}
|
|
190
208
|
const candidate = inlineValue ?? argv[lastIdx + 1];
|
|
191
|
-
if (candidate === "false")
|
|
209
|
+
if (candidate === "false") {
|
|
192
210
|
return { mode: "off" };
|
|
211
|
+
}
|
|
193
212
|
if (candidate === undefined ||
|
|
194
213
|
candidate === "" ||
|
|
195
214
|
candidate.startsWith("--") ||
|
|
@@ -197,4 +216,4 @@ export function parseDownloadFlag(argv) {
|
|
|
197
216
|
return { mode: "on" };
|
|
198
217
|
}
|
|
199
218
|
return { mode: "on", template: candidate };
|
|
200
|
-
}
|
|
219
|
+
};
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
type
|
|
1
|
+
import type { JsonValue } from "./types.js";
|
|
2
|
+
interface MediaRef {
|
|
2
3
|
url: string;
|
|
3
4
|
filename: string;
|
|
4
5
|
contentType: string | null;
|
|
5
|
-
}
|
|
6
|
+
}
|
|
6
7
|
/**
|
|
7
8
|
* Walk a fal result payload and pull out anything that looks like a media
|
|
8
9
|
* output. fal endpoints embed outputs in objects shaped like
|
|
@@ -10,8 +11,8 @@ type MediaRef = {
|
|
|
10
11
|
* content types and also fall back to URL extension when content_type is
|
|
11
12
|
* absent (some endpoints omit it).
|
|
12
13
|
*/
|
|
13
|
-
export declare
|
|
14
|
-
|
|
14
|
+
export declare const extractMediaRefs: (result: JsonValue) => MediaRef[];
|
|
15
|
+
interface DownloadResult {
|
|
15
16
|
downloaded: string[];
|
|
16
17
|
failed: {
|
|
17
18
|
url: string;
|
|
@@ -21,16 +22,16 @@ type DownloadResult = {
|
|
|
21
22
|
path: string;
|
|
22
23
|
actual: string;
|
|
23
24
|
}[];
|
|
24
|
-
}
|
|
25
|
+
}
|
|
26
|
+
export declare const disambiguateTargets: (paths: string[]) => string[];
|
|
25
27
|
/**
|
|
26
28
|
* Download all extracted media refs to disk, materializing the path from
|
|
27
29
|
* a template. Supported placeholders: {index}, {name}, {ext}, {request_id}.
|
|
28
30
|
* Falls back to the source filename in the cwd when no template is given.
|
|
29
31
|
*/
|
|
30
|
-
export declare
|
|
32
|
+
export declare const downloadMedia: (opts: {
|
|
31
33
|
refs: MediaRef[];
|
|
32
34
|
template?: string;
|
|
33
35
|
requestId: string;
|
|
34
|
-
})
|
|
35
|
-
export declare function disambiguateTargets(paths: string[]): string[];
|
|
36
|
+
}) => Promise<DownloadResult>;
|
|
36
37
|
export {};
|