diff --git a/src-tauri/src/commands/fs_util.rs b/src-tauri/src/commands/fs_util.rs new file mode 100644 index 0000000..535fb14 --- /dev/null +++ b/src-tauri/src/commands/fs_util.rs @@ -0,0 +1,46 @@ +//! 本地文件读取(供前端播放 Node 生成的临时音频等) + +use base64::{engine::general_purpose::STANDARD, Engine as _}; +use std::path::{Component, Path, PathBuf}; + +fn normalize_path(path: &str) -> PathBuf { + Path::new(path) + .components() + .filter(|c| !matches!(c, Component::ParentDir)) + .collect() +} + +/// 仅允许读取临时目录下的试听/流水线产物,避免任意路径读取。 +fn is_allowed_local_media(path: &Path) -> bool { + let lower = path.to_string_lossy().to_lowercase(); + if lower.contains("aiclient-voice-preview-cache") + || lower.contains("aiclient-node-pipeline") + { + return true; + } + if let Ok(temp) = std::env::temp_dir().canonicalize() { + if let Ok(canonical) = path.canonicalize() { + return canonical.starts_with(&temp); + } + } + false +} + +/// 读取本地文件为 base64(用于 `