Repository navigation
Send to Slicer: network folder targets, with Format and Quality rows (#2304) #10605
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
quantforge-br
wants to merge
3
commits into
tangency-labs:main
from
quantforge-br:slicer-network-folder
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
fb8a9b9
Send to Slicer: network folder targets for commands (#2304)
quantmind-br 28c2331
Send to Slicer: Format and Quality rows, and a Network folder window …
quantmind-br 734ad81
Docs: Send to Slicer's Format and Quality rows and network folders (#…
quantmind-br File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Large diffs are not rendered by default.
Oops, something went wrong.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| | assets/icons/ui/design/svg/model/network_folder.svg | SolidCraft contributors | original icon master (64 grid) | MIT OR Apache-2.0 | |
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| //! Network folders for Send to Slicer (#2304): add, remove and test the folders a mesh can be | ||
| //! sent to (`crate::remote_slicers`). They are the session's (`Session::network_folders`); the | ||
| //! desktop app stores them in the user's preferences when these commands succeed and puts them back | ||
| //! at the next start. Run without an app (CLI, scripts), a folder lasts as long as the session. | ||
|
|
||
| use serde_json::{Value, json}; | ||
|
|
||
| use super::CommandSpec; | ||
| use crate::params::{bad, str_}; | ||
| use crate::remote_slicers::{self, RemoteTarget}; | ||
| use crate::schema::file_remote::{AddRemoteParams, RemoteFolderReply, RemoveRemoteParams, RemoveRemoteReply, TestRemoteParams, TestRemoteReply}; | ||
| use crate::schema::{TypedContract, output_schema_for}; | ||
| use crate::{Result, Session}; | ||
|
|
||
| pub static COMMANDS: &[CommandSpec] = &[ | ||
| CommandSpec::new("file.slicers.add_remote", "Add Network Folder", crate::checked!("file.slicers.add_remote", add_remote)) | ||
| .icon("network_folder") | ||
| .noundo() | ||
| .doc_only() | ||
| .enabled(reaches_folders) | ||
| .contract(&ADD_CONTRACT) | ||
| .output(output_schema_for::<RemoteFolderReply>) | ||
| .params("name: 1..64 characters (shown in the Send to Slicer list); folder: the folder's whole path, such as a mounted SMB or NFS share that a slicer on another computer reads → {id: remote:<name>, name, kind: folder, folder, replaced}: adds a network folder to Send to Slicer, replacing one of the same name. Nothing is written until a mesh is sent; file.slicers.test checks the folder. The app keeps it in the user's preferences; without an app it lasts as long as the session"), | ||
| CommandSpec::new("file.slicers.remove_remote", "Remove Network Folder", crate::checked!("file.slicers.remove_remote", remove_remote)) | ||
| .icon("delete") | ||
| .noundo() | ||
| .doc_only() | ||
| .enabled(reaches_folders) | ||
| .contract(&REMOVE_CONTRACT) | ||
| .output(output_schema_for::<RemoveRemoteReply>) | ||
| .params("name: a network folder's name or id (file.slicers) → {name, removed: true}; the files sent there stay"), | ||
| CommandSpec::new("file.slicers.test", "Test Network Folder", crate::checked!("file.slicers.test", test)) | ||
| .icon("inspect") | ||
| .noundo() | ||
| .doc_only() | ||
| .enabled(reaches_folders) | ||
| .contract(&TEST_CONTRACT) | ||
| .output(output_schema_for::<TestRemoteReply>) | ||
| .params("name?: a network folder's name or id, or folder?: a folder's whole path (one of the two) → {ok, folder, name?, error?}: writes a small file in the folder and deletes it again, giving up after 30 s; error says what went wrong (not there, no permission, full, no answer)"), | ||
| ]; | ||
|
|
||
| const ADD_CONTRACT: TypedContract<AddRemoteParams> = TypedContract::new(); | ||
| const REMOVE_CONTRACT: TypedContract<RemoveRemoteParams> = TypedContract::new(); | ||
| const TEST_CONTRACT: TypedContract<TestRemoteParams> = TypedContract::new(); | ||
|
|
||
| /// The browser build has no folders to write to. | ||
| fn reaches_folders(_: &Session) -> std::result::Result<(), String> { | ||
| if cfg!(target_arch = "wasm32") { Err("network folders can't be reached from the browser".into()) } else { Ok(()) } | ||
| } | ||
|
|
||
| /// A folder an agent's commands may use: one in the folders it was allowed (`--allow-path`). The | ||
| /// app's own calls have no such limit. | ||
| fn allowed(cmd: &str, folder: &str) -> Result<()> { | ||
| solidcraft_io::vfs::check(folder).map_err(|e| bad(cmd, e.to_string())) | ||
| } | ||
|
|
||
| fn add_remote(s: &mut Session, p: &Value) -> Result<Value> { | ||
| let cmd = "file.slicers.add_remote"; | ||
| reaches_folders(s).map_err(|e| bad(cmd, e))?; | ||
| let name = remote_slicers::check_name(str_(p, "name").unwrap_or_default()).map_err(|e| bad(cmd, e))?; | ||
| let folder = remote_slicers::check_folder(str_(p, "folder").unwrap_or_default()).map_err(|e| bad(cmd, e))?; | ||
| allowed(cmd, folder)?; | ||
| let target = RemoteTarget::folder_target(name, folder); | ||
| let replaced = remote_slicers::add(&mut s.network_folders, target.clone()).map_err(|e| bad(cmd, e))?; | ||
| Ok(json!({"id": target.id(), "name": target.name, "kind": target.kind(), "folder": target.folder(), "replaced": replaced})) | ||
| } | ||
|
|
||
| fn remove_remote(s: &mut Session, p: &Value) -> Result<Value> { | ||
| let cmd = "file.slicers.remove_remote"; | ||
| reaches_folders(s).map_err(|e| bad(cmd, e))?; | ||
| let spec = str_(p, "name").filter(|n| !n.trim().is_empty()).ok_or_else(|| bad(cmd, "give `name` (see file.slicers)"))?; | ||
| let gone = | ||
| remote_slicers::remove(&mut s.network_folders, spec).ok_or_else(|| bad(cmd, format!("no network folder `{spec}` (see file.slicers)")))?; | ||
| Ok(json!({"name": gone.name, "removed": true})) | ||
| } | ||
|
|
||
| fn test(s: &mut Session, p: &Value) -> Result<Value> { | ||
| let cmd = "file.slicers.test"; | ||
| reaches_folders(s).map_err(|e| bad(cmd, e))?; | ||
| let (name, folder) = match (str_(p, "name"), str_(p, "folder")) { | ||
| (Some(spec), None) => { | ||
| let target = remote_slicers::resolve(&s.network_folders, spec) | ||
| .ok_or_else(|| bad(cmd, format!("no network folder `{spec}` (see file.slicers)")))?; | ||
| if let Some(folder) = target.on_this_computer() { | ||
| allowed(cmd, folder)?; | ||
| } | ||
| (Some(target.name.clone()), target.folder().to_string()) | ||
| } | ||
| (None, Some(folder)) => { | ||
| let folder = remote_slicers::check_folder(folder).map_err(|e| bad(cmd, e))?; | ||
| allowed(cmd, folder)?; | ||
| (None, folder.to_string()) | ||
| } | ||
| _ => return Err(bad(cmd, "give `name` or `folder`, one of the two")), | ||
| }; | ||
| let mut out = json!({"ok": true, "folder": folder}); | ||
| if let Some(name) = name { | ||
| out["name"] = json!(name); | ||
| } | ||
| if let Err(e) = remote_slicers::probe(&folder) { | ||
| out["ok"] = json!(false); | ||
| out["error"] = json!(e); | ||
| } | ||
| Ok(out) | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.