| 69 | } |
| 70 | |
| 71 | async fn save_truncated(content: &str, save_dir: &Path) -> std::io::Result<PathBuf> { |
| 72 | fs::create_dir_all(save_dir).await?; |
| 73 | |
| 74 | let timestamp = SystemTime::now() |
| 75 | .duration_since(UNIX_EPOCH) |
| 76 | .map(|d| d.as_millis()) |
| 77 | .unwrap_or(0); |
| 78 | |
| 79 | let filename = format!("truncated_{}.txt", timestamp); |
| 80 | let filepath = save_dir.join(filename); |
| 81 | |
| 82 | let mut file = fs::File::create(&filepath).await?; |
| 83 | file.write_all(content.as_bytes()).await?; |
| 84 | file.flush().await?; |
| 85 | |
| 86 | Ok(filepath) |
| 87 | } |
| 88 | |
| 89 | pub async fn cleanup(save_dir: &Path) -> std::io::Result<usize> { |
| 90 | if !save_dir.exists() { |