forked from 1b-agent/opencadstudio-upstream
Web control: open a drawing from bytes
On the web build, {"op":"open","path":…} resolves the name against the
browser's recent-files cache, so a file that is not already there cannot be
opened by the control channel. Accept {"op":"open","name":…,
"data_base64":…} instead: the bytes go through the same parse, caching
and recovery path as a file chosen in the browser picker
(io::open_bytes_web, now shared with pick_and_load_web).
Native builds keep path-based open and reject data_base64 with
invalid_request.
Refs #1349
This commit is contained in:
3 files changed
+124
-19
No files matched your search
@@ -526,6 +526,18 @@ pub async fn pick_and_load_web(
|
||||
let name = handle.file_name();
|
||||
progress.set(crate::app::OPEN_PHASE_READING, 500, 1, 2);
|
||||
let bytes: Arc<[u8]> = Arc::from(handle.read().await);
|
||||
open_bytes_web(name, bytes, progress).await
|
||||
}
|
||||
|
||||
/// Web file open from bytes the caller already holds (the control channel's
|
||||
/// `open` with `data_base64`). Same parse, caching and recovery handling as a
|
||||
/// file chosen in the browser picker.
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
pub async fn open_bytes_web(
|
||||
name: String,
|
||||
bytes: Arc<[u8]>,
|
||||
progress: Arc<OpenProgressState>,
|
||||
) -> WebOpenOutcome {
|
||||
let size_bytes = bytes.len() as u64;
|
||||
let result = load_web_bytes(&name, &bytes, progress.clone(), false, "", None).await;
|
||||
let keep_for_recovery = result
|
||||
|
||||
Reference in new issue
Block a user