bhcli

A TUI for chatting on LE PHP Chats (onion)
git clone https://git.dasho.dev/n0tr1v/bhcli.git
Log | Files | Refs | README

commit b44a7fc1aef848a2e9e16f2c95b5eef9779dd507
parent e298c1199ab4b21d688ab26fb6db684761740c2f
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Sat, 29 Apr 2023 22:45:44 -0700

fix more dynamic bs

Diffstat:
Msrc/main.rs | 18++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/src/main.rs b/src/main.rs @@ -479,16 +479,18 @@ impl LeChatPHPClient { return Ok(()); } if self.chat_type == ClientType::BHC { - let resp = self.client.get(&self.config.url).send().unwrap().text().unwrap(); - let doc = Document::from(resp.as_str()); - let meta_content = doc.find(Name("meta")).next().unwrap().attr("content").context("meta content not found").unwrap().to_owned(); - let index_url = META_REFRESH_RGX.captures(&meta_content).unwrap()[1].to_owned(); - - let resp = self.client.get(format!("{}/{}", &self.config.url, index_url)).send().unwrap().text().unwrap(); - let doc = Document::from(resp.as_str()); + let mut resp_txt = self.client.get(&self.config.url).send().unwrap().text().unwrap(); + let doc = Document::from(resp_txt.as_str()); + if let Some(meta) = doc.find(Name("meta")).next() { + let meta_content = meta.attr("content").context("meta content not found").unwrap().to_owned(); + let index_url = META_REFRESH_RGX.captures(&meta_content).unwrap()[1].to_owned(); + resp_txt = self.client.get(format!("{}/{}", &self.config.url, index_url)).send().unwrap().text().unwrap(); + } + let doc = Document::from(resp_txt.as_str()); let form_action = doc.find(Name("form")).next().unwrap().attr("action").context("form action not found").unwrap().to_owned(); + let captcha_url = doc.find(Name("img")).next().unwrap().attr("src").context("img src not found").unwrap().to_owned(); - let captcha_bytes = self.client.get(format!("{}/captcha.php", &self.config.url)).send().unwrap().bytes().unwrap(); + let captcha_bytes = self.client.get(format!("{}/{}", &self.config.url, captcha_url)).send().unwrap().bytes().unwrap(); let img = image::load_from_memory(&captcha_bytes).unwrap(); let img_buf = image::imageops::resize(&img, img.width(), img.height(), image::imageops::FilterType::Nearest); // Save captcha as file on disk