fix(web): STEP export no longer panics; STEP/STL exports download in the browser

The STEP header timestamp used SystemTime, which panics on wasm, and the
exports wrote through std::fs, which the browser does not have.

Fixes #761

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Hakan SevenandClaude Opus 5.5 committed 2026-09-28 19:18:53 +03:00
1 parent 5ccaaad48e
commit d70cc46712
2 files changed
+28 -7

No files matched your search

+11 -5
View File
@@ -255,11 +255,17 @@ pub fn build_step(meshes: &[&MeshModel]) -> Option<String> {
/// Returns an ISO 8601-like timestamp string for the STEP file header.
fn chrono_timestamp() -> String {
// Use seconds since Unix epoch for a simple timestamp without chrono dep.
use std::time::{SystemTime, UNIX_EPOCH};
let secs = SystemTime::now()
.duration_since(UNIX_EPOCH)
.map(|d| d.as_secs())
.unwrap_or(0);
// `SystemTime::now` panics in the browser; ask the page's clock there. (#761)
#[cfg(target_arch = "wasm32")]
let secs = (js_sys::Date::now() / 1000.0) as u64;
#[cfg(not(target_arch = "wasm32"))]
let secs = {
use std::time::{SystemTime, UNIX_EPOCH};
SystemTime::now()
.duration_since(UNIX_EPOCH)
.map(|d| d.as_secs())
.unwrap_or(0)
};
// Format: YYYY-MM-DDTHH:MM:SS (approximate UTC from epoch seconds).
let s = secs;
let mins = s / 60;