working on tilde integration

This commit is contained in:
notplants 2025-02-19 14:43:31 -05:00
parent 6bbfb454de
commit 22e32a5715
5 changed files with 34 additions and 11 deletions

View File

@ -59,8 +59,8 @@ pub fn get_peach_config_defaults() -> HashMap<String, String> {
("SSB_ADMIN_IDS", ""), ("SSB_ADMIN_IDS", ""),
("ADMIN_PASSWORD_HASH", "47"), ("ADMIN_PASSWORD_HASH", "47"),
("TEMPORARY_PASSWORD_HASH", ""), ("TEMPORARY_PASSWORD_HASH", ""),
("SOLAR_SBOT_DATADIR", "/home/peach/.local/share/local"), ("TILDE_SBOT_DATADIR", "/home/notplants/.local/share/tildefriends/"),
("SOLAR_SBOT_SERVICE", "solar-sbot.service"), ("TILDE_SBOT_SERVICE", "tilde-sbot.service"),
("PEACH_CONFIGDIR", "/var/lib/peachcloud"), ("PEACH_CONFIGDIR", "/var/lib/peachcloud"),
("PEACH_HOMEDIR", "/home/peach"), ("PEACH_HOMEDIR", "/home/peach"),
("PEACH_WEBDIR", "/usr/share/peach-web"), ("PEACH_WEBDIR", "/usr/share/peach-web"),

View File

@ -68,9 +68,10 @@ impl SbotStatus {
// note this command does not need to be run as sudo // note this command does not need to be run as sudo
// because non-privileged users are able to run systemctl show // 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") let info_output = Command::new("systemctl")
.arg("show") .arg("show")
.arg(config_manager::get_config_value("SOLAR_SBOT_SERVICE")?) .arg(service_name)
.arg("--no-page") .arg("--no-page")
.output()?; .output()?;
@ -92,7 +93,7 @@ impl SbotStatus {
// because non-privileged users are able to run systemctl status // because non-privileged users are able to run systemctl status
let status_output = Command::new("systemctl") let status_output = Command::new("systemctl")
.arg("status") .arg("status")
.arg(config_manager::get_config_value("SOLAR_SBOT_SERVICE")?) .arg(config_manager::get_config_value("TILDE_SBOT_SERVICE")?)
.output()?; .output()?;
let service_status = str::from_utf8(&status_output.stdout)?; let service_status = str::from_utf8(&status_output.stdout)?;
@ -130,10 +131,15 @@ impl SbotStatus {
} }
} }
// TOOD restore this
// get path to blobstore // get path to blobstore
// let blobstore_path = format!(
// "{}/blobs/sha256",
// config_manager::get_config_value("TILDE_SBOT_DATADIR")?
// );
let blobstore_path = format!( 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 // determine the size of the blobstore directory in bytes

View File

@ -29,7 +29,7 @@ pub fn systemctl_sbot_cmd(cmd: &str) -> Result<Output, PeachWebError> {
let output = Command::new("sudo") let output = Command::new("sudo")
.arg("systemctl") .arg("systemctl")
.arg(cmd) .arg(cmd)
.arg(config_manager::get_config_value("SOLAR_SBOT_SERVICE")?) .arg(config_manager::get_config_value("TILDE_SBOT_SERVICE")?)
.output()?; .output()?;
Ok(output) Ok(output)
} }
@ -69,7 +69,7 @@ pub async fn init_sbot_client() -> Result<TildeClient, PeachWebError> {
// initialise sbot connection with ip:port and shscap from config file // initialise sbot connection with ip:port and shscap from config file
let key_path = format!( let key_path = format!(
"{}/secret.toml", "{}/secret.toml",
config_manager::get_config_value("SOLAR_SBOT_DATADIR")? config_manager::get_config_value("TILDE_SBOT_DATADIR")?
); );
let sbot_client = init_sbot().await?; let sbot_client = init_sbot().await?;
Ok(sbot_client) Ok(sbot_client)

View File

@ -6,7 +6,7 @@ use std::fmt;
/// all tilde client errors /// all tilde client errors
#[derive(Debug)] #[derive(Debug)]
pub struct TildeError { pub struct TildeError {
message: String, pub(crate) message: String,
} }
impl fmt::Display for TildeError { impl fmt::Display for TildeError {

View File

@ -3,6 +3,7 @@
use crate::error::TildeError; use crate::error::TildeError;
use serde_json::Value; use serde_json::Value;
use std::process::{Command, exit};
mod error; mod error;
@ -23,12 +24,28 @@ pub fn get_sbot_client() -> TildeClient {
impl TildeClient { impl TildeClient {
pub fn run_tilde_command(&self, command: &str) -> Result<String, TildeError> {
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<String, TildeError> { pub async fn latest_description(&self, key: &str) -> Result<String, TildeError> {
todo!(); todo!();
} }
pub async fn whoami(&self) -> Result<String, TildeError> { pub async fn whoami(&self) -> Result<String, TildeError> {
todo!(); self.run_tilde_command("get_identity")
} }
pub async fn is_following(&self, from_id: &str, to_id: &str) -> Result<bool, TildeError> { pub async fn is_following(&self, from_id: &str, to_id: &str) -> Result<bool, TildeError> {
@ -53,4 +70,4 @@ impl TildeClient {
pub async fn publish(&self, post: Value) -> Result<Vec<String>, TildeError> { pub async fn publish(&self, post: Value) -> Result<Vec<String>, TildeError> {
todo!(); todo!();
} }
} }