Skip to content

Add /import?src=<url>: a hand-off point for scanning apps - #720

Open
alxbouchard wants to merge 7 commits into
pascalorg:mainfrom
alxbouchard:import-from-url
Open

Add /import?src=<url>: a hand-off point for scanning apps#720
alxbouchard wants to merge 7 commits into
pascalorg:mainfrom
alxbouchard:import-from-url

Conversation

@alxbouchard

@alxbouchard alxbouchard commented Aug 25, 2026

Copy link
Copy Markdown

What

A new /import?src=<https-url>[&name=<scene name>] page: an external tool — in our case an iOS LiDAR scanning app — hosts a build JSON at a URL and opens this page; the visitor reviews what the file contains and imports it as a new scene with one click.

Until now the only way to get a generated scene into the editor was dragging a file onto Load Build, which does not exist on mobile. With this page, any scan app can end its export flow with "Open in Pascal Editor".

How it works

  • The fetch happens client-side in the visitor's browser — the same trust model as dropping a file on Load Build. The host must allow CORS; no server ever fetches the URL, so there is no SSRF surface.
  • The file runs through the same validateBuildJson pre-flight as Load Build, and the page shows the node counts, floor area, warnings and errors before anything happens.
  • Only an explicit click creates the scene, through the regular POST /api/scenes route — so auth, origin checks and apiGraphSchema validation (including the AssetUrl allowlist) all apply unchanged.
  • src accepts https only (http for localhost during development), rejects embedded credentials, and caps the document at 25 MB. URL validation lives in lib/import-src.ts with unit tests.

Tested

  • bun test lib: 41 pass (6 new)
  • bun run check-types, biome check: clean
  • End to end against a real scan: a RoomPlan-captured apartment (31 walls, 27 items, slab, scene materials) served from a CORS-enabled URL → review page → one click → scene opens in the editor with furniture and per-item slot materials rendering correctly.

Why we built it

We build A3 Atlas Scanner, an iOS field tool that captures homes with RoomPlan and already exports your {nodes, rootNodeIds, materials} graph (catalog items scaled to measured dimensions, measured colors as scene materials, IFC alongside). This page is the missing link that turns every scan into a one-tap Pascal scene. Happy to adjust anything to fit the project's conventions.

🤖 Generated with Claude Code


Note

Medium Risk
New user-controlled URL fetch in the browser (mitigated by scheme/credential checks and no server-side fetch) plus scene creation through the existing authenticated API; materials validation changes affect all build JSON imports.

Overview
Adds /import?src=<url>[&name=…] so external tools (e.g. mobile scan apps) can hand off a CORS-hosted build JSON without Load Build’s file drop. The browser fetches and size-checks the file (10 MB cap, byte-accurate via Blob), runs validateBuildJson, shows stats/errors/warnings and an editable scene name, then creates a scene only on confirm via existing POST /api/scenes (with abort/cancel handling, double-submit guard, and retry on create failure).

parseImportSrc restricts src to absolute https (http on localhost only), blocks credentials and bad schemes, with unit tests.

validateBuildJson now preserves top-level materials on successful parse (invalid entries warned and skipped). Load Build in settings passes materials into setScene so scene:<id> slot refs keep custom finishes.

Reviewed by Cursor Bugbot for commit f30fc5e. Bugbot is set up for automated code reviews on this repo. Configure here.

A scanning app (or any external tool) can now open
editor.pascal.app/import?src=<https-url> to hand a build JSON to the
editor. The fetch happens client-side in the visitor's browser (same
trust model as dropping a file on Load Build; the host must allow
CORS), the file runs through the same validateBuildJson pre-flight,
the visitor reviews the contents, and only an explicit click creates
the scene through the regular POST /api/scenes route — so auth,
origin checks and apiGraphSchema validation all apply unchanged.

src accepts https only (http for localhost during development), no
embedded credentials, 25 MB cap. Unit tests for the URL validation.
Comment thread apps/editor/app/import/import-client.tsx Outdated
Comment thread apps/editor/app/import/import-client.tsx
Comment thread apps/editor/app/import/import-client.tsx
validateBuildJson dropped the top-level materials table: every
scene:<id> slot ref in an imported file pointed at a material that no
longer existed, so custom finishes silently reverted to defaults on
both Load Build and /import. ParsedBuildJson now carries materials —
each entry SceneMaterial-validated individually, invalid ones skipped
with a warning so a bad material never takes the import down — and
handleConfirmImport hands them to setScene, whose extra.materials
support already existed. Unit tests for valid, partially-invalid and
non-object materials.
@alxbouchard

Copy link
Copy Markdown
Author

Follow-up commit: while testing the import end to end I found that validateBuildJson drops the top-level materials table, so every scene:<id> slot ref in an imported file pointed at a material that no longer existed — custom finishes silently reverted to defaults on the existing Load Build path too, not just on this new page. The second commit carries materials through ParsedBuildJson (each entry validated individually, invalid ones skipped with a warning) and hands them to setScene, which already supported them. Covered by unit tests; verified visually with a scan whose furniture uses per-item scene materials.

Comment thread apps/editor/lib/import-src.ts Outdated
Review feedback (Bugbot): a superseded or aborted fetch could
overwrite a newer state — including surfacing the cleanup abort as a
CORS error — and a src change left the previous review (and its
Import button) live against the old file. The effect now resets to
'fetching' on every src change and every state update from a
cancelled run is ignored.
@alxbouchard

Copy link
Copy Markdown
Author

Addressed the Bugbot review (it ran against the first commit, 53b688c):

  • Import drops scene materials — this was real, and deeper than the new page: validateBuildJson dropped the top-level materials table for the existing Load Build path too. Fixed in 81715bc (materials carried through ParsedBuildJson, entries validated individually, handed to setScene).
  • Aborted fetch shown as CORS / stale review across src changes — both fixed in the latest commit: the effect resets to fetching on every src change, and a cancelled run can no longer overwrite newer state or surface its abort as an error.

Review feedback (Bugbot): MAX_IMPORT_BYTES was 25 MB while the sqlite
scene store rejects graphs over DEFAULT_MAX_SCENE_BYTES (10 MB) — a
file could pass review then fail POST /api/scenes with a 413 shown as
a generic error. The cap now matches the store's limit, and a 413 gets
its own explanation.
@alxbouchard

Copy link
Copy Markdown
Author

Third Bugbot point addressed: MAX_IMPORT_BYTES now matches the scene store's 10 MB limit (DEFAULT_MAX_SCENE_BYTES) so a file can't pass review and then 413 on create — and a 413 now gets its own message instead of the generic failure.

Comment thread apps/editor/app/import/import-client.tsx
Review feedback (Bugbot): a second tap on Import could fire before
React re-rendered into 'creating', creating two scenes and racing the
redirect. A synchronous useRef guard now blocks re-entry; it is
released in a finally so a failed create can be retried.
@alxbouchard

Copy link
Copy Markdown
Author

Double-tap point addressed: a synchronous useRef guard now blocks re-entry into the create call (released in a finally so a failed create can be retried) — the state-based check alone could indeed race the re-render, especially on the mobile hand-off this page exists for.

Comment thread apps/editor/app/import/import-client.tsx
Review feedback (Bugbot): a failed POST switched to the error phase,
unmounting the review and the validated graph — nothing left to retry,
and refreshing re-fetches a src URL that may be short-lived. A create
failure now stays in the review phase with the error shown inline and
the button relabelled 'Try again'.
@alxbouchard

Copy link
Copy Markdown
Author

Fifth point addressed: a failed create no longer unmounts the review — the validated graph stays on screen with the error shown inline and the button relabelled "Try again", so a short-lived src URL never has to be re-fetched just to retry.

@Aymericr Aymericr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this, and genuinely thanks for how you've handled the review rounds — the escalation from "import drops materials" to "validateBuildJson drops materials on the Load Build path too" is a real bug you found for us, and it's the strongest part of the PR. I confirmed it at main: handleConfirmImport passes only installedPlugins to setScene.

A few things before this can land.

One blocker: apps/editor/lib/import-src.test.ts imports from vitest, but vitest isn't a dependency anywhere in the repo, and every other test under apps/editor/lib/ uses bun:test (apps/editor's test script is bun test lib). That file can't resolve its imports, so the "41 pass" in the description can't have run. Please switch it to bun:test and re-run.

Then:

  • The size cap uses text.length, which is UTF-16 code units, not bytes — a graph with non-ASCII names can pass review and still 413 at the store, which is the thing the 10 MB alignment commit was for. new Blob([text]).size covers it.
  • validateBuildJson now stores SceneMaterial.safeParse().data, so it injects defaults and drops unknown keys. apps/editor/lib/graph-schema.ts deliberately does the opposite for exactly that reason (there's a comment). I'm fine with normalizing on a client-side import, but let's make it an explicit choice.
  • In the settings panel, the param is widened to Record<string, unknown> and then cast back. ParsedBuildJson is the right type now — please use it directly.
  • Please drop the bun.lock changes; the added sha512 hashes on the github: deps are a bun regeneration artifact, not part of this change.

On scope: I'd like to take the materials fix on its own, because it fixes a live bug on Load Build and shouldn't wait on the rest. Would you split it into a separate PR? I'll merge that quickly.

On the import page itself, one thing to sort out first. editor.pascal.app is a separate hosted app from apps/editor, so this page would only ship on the standalone editor, not the hosted one. And we just landed @pascal-app/capture-protocol (#713), which is the versioned, extensible hand-off format for exactly this use case — manifests, locators, capture sources. I don't think these are the same thing (yours is an already-converted build graph becoming a new scene; #713 is a capture session rendered as scan layers), and I can see wanting both. But I'd rather we agree on where the seam sits before adding a second entry point. Have a look at wiki/architecture/capture-runtime.md and tell me whether your tool would be better served by emitting a capture-protocol manifest, or whether the build-JSON path is genuinely the one you need — happy to talk it through.

- import-src.test.ts now imports from bun:test like every other test
  under apps/editor/lib (vitest is not a repo dependency — the bun
  runner shimmed the import, which is why the suite did run, but the
  file was wrong and the description should have said bun test).
- The size cap measures real bytes via Blob, not UTF-16 code units —
  non-ASCII names could otherwise pass review and still 413.
- bun.lock restored to main (the sha512 additions were a bun
  regeneration artifact, not part of this change).

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit f30fc5e. Configure here.

for (const [id, value] of Object.entries(materialsRaw)) {
const result = SceneMaterial.safeParse(value)
if (result.success) {
kept[id] = result.data

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imported materials get schema-rewritten

Medium Severity

Kept materials are stored as the Zod parse output rather than the original entries. That injects MaterialProperties defaults and drops unknown keys, so Load Build and /import can silently change finishes and strip extra palette fields before setScene or POST /api/scenes.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit f30fc5e. Configure here.

cancelled = true
controller.abort()
}
}, [src])

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scene name stays stale across src

Low Severity

sceneName is initialized from the name query once and the fetch effect only depends on src. A new /import?src=…&name=… navigation reuses the client instance, refetches the file, and still keeps the previous name, so the created scene can be labeled incorrectly.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit f30fc5e. Configure here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants