Add debug feature to dump requests

This commit is contained in:
Leon Grünewald 2024-01-01 21:50:57 +01:00
parent ddba5b2bb0
commit 74338fe59d
2 changed files with 10 additions and 7 deletions

View file

@ -14,3 +14,5 @@ serde_json = "1.0.108"
thiserror = "1.0.52" thiserror = "1.0.52"
url = "2.5.0" url = "2.5.0"
[features]
dump = []

View file

@ -1,3 +1,4 @@
use std::io::Write;
use crate::post::{Post, Posts}; use crate::post::{Post, Posts};
use anyhow::Result; use anyhow::Result;
use base64::{engine::GeneralPurpose, Engine}; use base64::{engine::GeneralPurpose, Engine};
@ -75,13 +76,13 @@ impl<'a> Client<'a> {
let res = self.list_posts_raw(limit, tags, page).await?; let res = self.list_posts_raw(limit, tags, page).await?;
let text = res.text().await?; let text = res.text().await?;
/* if cfg!(debug) {
let mut debug_file = std::fs::OpenOptions::new() let mut debug_file = std::fs::OpenOptions::new()
.write(true) .write(true)
.create(true) .create(true)
.open("./debug.json")?; .open("/tmp/debug.json")?;
debug_file.write_all(text.as_bytes())?; debug_file.write_all(text.as_bytes())?;
*/ }
Ok(serde_json::from_str::<Posts>(text.as_str())?.into()) Ok(serde_json::from_str::<Posts>(text.as_str())?.into())
} }