@civitai/app-sdk 0.92.0 → 0.93.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/README.md +3 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.js +4 -2
- package/dist/save-model3d/index.d.ts +54 -0
- package/dist/save-model3d/index.js +216 -0
- package/dist/save-zip/index.d.ts +5 -1
- package/dist/save-zip/index.js +7 -1
- package/package.json +5 -1
package/README.md
CHANGED
|
@@ -34,12 +34,13 @@ pnpm add @civitai/app-sdk
|
|
|
34
34
|
| `manifest/*` — `defineBlock`, `SCHEMA_DIVERGENCES`, `KNOWN_GAPS` (**Node only**) | Build-time manifest validation. `defineBlock(config)` compiles the vendored canonical schema with [Ajv](https://ajv.js.org) and validates a `BlockManifestV1` against it, so authoring mistakes surface in `pnpm dev` instead of at `civitai app validate`/submit. It is **derived from the schema, not a hand-written mirror of it** — that mirror is what produced [#330](https://github.com/civitai/civitai-app-starters/issues/330). Needs `node:fs` and the optional peer `ajv`, which is why it is not on the browser-facing `./blocks` surface. |
|
|
35
35
|
| `vite/*` — `blockManifestPlugin` (**Node only**) | A Vite plugin wrapping `defineBlock`, firing from `configResolved` — the one hook Vite calls on both the dev-server and the build path. Every block scaffold registers it, so `pnpm dev`, `pnpm dev:harness` and `pnpm build` all fail on a bad manifest with the offending field path. On the dev server only, it also exposes the manifest's `scopes` + `storage` to `@civitai/sdk` for a dev-tunnel local preview. Optional peers: `ajv` (runtime) and `vite` (types only). |
|
|
36
36
|
| `save-zip/*` — `validateSaveZip`, `verifySaveZipInflate`, `looksLikeSaveZip`, `SAVE_ZIP_MAX_BYTES`, `SAVE_ZIP_LIMITS`, `SAVE_ZIP_ALLOWED_EXTENSIONS`, the `SAVE_ZIP_*_ERROR` strings | The `.zip` validator behind `SAVE_IMAGE { bytes }` — the ONE copy: the civitai.com host runs it before it starts a download, and `@civitai/blocks-react`'s `createMockHost` imports it, so a block's tests accept and refuse the zips production does. Structure (local headers, central directory and EOCD laid end to end, cross-checked), entry names and types, declared sizes, then an inflate check (`DecompressionStream`). The rules an app author needs are in `@civitai/blocks-react`'s README under `useSaveImage()`. Dependency-free, browser and Node. |
|
|
37
|
+
| `save-model3d/*` — `looksLikeSaveModel3d`, `isValidSaveModel3d`, `SAVE_MODEL3D_MAX_BYTES`, `SAVE_MODEL3D_MAX_JSON_CHUNK_BYTES`, `SAVE_MODEL3D_EXTENSION`, `SaveModel3dType` | The binary glTF (`.glb`) / binary FBX (`.fbx`) check behind `SAVE_IMAGE { bytes }` — the ONE copy, shared by the civitai.com host and `createMockHost` like `save-zip`. A prefix test that picks the per-file cap (`SAVE_MODEL3D_MAX_BYTES`), then a strict structural check (a GLB's declared length and chunks fill the buffer exactly; an FBX's top-level records reach the null record with at most a footer after it). The rules an app author needs are in `@civitai/blocks-react`'s README under `useSaveImage()`. Dependency-free, browser and Node. |
|
|
37
38
|
|
|
38
39
|
## Entry points, and what the root barrel is
|
|
39
40
|
|
|
40
41
|
The root — `import … from '@civitai/app-sdk'` — is **exactly the union of four subpaths**: `@civitai/app-sdk/oauth`, `/scopes`, `/cookies` and `/orchestrator`. All of each, and nothing else. Import from the root when you want the OAuth-app surface in one specifier; import a subpath when you want only that slice. The two are the same symbols either way, which is asserted in both directions by `test/export-surface.test.ts` — the root cannot quietly gain a symbol none of those four exports, or miss one they do.
|
|
41
42
|
|
|
42
|
-
The other
|
|
43
|
+
The other seven subpaths are **deliberately not on the root**, each for a concrete cost it would push onto every consumer:
|
|
43
44
|
|
|
44
45
|
| Subpath | Why it is not on the root |
|
|
45
46
|
|---|---|
|
|
@@ -49,6 +50,7 @@ The other six subpaths are **deliberately not on the root**, each for a concrete
|
|
|
49
50
|
| `@civitai/app-sdk/manifest` | **Node only** — needs `node:fs` and the optional peer `ajv`. |
|
|
50
51
|
| `@civitai/app-sdk/vite` | **Node only** — optional peers `ajv` (runtime) and `vite` (types). |
|
|
51
52
|
| `@civitai/app-sdk/save-zip` | The host's `SAVE_IMAGE` zip validator, shared by the civitai.com host and `@civitai/blocks-react`'s `createMockHost`. An OAuth app never needs it. |
|
|
53
|
+
| `@civitai/app-sdk/save-model3d` | The host's `SAVE_IMAGE` binary glTF / FBX check, shared the same way. An OAuth app never needs it. |
|
|
52
54
|
|
|
53
55
|
> One name is declared twice on purpose: `BuzzAccountType` is the full set of Civitai Buzz pools on the root and `/oauth`, and a narrower three-pool union on `/blocks` — a block can neither prefer nor read the others. Same name, two subpaths, two types; the divergence is pinned rather than merged.
|
|
54
56
|
|
package/dist/index.d.ts
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
* accident rather than by decision. `./oauth` now re-exports `types.ts`, which
|
|
18
18
|
* fixes it additively: the root's surface did not change.
|
|
19
19
|
*
|
|
20
|
-
* ## The
|
|
20
|
+
* ## The seven subpaths deliberately NOT in the root, and why
|
|
21
21
|
*
|
|
22
22
|
* "Reachable two ways" is a cost, but an absent export is a worse one, so the
|
|
23
23
|
* bar for staying out is a concrete harm to the importer. Each of these clears
|
|
@@ -48,9 +48,11 @@
|
|
|
48
48
|
* - **`./save-zip`** — the host's `SAVE_IMAGE` zip validator, the one copy the
|
|
49
49
|
* civitai.com host and `@civitai/blocks-react`'s `createMockHost` share. An
|
|
50
50
|
* OAuth app never saves a zip through a block host.
|
|
51
|
+
* - **`./save-model3d`** — the host's `SAVE_IMAGE` binary glTF / FBX check,
|
|
52
|
+
* shared the same way and for the same reason.
|
|
51
53
|
*
|
|
52
54
|
* The ledger in `test/export-surface.test.ts` carries one of these reasons per
|
|
53
|
-
* `exports` key and fails when the key set GROWS or SHRINKS — so
|
|
55
|
+
* `exports` key and fails when the key set GROWS or SHRINKS — so an eighth
|
|
54
56
|
* subpath cannot arrive without a stated reason to exist, and a deleted one
|
|
55
57
|
* cannot leave a stale reason behind.
|
|
56
58
|
*
|
package/dist/index.js
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
* accident rather than by decision. `./oauth` now re-exports `types.ts`, which
|
|
18
18
|
* fixes it additively: the root's surface did not change.
|
|
19
19
|
*
|
|
20
|
-
* ## The
|
|
20
|
+
* ## The seven subpaths deliberately NOT in the root, and why
|
|
21
21
|
*
|
|
22
22
|
* "Reachable two ways" is a cost, but an absent export is a worse one, so the
|
|
23
23
|
* bar for staying out is a concrete harm to the importer. Each of these clears
|
|
@@ -48,9 +48,11 @@
|
|
|
48
48
|
* - **`./save-zip`** — the host's `SAVE_IMAGE` zip validator, the one copy the
|
|
49
49
|
* civitai.com host and `@civitai/blocks-react`'s `createMockHost` share. An
|
|
50
50
|
* OAuth app never saves a zip through a block host.
|
|
51
|
+
* - **`./save-model3d`** — the host's `SAVE_IMAGE` binary glTF / FBX check,
|
|
52
|
+
* shared the same way and for the same reason.
|
|
51
53
|
*
|
|
52
54
|
* The ledger in `test/export-surface.test.ts` carries one of these reasons per
|
|
53
|
-
* `exports` key and fails when the key set GROWS or SHRINKS — so
|
|
55
|
+
* `exports` key and fails when the key set GROWS or SHRINKS — so an eighth
|
|
54
56
|
* subpath cannot arrive without a stated reason to exist, and a deleted one
|
|
55
57
|
* cannot leave a stale reason behind.
|
|
56
58
|
*
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@civitai/app-sdk/save-model3d` — the App Blocks `SAVE_IMAGE { bytes }` 3D model check: binary
|
|
3
|
+
* glTF (`.glb`) and binary FBX (`.fbx`).
|
|
4
|
+
*
|
|
5
|
+
* 🔴 THE ONE COPY, like `./save-zip`. The civitai.com host and `@civitai/blocks-react`'s
|
|
6
|
+
* `createMockHost` both import this module, so the mock accepts and refuses exactly the models
|
|
7
|
+
* production does. Change the rules here, release, and bump the host's `@civitai/app-sdk`.
|
|
8
|
+
*
|
|
9
|
+
* glTF-JSON (`.gltf`), ASCII FBX and OBJ are NOT model types here: they are text, so the host saves
|
|
10
|
+
* them as `.txt` (and a `.gltf` usually references sidecar files a single save could not carry).
|
|
11
|
+
*
|
|
12
|
+
* Two steps, the same split as the zip rules:
|
|
13
|
+
* 1. {@link looksLikeSaveModel3d} — does the buffer START like one of these? Decided on the first
|
|
14
|
+
* 8 (GLB) or 21 (FBX) bytes, so a caller can pick the per-file cap
|
|
15
|
+
* ({@link SAVE_MODEL3D_MAX_BYTES}) before decoding anything. Both prefixes contain a NUL byte,
|
|
16
|
+
* so no text payload can ever be a candidate: refusing a candidate that fails step 2 takes
|
|
17
|
+
* nothing away from a text classifier that refuses every NUL-bearing buffer.
|
|
18
|
+
* 2. {@link isValidSaveModel3d} — the strict structural check. A GLB must account for EVERY byte
|
|
19
|
+
* of the buffer in its declared chunks (nothing can ride along after it); an FBX must have a
|
|
20
|
+
* well-formed run of top-level node records ending in the null record, with no more than a
|
|
21
|
+
* footer's worth of bytes after it.
|
|
22
|
+
*
|
|
23
|
+
* Dependency-free, browser and Node.
|
|
24
|
+
*/
|
|
25
|
+
/** The two 3D model types, each with the one extension (no dot) it saves under. */
|
|
26
|
+
export declare const SAVE_MODEL3D_EXTENSION: {
|
|
27
|
+
readonly 'model/gltf-binary': "glb";
|
|
28
|
+
readonly 'model/x-fbx': "fbx";
|
|
29
|
+
};
|
|
30
|
+
export type SaveModel3dType = keyof typeof SAVE_MODEL3D_EXTENSION;
|
|
31
|
+
/**
|
|
32
|
+
* The per-file cap on a buffer that starts like a model: 100 MiB. Generated meshes with embedded
|
|
33
|
+
* textures outgrow the 50 MiB cap of the other bytes types; the host also checks a model against
|
|
34
|
+
* its 100 MiB window budget, so a model at the cap is the only save that window admits.
|
|
35
|
+
*/
|
|
36
|
+
export declare const SAVE_MODEL3D_MAX_BYTES: number;
|
|
37
|
+
/**
|
|
38
|
+
* The largest JSON chunk a GLB may carry: 8 MiB. The check decodes and parses that chunk on the
|
|
39
|
+
* caller's thread (the host's is the viewer's main thread), and parse cost grows with it: a 49.5 MB
|
|
40
|
+
* chunk measured 2.6 s and 1.8 GB on node 24, a 99 MB one 7 s and 3.4 GB. Real GLB JSON is the
|
|
41
|
+
* scene description only — node, mesh, accessor and material records; the geometry and textures
|
|
42
|
+
* live in the BIN chunk — so it runs from a few KB to a few MB even for large scenes. 8 MiB leaves
|
|
43
|
+
* room above that while bounding the parse to a fraction of a second. Over it, the file is refused
|
|
44
|
+
* like any other GLB that fails the check, before anything is decoded.
|
|
45
|
+
*/
|
|
46
|
+
export declare const SAVE_MODEL3D_MAX_JSON_CHUNK_BYTES: number;
|
|
47
|
+
/**
|
|
48
|
+
* Which model type the buffer STARTS like (`glTF` + version 2, or the binary FBX magic), or `null`.
|
|
49
|
+
* Reads at most the first 21 bytes. Not a validation: see {@link isValidSaveModel3d}.
|
|
50
|
+
*/
|
|
51
|
+
export declare function looksLikeSaveModel3d(view: Uint8Array): SaveModel3dType | null;
|
|
52
|
+
/** Strict structural check of a buffer that {@link looksLikeSaveModel3d} called `type`. */
|
|
53
|
+
export declare function isValidSaveModel3d(view: Uint8Array, type: SaveModel3dType): boolean;
|
|
54
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@civitai/app-sdk/save-model3d` — the App Blocks `SAVE_IMAGE { bytes }` 3D model check: binary
|
|
3
|
+
* glTF (`.glb`) and binary FBX (`.fbx`).
|
|
4
|
+
*
|
|
5
|
+
* 🔴 THE ONE COPY, like `./save-zip`. The civitai.com host and `@civitai/blocks-react`'s
|
|
6
|
+
* `createMockHost` both import this module, so the mock accepts and refuses exactly the models
|
|
7
|
+
* production does. Change the rules here, release, and bump the host's `@civitai/app-sdk`.
|
|
8
|
+
*
|
|
9
|
+
* glTF-JSON (`.gltf`), ASCII FBX and OBJ are NOT model types here: they are text, so the host saves
|
|
10
|
+
* them as `.txt` (and a `.gltf` usually references sidecar files a single save could not carry).
|
|
11
|
+
*
|
|
12
|
+
* Two steps, the same split as the zip rules:
|
|
13
|
+
* 1. {@link looksLikeSaveModel3d} — does the buffer START like one of these? Decided on the first
|
|
14
|
+
* 8 (GLB) or 21 (FBX) bytes, so a caller can pick the per-file cap
|
|
15
|
+
* ({@link SAVE_MODEL3D_MAX_BYTES}) before decoding anything. Both prefixes contain a NUL byte,
|
|
16
|
+
* so no text payload can ever be a candidate: refusing a candidate that fails step 2 takes
|
|
17
|
+
* nothing away from a text classifier that refuses every NUL-bearing buffer.
|
|
18
|
+
* 2. {@link isValidSaveModel3d} — the strict structural check. A GLB must account for EVERY byte
|
|
19
|
+
* of the buffer in its declared chunks (nothing can ride along after it); an FBX must have a
|
|
20
|
+
* well-formed run of top-level node records ending in the null record, with no more than a
|
|
21
|
+
* footer's worth of bytes after it.
|
|
22
|
+
*
|
|
23
|
+
* Dependency-free, browser and Node.
|
|
24
|
+
*/
|
|
25
|
+
/** The two 3D model types, each with the one extension (no dot) it saves under. */
|
|
26
|
+
export const SAVE_MODEL3D_EXTENSION = {
|
|
27
|
+
// IANA-registered.
|
|
28
|
+
'model/gltf-binary': 'glb',
|
|
29
|
+
// FBX has no registered media type; this names it for the Blob without claiming a registration.
|
|
30
|
+
'model/x-fbx': 'fbx',
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* The per-file cap on a buffer that starts like a model: 100 MiB. Generated meshes with embedded
|
|
34
|
+
* textures outgrow the 50 MiB cap of the other bytes types; the host also checks a model against
|
|
35
|
+
* its 100 MiB window budget, so a model at the cap is the only save that window admits.
|
|
36
|
+
*/
|
|
37
|
+
export const SAVE_MODEL3D_MAX_BYTES = 100 * 1024 * 1024;
|
|
38
|
+
/**
|
|
39
|
+
* The largest JSON chunk a GLB may carry: 8 MiB. The check decodes and parses that chunk on the
|
|
40
|
+
* caller's thread (the host's is the viewer's main thread), and parse cost grows with it: a 49.5 MB
|
|
41
|
+
* chunk measured 2.6 s and 1.8 GB on node 24, a 99 MB one 7 s and 3.4 GB. Real GLB JSON is the
|
|
42
|
+
* scene description only — node, mesh, accessor and material records; the geometry and textures
|
|
43
|
+
* live in the BIN chunk — so it runs from a few KB to a few MB even for large scenes. 8 MiB leaves
|
|
44
|
+
* room above that while bounding the parse to a fraction of a second. Over it, the file is refused
|
|
45
|
+
* like any other GLB that fails the check, before anything is decoded.
|
|
46
|
+
*/
|
|
47
|
+
export const SAVE_MODEL3D_MAX_JSON_CHUNK_BYTES = 8 * 1024 * 1024;
|
|
48
|
+
/** `glTF` + container version 2 (little-endian u32). */
|
|
49
|
+
const GLB_PREFIX = [0x67, 0x6c, 0x54, 0x46, 0x02, 0x00, 0x00, 0x00];
|
|
50
|
+
const GLB_HEADER_BYTES = 12;
|
|
51
|
+
const GLB_CHUNK_HEADER_BYTES = 8;
|
|
52
|
+
const GLB_CHUNK_JSON = 0x4e4f534a; // "JSON" read as a little-endian u32
|
|
53
|
+
const GLB_CHUNK_BIN = 0x004e4942; // "BIN\0" read as a little-endian u32
|
|
54
|
+
/** `Kaydara FBX Binary` + two spaces + NUL: the binary FBX magic. ASCII FBX starts with `; FBX`. */
|
|
55
|
+
const FBX_MAGIC = [
|
|
56
|
+
0x4b, 0x61, 0x79, 0x64, 0x61, 0x72, 0x61, 0x20, 0x46, 0x42, 0x58, 0x20, 0x42, 0x69, 0x6e, 0x61,
|
|
57
|
+
0x72, 0x79, 0x20, 0x20, 0x00,
|
|
58
|
+
];
|
|
59
|
+
/** Magic, then `0x1A 0x00`, then the u32 version. */
|
|
60
|
+
const FBX_HEADER_BYTES = 27;
|
|
61
|
+
/**
|
|
62
|
+
* The version range accepted: from 6100 (FBX 2006, the oldest binary writers emit) to 7999. The
|
|
63
|
+
* newest version in use is 7700 (FBX 2020); the bound admits any later 7.x so a newer writer of the
|
|
64
|
+
* same record format is not refused. An 8.x would be a new format and is refused.
|
|
65
|
+
*/
|
|
66
|
+
const FBX_MIN_VERSION = 6100;
|
|
67
|
+
const FBX_MAX_VERSION = 7999;
|
|
68
|
+
/** From 7500 a node record's three leading fields are u64 instead of u32. */
|
|
69
|
+
const FBX_WIDE_RECORD_VERSION = 7500;
|
|
70
|
+
/**
|
|
71
|
+
* The most bytes allowed after the top-level null record. The footer writers emit is 160 bytes
|
|
72
|
+
* plus up to 15 of alignment padding; 256 leaves room for a writer that differs, and still means
|
|
73
|
+
* no second file of any size can follow the node data.
|
|
74
|
+
*/
|
|
75
|
+
const FBX_MAX_TAIL_BYTES = 256;
|
|
76
|
+
function startsWith(u8, sig) {
|
|
77
|
+
if (u8.length < sig.length)
|
|
78
|
+
return false;
|
|
79
|
+
for (let i = 0; i < sig.length; i++)
|
|
80
|
+
if (u8[i] !== sig[i])
|
|
81
|
+
return false;
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Which model type the buffer STARTS like (`glTF` + version 2, or the binary FBX magic), or `null`.
|
|
86
|
+
* Reads at most the first 21 bytes. Not a validation: see {@link isValidSaveModel3d}.
|
|
87
|
+
*/
|
|
88
|
+
export function looksLikeSaveModel3d(view) {
|
|
89
|
+
if (startsWith(view, GLB_PREFIX))
|
|
90
|
+
return 'model/gltf-binary';
|
|
91
|
+
if (startsWith(view, FBX_MAGIC))
|
|
92
|
+
return 'model/x-fbx';
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
/** Strict structural check of a buffer that {@link looksLikeSaveModel3d} called `type`. */
|
|
96
|
+
export function isValidSaveModel3d(view, type) {
|
|
97
|
+
return type === 'model/gltf-binary' ? isValidGlb(view) : isValidFbx(view);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* glTF 2.0 binary container (spec §4.4): a 12-byte header whose declared length equals the
|
|
101
|
+
* buffer's, then chunks. The JSON chunk comes first and only first; a BIN chunk, if any, only
|
|
102
|
+
* second; chunks of any other type are allowed after the JSON chunk, because the spec says
|
|
103
|
+
* "Client implementations MUST ignore chunks with unknown types to enable glTF extensions to
|
|
104
|
+
* reference additional chunks with new types following the first two chunks." Every chunk length
|
|
105
|
+
* is a multiple of 4 (the spec's alignment rule), every chunk lies inside the declared length, and
|
|
106
|
+
* the chunks end exactly at it. The JSON chunk must be at most
|
|
107
|
+
* {@link SAVE_MODEL3D_MAX_JSON_CHUNK_BYTES} (checked before it is decoded) and UTF-8 that parses to
|
|
108
|
+
* an object carrying `asset.version`, the one property glTF requires.
|
|
109
|
+
*/
|
|
110
|
+
function isValidGlb(u8) {
|
|
111
|
+
if (u8.length < GLB_HEADER_BYTES + GLB_CHUNK_HEADER_BYTES)
|
|
112
|
+
return false;
|
|
113
|
+
if (!startsWith(u8, GLB_PREFIX))
|
|
114
|
+
return false;
|
|
115
|
+
const view = new DataView(u8.buffer, u8.byteOffset, u8.byteLength);
|
|
116
|
+
const length = view.getUint32(8, true);
|
|
117
|
+
if (length !== u8.length || length % 4 !== 0)
|
|
118
|
+
return false;
|
|
119
|
+
let offset = GLB_HEADER_BYTES;
|
|
120
|
+
let index = 0;
|
|
121
|
+
while (offset < length) {
|
|
122
|
+
if (length - offset < GLB_CHUNK_HEADER_BYTES)
|
|
123
|
+
return false;
|
|
124
|
+
const chunkLength = view.getUint32(offset, true);
|
|
125
|
+
const chunkType = view.getUint32(offset + 4, true);
|
|
126
|
+
const dataStart = offset + GLB_CHUNK_HEADER_BYTES;
|
|
127
|
+
if (chunkLength % 4 !== 0 || chunkLength > length - dataStart)
|
|
128
|
+
return false;
|
|
129
|
+
if (index === 0) {
|
|
130
|
+
if (chunkType !== GLB_CHUNK_JSON || chunkLength === 0)
|
|
131
|
+
return false;
|
|
132
|
+
if (chunkLength > SAVE_MODEL3D_MAX_JSON_CHUNK_BYTES)
|
|
133
|
+
return false;
|
|
134
|
+
if (!isGltfJson(u8.subarray(dataStart, dataStart + chunkLength)))
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
else if (chunkType === GLB_CHUNK_JSON || (chunkType === GLB_CHUNK_BIN && index !== 1)) {
|
|
138
|
+
// A second JSON chunk, or a BIN chunk anywhere but second: out of the spec's order.
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
// Every chunk header is 8 bytes, so each pass moves forward and the walk terminates.
|
|
142
|
+
offset = dataStart + chunkLength;
|
|
143
|
+
index += 1;
|
|
144
|
+
}
|
|
145
|
+
return index >= 1 && offset === length;
|
|
146
|
+
}
|
|
147
|
+
function isGltfJson(bytes) {
|
|
148
|
+
let doc;
|
|
149
|
+
try {
|
|
150
|
+
doc = JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(bytes));
|
|
151
|
+
}
|
|
152
|
+
catch {
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
if (!doc || typeof doc !== 'object' || Array.isArray(doc))
|
|
156
|
+
return false;
|
|
157
|
+
const asset = doc.asset;
|
|
158
|
+
if (!asset || typeof asset !== 'object' || Array.isArray(asset))
|
|
159
|
+
return false;
|
|
160
|
+
return typeof asset.version === 'string';
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Binary FBX: the magic, `0x1A 0x00`, a version from 6100 to 7999, then a walk of the TOP-LEVEL
|
|
164
|
+
* node records. Each record's end offset must lie at or past the end of its own header and name
|
|
165
|
+
* (so the walk moves strictly forward) and stay inside the buffer, its name must be printable
|
|
166
|
+
* ASCII, and the walk must reach the all-zero null record with at least one node before it. At most
|
|
167
|
+
* {@link FBX_MAX_TAIL_BYTES} may follow the null record (the footer). Nested records are not
|
|
168
|
+
* walked: they lie inside a top-level record's span, which the walk has already bounded.
|
|
169
|
+
*/
|
|
170
|
+
function isValidFbx(u8) {
|
|
171
|
+
if (u8.length < FBX_HEADER_BYTES)
|
|
172
|
+
return false;
|
|
173
|
+
if (!startsWith(u8, FBX_MAGIC) || u8[21] !== 0x1a || u8[22] !== 0x00)
|
|
174
|
+
return false;
|
|
175
|
+
const view = new DataView(u8.buffer, u8.byteOffset, u8.byteLength);
|
|
176
|
+
const version = view.getUint32(23, true);
|
|
177
|
+
if (version < FBX_MIN_VERSION || version > FBX_MAX_VERSION)
|
|
178
|
+
return false;
|
|
179
|
+
const wide = version >= FBX_WIDE_RECORD_VERSION;
|
|
180
|
+
const fieldBytes = wide ? 8 : 4;
|
|
181
|
+
const recordHeaderBytes = fieldBytes * 3 + 1;
|
|
182
|
+
const readField = (at) => wide ? Number(view.getBigUint64(at, true)) : view.getUint32(at, true);
|
|
183
|
+
let offset = FBX_HEADER_BYTES;
|
|
184
|
+
let nodes = 0;
|
|
185
|
+
for (;;) {
|
|
186
|
+
if (u8.length - offset < recordHeaderBytes)
|
|
187
|
+
return false;
|
|
188
|
+
const endOffset = readField(offset);
|
|
189
|
+
const numProperties = readField(offset + fieldBytes);
|
|
190
|
+
const propertyListLength = readField(offset + fieldBytes * 2);
|
|
191
|
+
const nameLength = u8[offset + fieldBytes * 3];
|
|
192
|
+
if (endOffset === 0) {
|
|
193
|
+
// The null record: every field zero. Ends the top-level list.
|
|
194
|
+
if (numProperties !== 0 || propertyListLength !== 0 || nameLength !== 0)
|
|
195
|
+
return false;
|
|
196
|
+
const tail = u8.length - (offset + recordHeaderBytes);
|
|
197
|
+
return nodes > 0 && tail <= FBX_MAX_TAIL_BYTES;
|
|
198
|
+
}
|
|
199
|
+
const nameStart = offset + recordHeaderBytes;
|
|
200
|
+
const bodyStart = nameStart + nameLength;
|
|
201
|
+
// A node with no properties and no children ends right after its name; nameLength >= 1 keeps
|
|
202
|
+
// every step strictly forward, so the walk terminates.
|
|
203
|
+
if (nameLength === 0 || endOffset < bodyStart || endOffset > u8.length)
|
|
204
|
+
return false;
|
|
205
|
+
if (propertyListLength > endOffset - bodyStart)
|
|
206
|
+
return false;
|
|
207
|
+
for (let i = nameStart; i < bodyStart; i++) {
|
|
208
|
+
const c = u8[i];
|
|
209
|
+
if (c < 0x20 || c > 0x7e)
|
|
210
|
+
return false;
|
|
211
|
+
}
|
|
212
|
+
offset = endOffset;
|
|
213
|
+
nodes += 1;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
//# sourceMappingURL=index.js.map
|
package/dist/save-zip/index.d.ts
CHANGED
|
@@ -57,7 +57,11 @@ export declare const SAVE_ZIP_LIMITS: {
|
|
|
57
57
|
readonly maxEntryRatio: 100;
|
|
58
58
|
readonly ratioFloorBytes: number;
|
|
59
59
|
};
|
|
60
|
-
/**
|
|
60
|
+
/**
|
|
61
|
+
* Entry extensions a zip may contain (lowercase, after the last `.`). Directories need none. `glb`
|
|
62
|
+
* (binary glTF) and `fbx` are 3D model files, so a block can bundle a generated model with its
|
|
63
|
+
* renders; like every entry, only the name is checked, not the content.
|
|
64
|
+
*/
|
|
61
65
|
export declare const SAVE_ZIP_ALLOWED_EXTENSIONS: ReadonlySet<string>;
|
|
62
66
|
export declare const SAVE_ZIP_NO_EOCD_ERROR = "zip end of central directory not found (archive comments are not allowed)";
|
|
63
67
|
export declare const SAVE_ZIP_MULTIDISK_ERROR = "zip spans multiple disks";
|
package/dist/save-zip/index.js
CHANGED
|
@@ -57,7 +57,11 @@ export const SAVE_ZIP_LIMITS = {
|
|
|
57
57
|
maxEntryRatio: 100,
|
|
58
58
|
ratioFloorBytes: 1024 * 1024,
|
|
59
59
|
};
|
|
60
|
-
/**
|
|
60
|
+
/**
|
|
61
|
+
* Entry extensions a zip may contain (lowercase, after the last `.`). Directories need none. `glb`
|
|
62
|
+
* (binary glTF) and `fbx` are 3D model files, so a block can bundle a generated model with its
|
|
63
|
+
* renders; like every entry, only the name is checked, not the content.
|
|
64
|
+
*/
|
|
61
65
|
export const SAVE_ZIP_ALLOWED_EXTENSIONS = new Set([
|
|
62
66
|
'png',
|
|
63
67
|
'jpg',
|
|
@@ -66,6 +70,8 @@ export const SAVE_ZIP_ALLOWED_EXTENSIONS = new Set([
|
|
|
66
70
|
'txt',
|
|
67
71
|
'json',
|
|
68
72
|
'csv',
|
|
73
|
+
'glb',
|
|
74
|
+
'fbx',
|
|
69
75
|
]);
|
|
70
76
|
export const SAVE_ZIP_NO_EOCD_ERROR = 'zip end of central directory not found (archive comments are not allowed)';
|
|
71
77
|
export const SAVE_ZIP_MULTIDISK_ERROR = 'zip spans multiple disks';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@civitai/app-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.93.0",
|
|
4
4
|
"description": "OAuth + PKCE, encrypted-cookie sessions, scopes, and orchestrator helpers for building third-party Civitai apps.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -55,6 +55,10 @@
|
|
|
55
55
|
"types": "./dist/save-zip/index.d.ts",
|
|
56
56
|
"import": "./dist/save-zip/index.js"
|
|
57
57
|
},
|
|
58
|
+
"./save-model3d": {
|
|
59
|
+
"types": "./dist/save-model3d/index.d.ts",
|
|
60
|
+
"import": "./dist/save-model3d/index.js"
|
|
61
|
+
},
|
|
58
62
|
"./schemas/app-block/v1.json": "./schemas/app-block/v1.json"
|
|
59
63
|
},
|
|
60
64
|
"comment-packaging": "`!dist/**/*.map` keeps dangling sourcemaps out of the tarball (#376). Rationale: scripts/check-shipped-sourcemaps.mjs.",
|