vibedgames 0.5.0 → 0.6.0
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/LICENSE +21 -0
- 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 +43 -33
- package/dist/commands/deploy.d.ts +10 -10
- package/dist/commands/deploy.js +155 -139
- 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 +51 -46
- package/dist/commands/generate.js +318 -264
- package/dist/commands/init.d.ts +8 -8
- package/dist/commands/init.js +31 -24
- package/dist/commands/login.js +12 -12
- package/dist/commands/logout.js +2 -2
- package/dist/commands/new.d.ts +16 -16
- package/dist/commands/new.js +153 -142
- package/dist/commands/playtest-run.d.ts +62 -0
- package/dist/commands/playtest-run.js +258 -0
- package/dist/commands/playtest.d.ts +41 -6
- package/dist/commands/playtest.js +114 -101
- package/dist/commands/update.d.ts +7 -7
- package/dist/commands/update.js +20 -17
- package/dist/commands/whoami.d.ts +5 -5
- package/dist/commands/whoami.js +8 -7
- package/dist/index.js +21 -11
- package/dist/lib/api.d.ts +4 -4
- package/dist/lib/api.js +6 -12
- package/dist/lib/archive.d.ts +4 -4
- package/dist/lib/archive.js +121 -104
- package/dist/lib/codex.d.ts +45 -15
- package/dist/lib/codex.js +175 -106
- package/dist/lib/config-file.d.ts +6 -6
- package/dist/lib/config-file.js +28 -26
- package/dist/lib/config.d.ts +8 -8
- package/dist/lib/config.js +31 -33
- package/dist/lib/manifest.d.ts +3 -3
- package/dist/lib/manifest.js +42 -38
- package/dist/lib/media-args.d.ts +7 -7
- package/dist/lib/media-args.js +113 -95
- package/dist/lib/media-download.d.ts +9 -9
- package/dist/lib/media-download.js +148 -134
- package/dist/lib/media-poll.d.ts +8 -8
- package/dist/lib/media-poll.js +32 -27
- package/dist/lib/media-upload.d.ts +2 -2
- package/dist/lib/media-upload.js +27 -27
- package/dist/lib/output.d.ts +27 -12
- package/dist/lib/output.js +26 -26
- package/dist/lib/package-manager.d.ts +3 -3
- package/dist/lib/package-manager.js +27 -22
- package/dist/lib/playtest/agent.d.ts +188 -0
- package/dist/lib/playtest/agent.js +610 -0
- package/dist/lib/playtest/browser.d.ts +109 -0
- package/dist/lib/playtest/browser.js +219 -0
- package/dist/lib/playtest/controls.d.ts +47 -0
- package/dist/lib/playtest/controls.js +218 -0
- package/dist/lib/playtest/errors.d.ts +9 -0
- package/dist/lib/playtest/errors.js +12 -0
- package/dist/lib/playtest/keys.d.ts +41 -0
- package/dist/lib/playtest/keys.js +157 -0
- package/dist/lib/playtest/run.d.ts +193 -0
- package/dist/lib/playtest/run.js +408 -0
- 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 +28 -18
- package/dist/lib/types.d.ts +5 -5
- package/dist/lib/types.js +9 -12
- package/dist/lib/update.d.ts +4 -4
- package/dist/lib/update.js +41 -32
- package/dist/lib/upload.d.ts +4 -4
- package/dist/lib/upload.js +14 -9
- package/package.json +16 -16
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",
|
|
@@ -10,78 +10,82 @@ const IGNORED_TOP_LEVEL = new Set([
|
|
|
10
10
|
"vibedgames.json",
|
|
11
11
|
]);
|
|
12
12
|
const CONTENT_TYPES = new Map(Object.entries({
|
|
13
|
-
|
|
14
|
-
htm: "text/html; charset=utf-8",
|
|
15
|
-
js: "application/javascript; charset=utf-8",
|
|
16
|
-
mjs: "application/javascript; charset=utf-8",
|
|
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
44
|
}));
|
|
45
|
-
|
|
46
|
-
const ext =
|
|
45
|
+
const contentTypeForPath = (file) => {
|
|
46
|
+
const ext = file.split(".").pop()?.toLowerCase() ?? "";
|
|
47
47
|
return CONTENT_TYPES.get(ext) ?? "application/octet-stream";
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const top = relPath.split(sep)[0] ?? "";
|
|
51
|
-
if (IGNORED_TOP_LEVEL.has(top))
|
|
48
|
+
};
|
|
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
|
@@ -10,21 +10,21 @@ import type { JsonObject } from "./types.js";
|
|
|
10
10
|
* `"prompt=hello"` upstream, and `--async=true` would slip past the
|
|
11
11
|
* RUN_RESERVED_FLAGS guard as a bogus model param.
|
|
12
12
|
*/
|
|
13
|
-
export declare
|
|
14
|
-
export
|
|
13
|
+
export declare const parseRunInput: (argv: string[]) => JsonObject;
|
|
14
|
+
export interface LocalFile {
|
|
15
15
|
path: string;
|
|
16
16
|
filename: string;
|
|
17
17
|
contentType: string;
|
|
18
|
-
}
|
|
18
|
+
}
|
|
19
19
|
/**
|
|
20
20
|
* Probe a path the user explicitly asked us to read (e.g.
|
|
21
21
|
* `vg generate upload <path>`). Skips the path-shape heuristic so a bare
|
|
22
22
|
* filename with a non-media extension — `model.glb`, `scene.fbx`,
|
|
23
23
|
* `data.ply`, even `LICENSE` — still works.
|
|
24
24
|
*/
|
|
25
|
-
export declare
|
|
26
|
-
export
|
|
25
|
+
export declare const readExplicitLocalFile: (value: string) => LocalFile | null;
|
|
26
|
+
export interface DownloadFlag {
|
|
27
27
|
mode: "off" | "on";
|
|
28
28
|
template?: string;
|
|
29
|
-
}
|
|
30
|
-
export declare
|
|
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,59 +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
|
-
// SAFETY: JSON.parse output is structurally JsonValue.
|
|
90
|
-
return JSON.parse(raw);
|
|
91
|
-
}
|
|
92
|
-
catch {
|
|
93
|
-
return raw;
|
|
94
|
-
}
|
|
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();
|
|
95
117
|
}
|
|
96
|
-
if (
|
|
97
|
-
|
|
98
|
-
if (Number.isFinite(n))
|
|
99
|
-
return n;
|
|
118
|
+
if (value.startsWith("~/") || value.startsWith("~\\")) {
|
|
119
|
+
return path.join(homedir(), value.slice(2));
|
|
100
120
|
}
|
|
101
|
-
return
|
|
102
|
-
}
|
|
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
|
+
};
|
|
103
151
|
/**
|
|
104
152
|
* Probe a path the user explicitly asked us to read (e.g.
|
|
105
153
|
* `vg generate upload <path>`). Skips the path-shape heuristic so a bare
|
|
106
154
|
* filename with a non-media extension — `model.glb`, `scene.fbx`,
|
|
107
155
|
* `data.ply`, even `LICENSE` — still works.
|
|
108
156
|
*/
|
|
109
|
-
export
|
|
110
|
-
if (value.startsWith("http://") || value.startsWith("https://"))
|
|
157
|
+
export const readExplicitLocalFile = (value) => {
|
|
158
|
+
if (value.startsWith("http://") || value.startsWith("https://")) {
|
|
111
159
|
return null;
|
|
112
|
-
|
|
160
|
+
}
|
|
161
|
+
if (value.startsWith("data:")) {
|
|
113
162
|
return null;
|
|
114
|
-
|
|
163
|
+
}
|
|
164
|
+
if (value.length === 0) {
|
|
115
165
|
return null;
|
|
166
|
+
}
|
|
116
167
|
const expanded = expandHome(value);
|
|
117
|
-
const abs = isAbsolute(expanded) ? expanded : resolve(expanded);
|
|
168
|
+
const abs = path.isAbsolute(expanded) ? expanded : path.resolve(expanded);
|
|
118
169
|
let stat;
|
|
119
170
|
try {
|
|
120
171
|
stat = statSync(abs);
|
|
@@ -122,61 +173,26 @@ export function readExplicitLocalFile(value) {
|
|
|
122
173
|
catch {
|
|
123
174
|
return null;
|
|
124
175
|
}
|
|
125
|
-
if (!stat.isFile())
|
|
176
|
+
if (!stat.isFile()) {
|
|
126
177
|
return null;
|
|
178
|
+
}
|
|
127
179
|
return {
|
|
128
|
-
path: abs,
|
|
129
|
-
filename: basename(abs),
|
|
130
180
|
contentType: contentTypeForPath(abs),
|
|
181
|
+
filename: path.basename(abs),
|
|
182
|
+
path: abs,
|
|
131
183
|
};
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// node:path's resolve() doesn't expand `~` — that's a shell feature.
|
|
135
|
-
// We expand it ourselves so quoted paths like `"~/photo.png"` work.
|
|
136
|
-
if (value === "~")
|
|
137
|
-
return homedir();
|
|
138
|
-
if (value.startsWith("~/") || value.startsWith("~\\")) {
|
|
139
|
-
return join(homedir(), value.slice(2));
|
|
140
|
-
}
|
|
141
|
-
return value;
|
|
142
|
-
}
|
|
143
|
-
function contentTypeForPath(path) {
|
|
144
|
-
// extname splits on basename, so a dotted directory like
|
|
145
|
-
// "/home/user/my.project/texture" correctly yields "" instead of
|
|
146
|
-
// mistaking "project/texture" for the extension.
|
|
147
|
-
const ext = extname(path).slice(1).toLowerCase();
|
|
148
|
-
const map = new Map(Object.entries({
|
|
149
|
-
png: "image/png",
|
|
150
|
-
jpg: "image/jpeg",
|
|
151
|
-
jpeg: "image/jpeg",
|
|
152
|
-
webp: "image/webp",
|
|
153
|
-
gif: "image/gif",
|
|
154
|
-
bmp: "image/bmp",
|
|
155
|
-
tif: "image/tiff",
|
|
156
|
-
tiff: "image/tiff",
|
|
157
|
-
avif: "image/avif",
|
|
158
|
-
mp4: "video/mp4",
|
|
159
|
-
mov: "video/quicktime",
|
|
160
|
-
webm: "video/webm",
|
|
161
|
-
mp3: "audio/mpeg",
|
|
162
|
-
wav: "audio/wav",
|
|
163
|
-
ogg: "audio/ogg",
|
|
164
|
-
flac: "audio/flac",
|
|
165
|
-
m4a: "audio/mp4",
|
|
166
|
-
txt: "text/plain",
|
|
167
|
-
json: "application/json",
|
|
168
|
-
}));
|
|
169
|
-
return map.get(ext) ?? "application/octet-stream";
|
|
170
|
-
}
|
|
171
|
-
export function parseDownloadFlag(argv) {
|
|
184
|
+
};
|
|
185
|
+
export const parseDownloadFlag = (argv) => {
|
|
172
186
|
let lastIdx = -1;
|
|
173
187
|
let inlineValue;
|
|
174
|
-
for (let i = 0; i < argv.length; i
|
|
188
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
175
189
|
const arg = argv[i];
|
|
176
|
-
if (!arg)
|
|
190
|
+
if (!arg) {
|
|
177
191
|
continue;
|
|
178
|
-
|
|
192
|
+
}
|
|
193
|
+
if (arg === "--") {
|
|
179
194
|
break;
|
|
195
|
+
}
|
|
180
196
|
if (arg === "--download") {
|
|
181
197
|
lastIdx = i;
|
|
182
198
|
inlineValue = undefined;
|
|
@@ -186,11 +202,13 @@ export function parseDownloadFlag(argv) {
|
|
|
186
202
|
inlineValue = arg.slice("--download=".length);
|
|
187
203
|
}
|
|
188
204
|
}
|
|
189
|
-
if (lastIdx === -1)
|
|
205
|
+
if (lastIdx === -1) {
|
|
190
206
|
return { mode: "off" };
|
|
207
|
+
}
|
|
191
208
|
const candidate = inlineValue ?? argv[lastIdx + 1];
|
|
192
|
-
if (candidate === "false")
|
|
209
|
+
if (candidate === "false") {
|
|
193
210
|
return { mode: "off" };
|
|
211
|
+
}
|
|
194
212
|
if (candidate === undefined ||
|
|
195
213
|
candidate === "" ||
|
|
196
214
|
candidate.startsWith("--") ||
|
|
@@ -198,4 +216,4 @@ export function parseDownloadFlag(argv) {
|
|
|
198
216
|
return { mode: "on" };
|
|
199
217
|
}
|
|
200
218
|
return { mode: "on", template: candidate };
|
|
201
|
-
}
|
|
219
|
+
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import type { JsonValue } from "./types.js";
|
|
2
|
+
interface MediaRef {
|
|
3
3
|
url: string;
|
|
4
4
|
filename: string;
|
|
5
5
|
contentType: string | null;
|
|
6
|
-
}
|
|
6
|
+
}
|
|
7
7
|
/**
|
|
8
8
|
* Walk a fal result payload and pull out anything that looks like a media
|
|
9
9
|
* output. fal endpoints embed outputs in objects shaped like
|
|
@@ -11,8 +11,8 @@ type MediaRef = {
|
|
|
11
11
|
* content types and also fall back to URL extension when content_type is
|
|
12
12
|
* absent (some endpoints omit it).
|
|
13
13
|
*/
|
|
14
|
-
export declare
|
|
15
|
-
|
|
14
|
+
export declare const extractMediaRefs: (result: JsonValue) => MediaRef[];
|
|
15
|
+
interface DownloadResult {
|
|
16
16
|
downloaded: string[];
|
|
17
17
|
failed: {
|
|
18
18
|
url: string;
|
|
@@ -22,16 +22,16 @@ type DownloadResult = {
|
|
|
22
22
|
path: string;
|
|
23
23
|
actual: string;
|
|
24
24
|
}[];
|
|
25
|
-
}
|
|
25
|
+
}
|
|
26
|
+
export declare const disambiguateTargets: (paths: string[]) => string[];
|
|
26
27
|
/**
|
|
27
28
|
* Download all extracted media refs to disk, materializing the path from
|
|
28
29
|
* a template. Supported placeholders: {index}, {name}, {ext}, {request_id}.
|
|
29
30
|
* Falls back to the source filename in the cwd when no template is given.
|
|
30
31
|
*/
|
|
31
|
-
export declare
|
|
32
|
+
export declare const downloadMedia: (opts: {
|
|
32
33
|
refs: MediaRef[];
|
|
33
34
|
template?: string;
|
|
34
35
|
requestId: string;
|
|
35
|
-
})
|
|
36
|
-
export declare function disambiguateTargets(paths: string[]): string[];
|
|
36
|
+
}) => Promise<DownloadResult>;
|
|
37
37
|
export {};
|