app
Adom Chipsmith
Public Made by Adomby adom
STEP-native chip validator — 5-source cross-validation, OCCT-generated copyright-free 3D models with embedded signal annotations, datasheet-to-STEP pipeline.
//! On-disk content-hashed cache for converted GLBs.
//! Files land at /tmp/adom-step-cache/<sha256>.glb plus a sibling
//! <sha256>.materials.json with the materials payload from the service.
use anyhow::{anyhow, Result};
use sha2::{Digest, Sha256};
use std::path::{Path, PathBuf};
pub fn cache_dir() -> PathBuf {
let base = std::env::var("ADOM_STEP_CACHE")
.unwrap_or_else(|_| "/tmp/adom-step-cache".to_string());
PathBuf::from(base)
}
pub fn ensure_dir() -> Result<PathBuf> {
let d = cache_dir();
std::fs::create_dir_all(&d).map_err(|e| anyhow!("create cache dir {}: {e}", d.display()))?;
Ok(d)
}
pub fn sha256_hex(bytes: &[u8]) -> String {
let mut h = Sha256::new();
h.update(bytes);
hex::encode(h.finalize())
}
pub fn glb_path(hash: &str) -> PathBuf {
cache_dir().join(format!("{hash}.glb"))
}
pub fn materials_path(hash: &str) -> PathBuf {
cache_dir().join(format!("{hash}.materials.json"))
}
pub fn read_materials(p: &Path) -> serde_json::Value {
std::fs::read_to_string(p)
.ok()
.and_then(|s| serde_json::from_str(&s).ok())
.unwrap_or(serde_json::json!([]))
}