This commit is contained in:
2025-05-13 08:52:47 +03:00
parent 2fae059512
commit 7fa4125dc0
8 changed files with 326 additions and 5 deletions

View File

@@ -530,6 +530,35 @@ impl DocTree {
Ok(())
}
/// Exports all collections to IPFS, encrypting their files and generating CSV manifests.
///
/// # Arguments
///
/// * `output_dir` - The directory to save the output CSV files.
///
/// # Returns
///
/// Ok(()) on success or an error.
pub async fn export_collections_to_ipfs<P: AsRef<Path>>(&self, output_dir: P) -> Result<()> {
use tokio::fs;
let output_dir = output_dir.as_ref();
// Create the output directory if it doesn't exist
fs::create_dir_all(output_dir).await.map_err(DocTreeError::IoError)?;
for (name, collection) in &self.collections {
let csv_file_path = output_dir.join(format!("{}.csv", name));
println!("DEBUG: Exporting collection '{}' to IPFS and generating CSV at {:?}", name, csv_file_path);
if let Err(e) = collection.export_to_ipfs(&csv_file_path).await {
eprintln!("Error exporting collection '{}': {}", name, e);
// Continue with the next collection
}
}
Ok(())
}
}
impl DocTreeBuilder {
@@ -713,9 +742,6 @@ impl DocTreeBuilder {
}
/// Create a new DocTree instance
///
/// For backward compatibility, it also accepts path and name parameters