From 22e32a5715edfea54b3c84d1d42934cbcc65a089 Mon Sep 17 00:00:00 2001 From: notplants Date: Wed, 19 Feb 2025 14:43:31 -0500 Subject: [PATCH] working on tilde integration --- peach-lib/src/config_manager.rs | 4 ++-- peach-lib/src/sbot.rs | 14 ++++++++++---- peach-web/src/utils/sbot.rs | 4 ++-- tilde-client/src/error.rs | 2 +- tilde-client/src/lib.rs | 21 +++++++++++++++++++-- 5 files changed, 34 insertions(+), 11 deletions(-) diff --git a/peach-lib/src/config_manager.rs b/peach-lib/src/config_manager.rs index 385a098..52205f1 100644 --- a/peach-lib/src/config_manager.rs +++ b/peach-lib/src/config_manager.rs @@ -59,8 +59,8 @@ pub fn get_peach_config_defaults() -> HashMap { ("SSB_ADMIN_IDS", ""), ("ADMIN_PASSWORD_HASH", "47"), ("TEMPORARY_PASSWORD_HASH", ""), - ("SOLAR_SBOT_DATADIR", "/home/peach/.local/share/local"), - ("SOLAR_SBOT_SERVICE", "solar-sbot.service"), + ("TILDE_SBOT_DATADIR", "/home/notplants/.local/share/tildefriends/"), + ("TILDE_SBOT_SERVICE", "tilde-sbot.service"), ("PEACH_CONFIGDIR", "/var/lib/peachcloud"), ("PEACH_HOMEDIR", "/home/peach"), ("PEACH_WEBDIR", "/usr/share/peach-web"), diff --git a/peach-lib/src/sbot.rs b/peach-lib/src/sbot.rs index a29085f..07f41df 100644 --- a/peach-lib/src/sbot.rs +++ b/peach-lib/src/sbot.rs @@ -68,9 +68,10 @@ impl SbotStatus { // note this command does not need to be run as sudo // because non-privileged users are able to run systemctl show + let service_name = config_manager::get_config_value("TILDE_SBOT_SERVICE")?; let info_output = Command::new("systemctl") .arg("show") - .arg(config_manager::get_config_value("SOLAR_SBOT_SERVICE")?) + .arg(service_name) .arg("--no-page") .output()?; @@ -92,7 +93,7 @@ impl SbotStatus { // because non-privileged users are able to run systemctl status let status_output = Command::new("systemctl") .arg("status") - .arg(config_manager::get_config_value("SOLAR_SBOT_SERVICE")?) + .arg(config_manager::get_config_value("TILDE_SBOT_SERVICE")?) .output()?; let service_status = str::from_utf8(&status_output.stdout)?; @@ -130,10 +131,15 @@ impl SbotStatus { } } + // TOOD restore this // get path to blobstore + // let blobstore_path = format!( + // "{}/blobs/sha256", + // config_manager::get_config_value("TILDE_SBOT_DATADIR")? + // ); let blobstore_path = format!( - "{}/blobs/sha256", - config_manager::get_config_value("SOLAR_SBOT_DATADIR")? + "{}", + config_manager::get_config_value("TILDE_SBOT_DATADIR")? ); // determine the size of the blobstore directory in bytes diff --git a/peach-web/src/utils/sbot.rs b/peach-web/src/utils/sbot.rs index 55a2fa8..c167489 100644 --- a/peach-web/src/utils/sbot.rs +++ b/peach-web/src/utils/sbot.rs @@ -29,7 +29,7 @@ pub fn systemctl_sbot_cmd(cmd: &str) -> Result { let output = Command::new("sudo") .arg("systemctl") .arg(cmd) - .arg(config_manager::get_config_value("SOLAR_SBOT_SERVICE")?) + .arg(config_manager::get_config_value("TILDE_SBOT_SERVICE")?) .output()?; Ok(output) } @@ -69,7 +69,7 @@ pub async fn init_sbot_client() -> Result { // initialise sbot connection with ip:port and shscap from config file let key_path = format!( "{}/secret.toml", - config_manager::get_config_value("SOLAR_SBOT_DATADIR")? + config_manager::get_config_value("TILDE_SBOT_DATADIR")? ); let sbot_client = init_sbot().await?; Ok(sbot_client) diff --git a/tilde-client/src/error.rs b/tilde-client/src/error.rs index 14cadaf..10a5eee 100644 --- a/tilde-client/src/error.rs +++ b/tilde-client/src/error.rs @@ -6,7 +6,7 @@ use std::fmt; /// all tilde client errors #[derive(Debug)] pub struct TildeError { - message: String, + pub(crate) message: String, } impl fmt::Display for TildeError { diff --git a/tilde-client/src/lib.rs b/tilde-client/src/lib.rs index 38dee82..891ced0 100644 --- a/tilde-client/src/lib.rs +++ b/tilde-client/src/lib.rs @@ -3,6 +3,7 @@ use crate::error::TildeError; use serde_json::Value; +use std::process::{Command, exit}; mod error; @@ -23,12 +24,28 @@ pub fn get_sbot_client() -> TildeClient { impl TildeClient { + + pub fn run_tilde_command(&self, command: &str) -> Result { + let output = Command::new("out/release/tildefriends.standalone") + .arg(command) + .output().map_err(|e| TildeError { + message: format!("Command execution failed: {}", e), + })?; + + if !output.status.success() { + return Err(TildeError { message: format!("Command failed with status: {}", output.status) }) + } + + let result = String::from_utf8_lossy(&output.stdout).to_string(); + println!("Command output: {}", result); + Ok(result) + } pub async fn latest_description(&self, key: &str) -> Result { todo!(); } pub async fn whoami(&self) -> Result { - todo!(); + self.run_tilde_command("get_identity") } pub async fn is_following(&self, from_id: &str, to_id: &str) -> Result { @@ -53,4 +70,4 @@ impl TildeClient { pub async fn publish(&self, post: Value) -> Result, TildeError> { todo!(); } -} \ No newline at end of file +}