diff --git a/Cargo.toml b/Cargo.toml index 6cbd57e..eda8684 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,3 +14,5 @@ serde_json = "1.0.108" thiserror = "1.0.52" url = "2.5.0" +[features] +dump = [] \ No newline at end of file diff --git a/src/client.rs b/src/client.rs index c423b17..0fce8c9 100644 --- a/src/client.rs +++ b/src/client.rs @@ -1,3 +1,4 @@ +use std::io::Write; use crate::post::{Post, Posts}; use anyhow::Result; use base64::{engine::GeneralPurpose, Engine}; @@ -75,13 +76,13 @@ impl<'a> Client<'a> { let res = self.list_posts_raw(limit, tags, page).await?; let text = res.text().await?; - /* - let mut debug_file = std::fs::OpenOptions::new() - .write(true) - .create(true) - .open("./debug.json")?; - debug_file.write_all(text.as_bytes())?; - */ + if cfg!(debug) { + let mut debug_file = std::fs::OpenOptions::new() + .write(true) + .create(true) + .open("/tmp/debug.json")?; + debug_file.write_all(text.as_bytes())?; + } Ok(serde_json::from_str::(text.as_str())?.into()) }