Add an optional local import server for receiving model files from browser-based CAD Packages#15451
Open
JFKingsley wants to merge 6 commits into
Open
Add an optional local import server for receiving model files from browser-based CAD Packages#15451JFKingsley wants to merge 6 commits into
JFKingsley wants to merge 6 commits into
Conversation
This endpoint exists so any external tool can POST a model file (STEP/STL/3MF/OBJ) and have it open in the running PrusaSlicer window - e.g. a browser CAD app's "Send to PrusaSlicer" button, similar to Fusion 360. It reuses the existing Plater::load_files() path (the same one used by single-instance IPC and drag-and-drop): the server thread writes the received bytes to a temp file and hands the path to a callback that marshals onto the GUI thread via CallAfter(). Notes: - Plain HTTP on loopback only. No TLS needed (didn't want to start linking OpenSSL!): callers are served over HTTPS, and browsers permit an HTTPS page to call http://127.0.0.1 (loopback is a "potentially trustworthy" origin). Settings (Preferences > General, both default OFF): - "Enable local import server" - the on/off toggle. - "Require an access key" - when on, requests must present a matching X-Prusa-Token header; a random key is generated into local_import_token on first enable. Configurable via PrusaSlicer.ini: local_import_bind_address (default 127.0.0.1), local_import_server_port, local_import_allowed_origin.
…rusaSlicer into feature/local-import-server
Author
|
Only other note: I've confirmed this builds/runs correctly on macOS Tahoe 26.5, but have not been able to test it on other platforms as of yet - wasn't sure if there was a requirement there! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this does
Adds an optional, off-by-default HTTP endpoint that listens on localhost so an
external tool can POST a model file (STEP/STL/3MF/OBJ) and have it open in the
already-running PrusaSlicer window.
The motivation is a "Send to PrusaSlicer" button for browser-based CAD tools
(Onshape, etc.), similar to what Fusion 360 offers. As a former long-suffering Fusion 360 user currently migrating much of my work to Onshape, this is one of my biggest current frustrations, hence the PR!
I was recently having to debug some issues with the 3DConnexion server interface that proxies SpaceMouse data into Onshape using a similar local REST server interface, so this is where much of the stylistic inspiration comes from in terms of implementation detail.
How it works
The endpoint reuses the existing
Plater::load_files()path; the same one alreadyused by the drag-and-drop interface. The server runs on its own thread. When a file arrives it's written to a temp file and the path is handed to a callback that marshals onto the GUI thread via
CallAfter()before callingload_files(). We make no changes to the import/loading logic itself.Request flow:
Settings
Two checkboxes under Preferences -> Other, both default OFF:
X-Prusa-Tokenheader. A random key is generated intolocal_import_tokenon firstenable, so it's secure without manual setup. You can regenerate and copy the key from within the settings UI.
Advanced options live in
PrusaSlicer.ini:enable_local_import_server0local_import_require_key0X-Prusa-Tokenheaderlocal_import_tokenlocal_import_bind_address127.0.0.1local_import_server_port8126local_import_allowed_originSecurity
0.0.0.0).*.X-Prusa-Token) means you have the ability to add an additional security checkpoint to further restrict any errant browser JS from writing local files without your say-so.is stripped of path components and unsafe characters; it cannot influence where the
file is written. The same name reuses the same temp file so re-sends replace cleanly rather than creating new objects.
importer logic.
Why plain HTTP (no TLS/OpenSSL)
The endpoint is plain HTTP on loopback only. It does not pull in OpenSSL or any TLS
stack (not least as we don't do that at present afaik): the browser pages that call it are themselves served over HTTPS, and browsers already permit an HTTPS page to call
http://127.0.0.1because loopback is a "potentially trustworthy" origin under W3C Secure Contexts. This keeps the change small and avoids touching the dependency graph.Build / opt-out
Gated behind a new CMake option
SLIC3R_LOCAL_IMPORT_SERVER(defaultON).Testing
SLIC3R_LOCAL_IMPORT_SERVER=ON, enable the toggle in Preferences, then:curl http://127.0.0.1:8126/ping
curl -X POST --data-binary @part.step -H 'X-Filename: part.step'
http://127.0.0.1:8126/open
-> the part opens in the running window.
X-Prusa-Tokenis rejected (401); with the key it succeeds.
Notes
PrusaSlicer; that stays in the external sender.
port/origin in the Preferences UI) to match the preferences - I couldn't seem to find much if any docs on requested styles/security preferences here, so entirely up for feedback!
Thanks for all for good work y'all do on PrusaSlicer :)
Jon