From 3322d479573d63442a7774b361be065b65b8bd52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leon=20Gr=C3=BCnewald?= <10533763+dhalucario@users.noreply.github.com> Date: Tue, 10 Jun 2025 00:52:21 +0200 Subject: [PATCH] client: Simplify json conversion --- src/client.rs | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/src/client.rs b/src/client.rs index e56c84b..af45dfd 100644 --- a/src/client.rs +++ b/src/client.rs @@ -1,4 +1,3 @@ -use std::io::Write; use crate::post::{Id, Post, RawPost, RawPosts}; use anyhow::Result; use base64::{engine::GeneralPurpose, Engine}; @@ -79,17 +78,7 @@ impl Client { ) -> Result> { self.request_limiter().await; let res = self.list_posts_raw(limit, tags, page).await?; - let text = res.text().await?; - - 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()) + Ok(res.json::().await?.into()) } /// Get a specific post @@ -112,9 +101,7 @@ impl Client { pub async fn get_post(&mut self, post_id: Id) -> Result { self.request_limiter().await; let res = self.get_post_raw(post_id).await?; - let text = res.text().await?; - - Ok(serde_json::from_str::(text.as_str())?.into()) + Ok(res.json::().await?.into()) } pub async fn get_post_raw(&mut self, post_id: Id) -> Result {